ian - 2009-10-19 16:40:03
Hi all, I hope I'm posting this in the correct place.
I'm pretty new to mysql and php and have hit a problem.
I can display data from a query in a table using this code
<?php
$database="my database name";
mysql_connect ("localhost", "my username", "my password");
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "SELECT field1, field2, field3 FROM species WHERE `animal` = 'cat' ORDER BY `class` " )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
?>
This works fine, however I would like to display the data following this format but can't get it to work:
<div id="info"><!--this is a div contanier for info"-->
<h1> field1 </h1>
<img src="field2" class="floatLeft" /><p>field3</p>
</div><!--close info div-->
This will display the animal name using a H3 tag, an image of the animal, floated to the left and some info about the animal to the right. If there are four species of cat, then four lots of the above code would be generated.
Any help would be greatly appreciated.