Jump to content

Why won't this print my mysql table contents?


tracy

Recommended Posts

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body><!--p

include "connectionpage.php";

$query="SELECT * FROM 'Inventory'";
$result=mysql_query($query);

//where table name is Inventory

$num=mysql_numrows($result);

<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Stock#</font>
</th>
<th><font face="Arial, Helvetica, sans-serif">Year</font>
</th>
<th><font face="Arial, Helvetica, sans-serif">Make</font>
</th>
<th><font face="Arial, Helvetica, sans-serif">Model</font>
</th>
<th><font face="Arial, Helvetica, sans-serif">Price</font>
</th>
<th><font face="Arial, Helvetica, sans-serif">Miles</font>
</th>
<th><font face="Arial, Helvetica, sans-serif">Photo</font>
</th>
</tr>"<!--$i=0;
while ($i < $num) {

$stock=mysql_result($result,$i,"stock");
$year=mysql_result($result,$i,"year");
$make=mysql_result($result,$i,"make");
$model=mysql_result($result,$i,"model");
$price=mysql_result($result,$i,"price");
$miles=mysql_result($result,$i,"miles");
$photo=mysql_result($result,$i,"photo1");


<tr>
<td><font face="Arial, Helvetica, sans-serif"><!--cho $stock;--></font>
</td>
<td><font face="Arial, Helvetica, sans-serif"><!--cho $year;--></font>
</td>
<td><font face="Arial, Helvetica, sans-serif"><!--cho $make;--></font>
</td>
<td><font face="Arial, Helvetica, sans-serif"><!--cho $model;--></font>
</td>
<td><font face="Arial, Helvetica, sans-serif"><!--cho $price;--></font>
</td>
<td><font face="Arial, Helvetica, sans-serif"><!--cho $miles;--></font>
</td>
<td><font face="Arial, Helvetica, sans-serif"><!--cho $photo1;--></font>
</td>
</tr><!--$i++;
}

echo "</table>";

?>
</body>
</html>
Link to comment
Share on other sites

It could be that you have no opening tag for the PHP code. You also have no error handling to check for errors. Try this:

[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>

<?php
include "connectionpage.php";
$query="SELECT * FROM 'Inventory'";
$result = mysql_query($sql) or die ("The query:<br>".$query."<br>produced the following error:<br>".mysql_error());
if (!mysql_num_rows($result)) {
    echo "there were no results.";
} else {
    echo "<table border=1>";
    $firstRecord = true;
    while ($row = mysql_fetch_assoc($result)) {
      if ($firstRecord) {
        echo "<tr>";
        foreach ($row as $key => $value) {echo "<td>".$key."</td>";}
        echo "</tr>";
        $firstRecord = false;
      }
      echo "<tr>";
      foreach ($row as $value) { echo "<td>".$value."</td>"; }
      echo "</tr>";
    }
    echo "</table><br>";
}
?>
</body>
</html>[/code]
Link to comment
Share on other sites


[code]
<?php
include ("connectionpage.php");

$query= mysql_query("SELECT * FROM `Inventory`");

$num = mysql_num_rows($query);

if ($num == '0') {
echo "Nothing Exist.";
die();
}
else {

echo "<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td><font face=Arial>Stock#</font>
</td>
<td><font face=Arial>Year</font>
</td>
<td><font face=Arial>Make</font>
</td>
<td><font face=Arial>Model</font>
</td>
<td><font face=Arial>Price</font>
</td>
<td><font face=Arial>Miles</font>
</td>
<td><font face=Arial>Photo</font>
</td>
</tr>";
while ($info = mysql_fetch_array($query)) {
$stock = $info['stock'];
$year = $info['year'];
$make = $info['make'];
$model = $info['model'];
$price = $info['price'];
$miles = $info['miles'];
$photo1 = $info['photo1'];
echo "
<tr>
<td> <font face=Arial> $stock</font>
</td>
<td> <font face=Arial> $year</font>
</td>
<td> <font face=Arial>  $make</font>
</td>
<td> <font face=Arial> $model</font>
</td>
<td> <font face=Arial>$price</font>
</td>
<td> <font face=Arial> $miles</font>
</td>
<td> <font face=Arial> $photo1</font>
</td>
</tr>"
}

echo "</table>";
}

?>[/code]





Link to comment
Share on other sites

You can mess with the HTML output all you want, but if your query is failing you still won't get any output!

Either you are not connecting to the database or the table name is incorrect. I'm not sure that your include statement will work the way it is written. Try changing it to the correct format like this:

include ("connectionpage.php");

If that doesn't work, post the code from that included page.
Link to comment
Share on other sites

After all your suggestions, here's the new code:

[code]
<?php
include ("link.php");

$query= mysql_query("SELECT * FROM 'Inventory'");

$num = mysql_num_rows($query);

if ($num == '0') {
echo "Nothing Exist.";
die();
}
else {

echo "<table border=0 cellspacing=2 cellpadding=2>
<tr>
<td><font face=Arial>Stock#</font>
</td>
<td><font face=Arial>Year</font>
</td>
<td><font face=Arial>Make</font>
</td>
<td><font face=Arial>Model</font>
</td>
<td><font face=Arial>Price</font>
</td>
<td><font face=Arial>Miles</font>
</td>
<td><font face=Arial>Photo</font>
</td>
</tr>";
while ($info = mysql_fetch_array($query)) {
$stock = $info['stock'];
$year = $info['year'];
$make = $info['make'];
$model = $info['model'];
$price = $info['price'];
$miles = $info['miles'];
$photo1 = $info['photo1'];
echo "
<tr>
<td> <font face=Arial> $stock</font>
</td>
<td> <font face=Arial> $year</font>
</td>
<td> <font face=Arial>  $make</font>
</td>
<td> <font face=Arial> $model</font>
</td>
<td> <font face=Arial>$price</font>
</td>
<td> <font face=Arial> $miles</font>
</td>
<td> <font face=Arial> $photo1</font>
</td>
</tr>";


?>
[/code]
Here's the new error:

Parse error: syntax error, unexpected $end in /home/inv/public_html/display3.php on line 58

I feel I am connecting to the database, and my server seems to require the ' before and after the database name.  Thanks...
Link to comment
Share on other sites

Parse error: syntax error, unexpected '>' in /home/inv/public_html/display.php on line 16

This is what happens when the code looks like this with the right curly brackets...

<?php
include ("link.php");

$query= mysql_query("SELECT * FROM Inventory");

$num = mysql_num_rows($query);

if ($num == '0') {
echo "Nothing Exist.";
die();
}
else {

echo '<table border="0" cellspacing="2" cellpadding="2">'

<td><font face=Arial>Stock#</font>
</td>
<td><font face=Arial>Year</font>
</td>
<td><font face=Arial>Make</font>
</td>
<td><font face=Arial>Model</font>
</td>
<td><font face=Arial>Price</font>
</td>
<td><font face=Arial>Miles</font>
</td>
<td><font face=Arial>Photo</font>
</td>
</tr>";
while ($info = mysql_fetch_array($query)) {
$stock = $info['stock'];
$year = $info['year'];
$make = $info['make'];
$model = $info['model'];
$price = $info['price'];
$miles = $info['miles'];
$photo1 = $info['photo1'];
echo "
<tr>
<td> <font face=Arial> $stock</font>
</td>
<td> <font face=Arial> $year</font>
</td>
<td> <font face=Arial>  $make</font>
</td>
<td> <font face=Arial> $model</font>
</td>
<td> <font face=Arial>$price</font>
</td>
<td> <font face=Arial> $miles</font>
</td>
<td> <font face=Arial> $photo1</font>
</td>
</tr>"
}

echo "</table>";
}

?>
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.