Hello!
On my website I'm looking to create a dynamic HTML table from the contents of a MySQL database.
I have no idea how many rows there will be, and I need it to look a bit like an iPhone home screen.
Here is some code:
v1:
// Make a MySQL Connection
mysql_connect("localhost", "jsathost_nintube", "********") or die(mysql_error());
mysql_select_db("jsathost_nintube") or die(mysql_error());
// Connect me to "videos", please!
$query = "SELECT * FROM videos";
$result = mysql_query($query) or die(mysql_error());
echo "<TR>";
while($row = mysql_fetch_array($result)){
echo "<TD><A href='watch.php?id=".$row['idn']."' title='".$row['name']."'><IMG src='http://www.nintube.jsathost.co.cc/genthumb.php?pic=".$row['furl']."' alt='".$row['name']."'><!--<BR />".$row['name']."--></A></TD>";
}
echo "</TR>";
// echo "<LI><A href='watch.php?id=".$row['idn']."' title='".$row['name']."'>".$row['name']."</A></LI><BR />";
v2:
// Make a MySQL Connection
mysql_connect("localhost", "jsathost_nintube", "********") or die(mysql_error());
mysql_select_db("jsathost_nintube") or die(mysql_error());
// Connect me to "videos", please!
$query = "SELECT * FROM videos";
$result = mysql_query($query) or die(mysql_error());
if (($result)||(mysql_errno == 0))
{
echo '<TABLE border="0" cellspacing="5" width="200">';
if (mysql_num_rows($result)>0)
{
//display the data
while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<TR>";
//loop thru the serials to create three columns
$i = 0;
while ($i < 1)
{
echo "<TD><A href='watch.php?id=".$rows['idn']."' title='".$rows['name']."'><IMG src='http://www.nintube.jsathost.co.cc/genthumb.php?pic=".$rows['furl']."' alt='".$rows['name']."'><!--<BR />".$rows['name']."--></A></TD>";
$i++;
}
echo "</TR>";
}
}else{
echo "<tr><td colspan='" . ($i+1) . "'>Error: No videos found!</td></tr>";
}
echo "</table>";
}else{
echo "Error in running MySQL query: ". mysql_error();
}
Could anyone possibly help me with this?