I'm trying to output a sql table into a html table. Below is the code.
mysql_select_db("zid", $con);
$query = "SELECT cid, firstn, lastn, email, rating FROM userinfo ORDER BY Lname";
//gets information
$result = mysql_query($query, $con);
//creates table for displaying all on roster
echo("<table border = 1> <center>
<tr><th> CID </th>
<th> Last Name </th>
<th> First Name </th>
<th> Email </Th>
<th> Rank </th>");
while($row = mysql_fetch_array($result))
{
echo("<tr>");
echo("<td>" . $row['cid'] . "</td>");
echo("<td>" . $row['firstn'] . "</td>");
echo("<td>" . $row['lastn'] . "</td>");
echo("<td>" . $row['email'] . "</td>");
echo("<td>" . $row['rating'] . "</td>");
}
echo("</table> </center>");
cid, first, lastn, email, rating, are the actual colum names in mysql. It gives me an error stating mysql_fetch_array is not a valid sql result resource. Any tips. I've looked it over and searched to try to find the answer. No luck.
QUESTION #2
If i created a file that contained the connection info such as:
connection.php
<?php
//connection file
$con = mysql_connect("localhost", "root", ""); ?>
and included it in my other php files using
include 'connection.php';
then would I be able to call $con in my other php files using for the example at the top mysql_query($query, $con) or do i have to define $con as a global variable to do that? (hope this makes sense)
-Mike