First of all, I just picked up PHP and SQL out of necessity for a new site. What I've learned so far has amazed me. I'm having a little hiccup, though. I'm using PHP to execute queries to an item database and "echo"ing the html code to set the returns in a table. The method I'm using, though, is only allowing one cell per table row. I've tried to manipulate the code a little, but have yet to find a solution. The example code below is returning a duplicate item in the second cell of each row. Any solutions?
<?php
// set database server access variables:
$host = "host";
$user = "user";
$pass = "pass";
$db = "db";
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$query = "SELECT * FROM sampletable";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table border=0 cellspacing=0 cellpadding=0 class=box_width_cont product>";
while($row = mysql_fetch_row($result)) {
// first cell
echo "<td><center><img height=125 width=175 src=".$row[1]."></center>";
echo "<center><font color=#855b63>".$row[2]."
".$row[3]."
".$row[7]." Cut
Size: ".$row[4]."</font><font color=#855b63 size=3>".$row[10]."</center></font>";
echo "<center><a href=items/".$row[0].".php><img src='images/button_details.gif'>[/url]</center>";
echo "</td>";
// second cell - exact duplicate of one above
echo "<td><center><img height=125 width=175 src=".$row[1]."></center>";
echo "<center><font color=#855b63>".$row[2]."
".$row[3]."
".$row[7]." Cut
Size: ".$row[4]."</font><font color=#855b63 size=3>".$row[10]."</center></font>";
echo "<center><a href=items/".$row[0].".php><img src='images/button_details.gif'>[/url]</center></td>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No items found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>