Unstoppable Domains โ€” AI Assistant

PHP/MySQL Questions

SpaceshipSpaceship
Watch

LazyD

Established Member
Impact
0
Hi all,

Im currently creating a website that is going to display credit cards by type, insurance and credit services.

Each credit card, credit service or insurance listing is going to be in its own box with a small space between each one, each listing is to be created by the MySQL output loop.

My questions are these:
1. Is there a way to tell the the MySQL output, to put something, like an advertisement from an affiliate between every 3rd or 4th listing?

2. For the area where im going to put APRs and other card properties, to make it easier to read, I would like to alternate what color the background is, is there a way I can tell the MySQL output, that I want entries with a certain fieldname to use "Div A" and other ones "Div B"?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
You may want to use modulus (%)

Example

PHP:
$x = 0;
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while($line = mysql_fetch_row($result)){
 ($x % 2 == 0 ? $div = "diva" : $div = "divb"); // modulus here
   echo "<div class=\"$div\">$line[0]</div>";
   $x++;
}
Same can be used for your ads
 
Last edited:
0
•••
Noobie said:
You may want to use modulus (%)

Example

PHP:
$x = 0;
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while($line = mysql_fetch_row($result)){
 ($x % 2 == 0 ? $div = "diva" : $div = "divb"); // modulus here
   echo "<div class=\"$div\">$line[0]</div>";
   $x++;
}
Same can be used for your ads


Thanks Noobie... Just so I understand, since at the part where your echoing back the div, you have $line[0], how will that work with my output loop? Would having 0 in the array area cause problems? I dont understand how that works, and I am curious from a learning aspect...
 
0
•••
the $line[0] just means the first field in your resultset, was just an example.

replace my $line[0] with a table or whatever you want to display.
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy โ€” Payment Flexibility
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back