Jump to content

[SOLVED] putting data from database into html table...


Dragen

Recommended Posts

I'm trying to write some script that will get info from my table and put it into an html table.

 

		<table border="0" cellpadding="0" cellspacing="0" align="center" width="100%">
		<tr>
	<?php
	$result = mysql_query("SELECT * FROM booked");
	$no = 0;
	for($no = 0; $no <= 5; $no++){
		$row = mysql_fetch_array($result);
		  echo "\t\t<td align=\"center\">";
		  echo $row['day'] . " / " . $row['month'] . " / " . $row['year'];
		  echo "</td>\n";
		if($no == 5){
		echo "\t</tr>\n\t<tr>";
		}
	}
	?>
		</tr>
	</table>

This is what I've got so far, but it's not working...

What should happen is when it reaches 6 column across it starts on a new row. At the moment it's just putting the first six along the top and stopping..

I can't seem to get the code right to make it continue on another line...

note: yes I do mean 6 colums although it says $no <= 5;

This is because the first is counted as 0

Link to comment
Share on other sites

When $no == 5, you also need to reset it back to 0.  But the other thing you need to do is break the loop when there's no data left:

 

if ($row === false) break;

...

if ($no == 5) {
  echo "\t</tr>\n\t<tr>";
  $no = 0;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.