Page 1 of 1

table display using while

Posted: Mon Nov 22, 2010 8:04 am
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

Re: table display using while

Posted: Mon Nov 22, 2010 12:46 pm
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>";

Re: table display using while

Posted: Tue Nov 23, 2010 4:29 am
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

Re: table display using while

Posted: Tue Nov 23, 2010 8:51 am
by AbraCadaver

Re: table display using while

Posted: Wed Nov 24, 2010 3:47 am
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?