RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting

Clean Previous Next Script for MySQL results

Join Date: May 2004
Location: berg en terblijt
Posts: 10
Reputation: Patrickske is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Patrickske's Avatar
Patrickske Patrickske is offline Offline
Newbie Poster

Re: Clean Previous Next Script for MySQL results

  #15  
Jun 10th, 2004
Originally Posted by cscgal
I don't know PHP for anything but the following is code for one row ...

So now, perhaps use code like the following? Keep in mind I'm NOT a php programmer.

 echo "<table><tr>";
 while ($row = mysql_fetch_array($result)) 
  {
 echo "<td><a HREF=images/ingame/".$row['big']." TARGET=_blank><img src=images/ingame/thumbs/".$row['thumb']." border=0 alt=".$row['big']."></a></td>"; // display your results as you see fit here.
 if (($row % 3) == 0)
   { echo "</tr><tr>"; }
  }
 </tr></table>
 

Keep also in mind that you need to add "empty" cells if you want to display images in a table of 3x4.
I you have a total of 10 records, and the table has 3 rows, 4 columns, then the last row of the table has only 2 columns in it. You need to add <td></td> (or <td>&nbsp;</td>) cells to fill up the row.

I've made an example at http://quaedackers.homeip.net/testsite/table_format.php

As you can see I use 2 nested loops. 1 for the rows, and 1 for the columns. By checking if the row-object (or array) contains any data (it must NOT be false) then you can write the data in the cell. If the object equals false, then you need to write an empty cell.

[php]
echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n";

for($row=0; $row<$rowCount; $row++){ // create the rows in a nice loop
echo "<tr>";
for($col=0; $col<$colCount; $col++){ // create the columns in a nice nested loop
echo "<td width=\"30\" align=\"center\">";
if($db_row = mysql_fetch_object($result))
// fetch the results in an object and thest if there is data.
// (if there is no data, $db_row will be 'false')
{
echo htmlentities($db_row->some_field); // There is data, display it!
}
else
{
echo "&nbsp;"; // There was no data. Write a &nbsp; to create an 'empty' cell
}
echo "</td>"; // close the cell
}
echo "</tr>\n"; // close the row
}

echo "</table>\n"; // close the table
[/php]

/ Patrick
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:54 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC