[SOLVED]:Grabbing data from a mysql database in a loop
Posted: Tue Feb 24, 2009 11:07 am
Hello all...I apologize if this has already been answered, but I couldn't find anything relevant in a quick search.
I am trying to build a page that is entirely database driven. My database is already set up, my mysql code seems to work (as best as I can tell, anyway) but PHP throws up all over itself when I run my script. Let me give you guys some more details.
I want my page to look like this (http://www.sunnywoodstudios.com/woods1.php), which is a stop-gap I coded to be static, not database-driven. I want the pictures and descriptions to come from the database, so when the site admin needs to add a new product, all he needs to do is add a row to the database and the page would update itself. The code I posted below shows how I tried to do this using a FOR loop.
I can give you a copy of the entire page code if you want, but it seems like my problems are in here. I hope I've made sense with my request, please let me know if you need anything else.
Thanks so much in advance!
I am trying to build a page that is entirely database driven. My database is already set up, my mysql code seems to work (as best as I can tell, anyway) but PHP throws up all over itself when I run my script. Let me give you guys some more details.
I want my page to look like this (http://www.sunnywoodstudios.com/woods1.php), which is a stop-gap I coded to be static, not database-driven. I want the pictures and descriptions to come from the database, so when the site admin needs to add a new product, all he needs to do is add a row to the database and the page would update itself. The code I posted below shows how I tried to do this using a FOR loop.
Code: Select all
<?php
$numrows = mysql_num_rows($result);
For ($i=0; $i <= $numrows; $i++)
{
If ($numrows % 2 == 0)
{
echo"<td width='20%' height='77'>";
echo"<a href='woodinfo.php?type={mysql_result($result,$i,'type')}'><img src='images/{mysql_result($result,$i,'SmallImage')}' width='172' height='77' border='0'>";
echo"</a>";
echo"</td>";
echo"</tr>";
echo"<tr>";
}else
{
echo"<td width='20%' height='77'>";
echo"<a href='woodinfo.php?type={mysql_result($result,$i,'type')}'><img src='images/{mysql_result($result,$i,'SmallImage')}' width='172' height='77' border='0'>";
echo"</a>";
echo"</td>";
}
}
?>Thanks so much in advance!