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";

 

?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.