Jump to content


Photo

display mysql data on a web page in a table


  • Please log in to reply
3 replies to this topic

#1 kevinritt

kevinritt
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts
  • LocationBoston, MA

Posted 16 October 2006 - 10:57 AM

Hi,
I recently received some great help from these forums on how to enter homework on a school's website. I tried displaying the data on a webpage in a table but it does not work. Can anyone point me to a tutorial or show me how to display a table using php?
;D

#2 dymon

dymon
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 16 October 2006 - 11:32 AM

<?
  /*DB Connection*/
  /*DB Query & Result*/
?>
<table border="0">
  <?whilt $row=mysql_fetch_array($query_result) {
      print "<tr>";
        print "<td>".$row['field_name']."</td>";
        print "<td>".$row['field_name2']."</td>";
        print "<td>".$row['field_name3']."</td>";
        .....................................................
      print "<tr>";
</table>

Web is the future ... desktop will die ...

#3 kevinritt

kevinritt
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts
  • LocationBoston, MA

Posted 16 October 2006 - 01:19 PM

<?
  /*DB Connection*/
  /*DB Query & Result*/
?>
<table border="0">
  <?whilt $row=mysql_fetch_array($query_result) {
      print "<tr>";
        print "<td>".$row['field_name']."</td>";
        print "<td>".$row['field_name2']."</td>";
        print "<td>".$row['field_name3']."</td>";
        .....................................................
      print "<tr>";
</table>

Is there a closing ?> missing
also I am only pulling the latest entry from the database so I would not need the fetch_array. Is that correct? I am using the SELECT LAST_INSERT_ID();


#4 dymon

dymon
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 16 October 2006 - 01:41 PM

Yes there should be ?> after print ...;

If you want to extract the last entry, you can use:
                 mysql_query("SET NOCOUNT ON", $conn);
		$result = mysql_query("SELECT @"."@IDENTITY AS Ident", $conn);
		$row = mysql_fetch_row($result);

This code worked for me, and in the $row are all the fields and values for the last entry.
Web is the future ... desktop will die ...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users