Jump to content

Echo a table form a database


Genesis730

Recommended Posts

I posted this a little bit ago, and was told to change a row field from "primary" to something else since primary is a key word... here is my updated code, i still get the same error...

 

"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource"

 

<table cellspacing="0" cellpadding="0" border="1">
  <tr>
    <td>ID</td><td>Name</td><td>Primary #</td><td>Secondary #</td><td>Address</td><td>City</td><td>Arizona</td><td>ZIP</td><td>Email Address</td><td>Diagnostic</td><td>Virus</td><td>Optimize</td><td>Repair</td><td>Setup</td><td>OS</td><td>Backup</td><td>Questions</td><td>Miles</td><td>Paid</td>
  </tr>
<?PHP
   $res = mysql_query("SELECT id, date, firstname, lastname, primaryphone, secondaryphone, address, city, state, zip, emailaddress, diagnostic, virus, optimize, repair, setup, os, backup, questions, miles, paid FROM contact ORDER BY date");

   while ($row = mysql_fetch_assoc($res)) {
      echo "<tr><td>{$row['id']}</td><td>{$row['firstname']} {$row['lastname']}</td><td>{$row['primaryphone']}</td><td>{$row['secondaryphone']}</td><td>{$row['address']}</td><td>{$row['city']}</td><td>{$row['state']}</td><td>{$row['zip']}</td><td>{$row['emailaddress']}</td><td>{$row['diagnostic']}</td><td>{$row['virus']}</td><td>{$row['optimize']}</td><td>{$row['repair']}</td><td>{$row['setup']}</td><td>{$row['os']}</td><td>{$row['backup']}</td><td>{$row['questions']}</td><td>{$row['miles']}</td><td>{$row['paid']}</td></tr>";
   }
?>

</table>

Link to comment
Share on other sites

Change your query so that it has the or die(trigger_error()); after it (temporarily) and post back the result.

 

 

   $res = mysql_query("SELECT id, date, firstname, lastname, primaryphone, secondaryphone, address, city, state, zip, emailaddress, diagnostic, virus, optimize, repair, setup, os, backup, questions, miles, paid FROM contact ORDER BY date") or trigger_error(mysql_error());

Link to comment
Share on other sites

I did what you suggested Andy-H and got this error

"Notice: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'optimize, repair, setup, os, backup, questions, miles, paid FROM contact ORDER B' at line 1"

 

$res = mysql_query("SELECT id, date, firstname, lastname, primaryphone, secondaryphone, address, city, state, zip, emailaddress, diagnostic, virus, optimize, repair, setup, os, backup, questions, miles, paid FROM contact ORDER BY date");

WAS CHANGED TO

$res = mysql_query("SELECT id, date, firstname, lastname, primaryphone, secondaryphone, address, city, state, zip, emailaddress, diagnostic, virus, optimize, repair, setup, os, backup, questions, miles, paid FROM contact ORDER BY date") or trigger_error(mysql_error());

 

Link to comment
Share on other sites

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

 

 

Looks like optimize is a mysql keyword, add the backticks (`) around the fieldname in your query as shown in the code below or change the table name.

   $res = mysql_query("SELECT id, date, firstname, lastname, primaryphone, secondaryphone, address, city, state, zip, emailaddress, diagnostic, virus, `optimize`, repair, setup, os, backup, questions, miles, paid FROM contact ORDER BY date") or trigger_error(mysql_error());

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.