Jump to content

Displaying MySQL database content on a webpage


flipper828

Recommended Posts

I am new to php and am having problems displaying the contents of a database on a webpage.  The headings and table show up properly but the cells that are suppose to show the database content are blank.  Here's my code and I truly appreciate any help I can get.

 

<?php

 

$adminid = $_SESSION['UGsurv_admin'];

 

$query = "SELECT name FROM admin WHERE adminid = '$adminid'";

$result=mysql_query($query);

$row=mysql_fetch_array($result, MYSQL_ASSOC);

 

$name = $row['name'];

echo "<h2>Welcome, $name</h2><br />\n";

 

$date = date("l, F j, Y");

echo "<h2>Today's date: $date</h2><br />\n";

 

 

echo "<h2><br />Survey Results:</h2>\n";

 

 

  echo "<table width=\"100%\" cellpadding=\"1\" border=\"1\"\n";

  echo "<tr><td><strong>Firm Name</strong></td><td><strong>Preferred Dates</strong></td><td><strong>Est. Number of Attendees</strong></td><td><strong>Prior Attendance?</strong></td><td><strong>Prior Topics Found Most Valuable</strong></td><td><strong>Topics of Most Interest</strong></td></tr>\n";

 

  {

 

  $query = "SELECT survid,firmname,prefdates,estnum,attb4,comments,comments2 FROM survey ORDER BY survid";

  $result = mysql_query($query);

   

while($row=mysql_fetch_array($result, MYSQL_ASSOC)) 

 

      $survid = $row['survid'];

    $firmname = $row['firmname'];

      $prefdates = $row['prefdates'];

      $estnum = $row['estnum'];

      $attb4 = $row['attb4'];

      $comments = $row['comments'];

      $comments2 = $row['comments2'];

     

  printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n" , $firmname, $prefdates, $estnum, $attb4, $comments, $comments2);

 

  if ($estnum == 0)

 

 

    echo "  <font color=\"ff000\">No</font><br />\n";

  else

    echo "<br />";

  }

 

 

echo "</table><br /><br />\n";

 

?>

Link to comment
Share on other sites

Your code should be

<?php

$adminid = $_SESSION['UGsurv_admin'];

$query = "SELECT name FROM admin WHERE adminid = '$adminid'";
$result=mysql_query($query);
$row=mysql_fetch_array($result, MYSQL_ASSOC);

$name = $row['name'];
echo "<h2>Welcome, $name</h2><br />\n";

$date = date("l, F j, Y");
echo "<h2>Today's date: $date</h2><br />\n";


echo "<h2><br />Survey Results:</h2>\n";


echo "<table width=\"100%\" cellpadding=\"1\" border=\"1\"\n";
echo "<tr><td><strong>Firm Name</strong></td><td><strong>Preferred Dates</strong></td><td><strong>Est. Number of Attendees</strong></td><td><strong>Prior Attendance?</strong></td><td><strong>Prior Topics Found Most Valuable</strong></td><td><strong>Topics of Most Interest</strong></td></tr>\n";

$query = "SELECT survid,firmname,prefdates,estnum,attb4,comments,comments2 FROM survey ORDER BY survid";
$result = mysql_query($query);

while($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
    $survid = $row['survid'];
    $firmname = $row['firmname'];
    $prefdates = $row['prefdates'];
    $estnum = $row['estnum'];
    $attb4 = $row['attb4'];
    $comments = $row['comments'];
    $comments2 = $row['comments2'];

    printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n" , $firmname, $prefdates, $estnum, $attb4, $comments, $comments2);

    if ($estnum == 0)
        echo "  <font color=\"ff000\">No</font><br />\n";
    else
        echo "<br />";
}

echo "</table><br /><br />\n";

?>

 

NOTE: when posting code in the forum please use the


tags.

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.