PHP Classes

MySQL Display data problem

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  MySQL Display data problem  
Subject:MySQL Display data problem
Summary:I'm trying to display data from a query
Messages:2
Author:ian
Date:2009-10-19 10:27:53
Update:2009-10-19 18:18:23
 

  1. MySQL Display data problem   Reply   Report abuse  
Picture of ian 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.


There is 1 reply in this thread, which is not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.