table display using while

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

table display using while

Post by aravona »

I want to draw information from my db and display it - not an issue!

What I want to do is, when the columns in the table (the <td>'s) reaches 5 to start a new row.

I can't quite figure it out as I'm using a while loop to display the data currently.

Code: Select all

<?php $query = "select image from wp_wpsc_variation_values where id = '" .wpsc_the_variation_id(). "'";
				$result = mysql_query($query); 
				while($row = mysql_fetch_array($result)){
				echo "<td><img src='http://www.site.co.uk/wordpress/wp-content/plugins/wp-e-commerce/themes/lsotheme/variationimgs/$row[image]' /></td>";
				}
				?>
I get the images showing up from the DB but it is just too long on the page.

Any Ideas? :)

Aravona
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: table display using while

Post by AbraCadaver »

Code: Select all

echo "<tr>";
$count = 1;
while($row = mysql_fetch_array($result)) {
   if($count % 5 === 0) {
      echo "</tr><tr>";
   }
   echo "<td><img src='http://www.site.co.uk/wordpress/wp-content/plugins/wp-e-commerce/themes/lsotheme/variationimgs/
   $row[image]' /></td>";
   $count++;
}
echo "</tr>";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: table display using while

Post by aravona »

I'm afraid that didn't work.

I ended up with the page looking like this: All over the place

Code: Select all

<?php $query = "select image from wp_wpsc_variation_values where id = '" .wpsc_the_variation_id(). "'";
				$result = mysql_query($query); 
				echo "<tr>";
				$count = 1;
				while($row = mysql_fetch_array($result)) {
  					 if($count % 5 == 0) {
			  				echo "</tr><tr>";
  					 }
				echo '<td>
									<input type="radio"  value="<?php echo wpsc_the_variation_id(); ?>" class="wpsc_select_variation" name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>"></td>';
   				echo "<td><img src='http://www.samleisure.co.uk/wordpress/wp-content/plugins/wp-e-commerce/themes/lsotheme/variationimgs/$row[image]' /></td>";
  				$count++;
				}
				echo "</tr>";
				?>

I had to add the other row in, but its not exactly showing right.

Heres the entire code in paste bin: http://pastebin.com/S6KLMQNj
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: table display using while

Post by AbraCadaver »

mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: table display using while

Post by aravona »

I've been looking through the validation and I am working on it.

However I noticed with the code you gave me, the count is alwasy 2. I'm assuming its not supposed to echo '2' every time but increment. However it isnt?
Post Reply