Jump to content

display mysql data on a web page in a table


kevinritt

Recommended Posts

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
Link to comment
Share on other sites

<?
  /*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>
Link to comment
Share on other sites

[quote author=dymon link=topic=111636.msg452528#msg452528 date=1160998355]
<?
  /*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>

[/quote]
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();
Link to comment
Share on other sites

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

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

This code worked for me, and in the $row are all the fields and values for the last entry.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.