I have about two days' worth of PHP experience (more like one), and this is stumping me. I want to create a table with output from a MySqueal query. I also create a header with column names.
The header is created, the data rows are not.
Also, you might wonder why I didn't use require_once. I tried. This page is supposed to be included in another page of a larger program (which I largely don't get yet), and when I tried to use require_once, I got no output and a rather strange error. It didn't happen when I did it this way.
Code:
Output:
Also, dollar signs should be followed by NUMBERS. Big ones.
The header is created, the data rows are not.
Also, you might wonder why I didn't use require_once. I tried. This page is supposed to be included in another page of a larger program (which I largely don't get yet), and when I tried to use require_once, I got no output and a rather strange error. It didn't happen when I did it this way.
Code:
Code:
<?php
if (!function_exists("db_conn"))
{
require '../include/functions.php';
}
$db = db_conn('project'); //creates a DB connection.
$link = mysql_query("select 1, 2, 3;", $db);
if ($link)
{
echo "<table border='1'><tr style='background-color:FFFFCC'>";
for ($i = 0; $i < mysql_num_fields($link); $i++)
{
echo sprintf("<th>%s</th>", mysql_field_name($link, $i));
}
echo "</tr>";
while (true)
{
$row = mysql_fetch_row($res);
if ($row)
{
echo "<tr>";
for ($i = 0; $i < count($row); $i++)
{
echo sprintf("<td>%s</td>", $row[$i]);
}
echo "</tr>";
}
else
{
break;
}
}
echo "</table>";
mysql_close($link);
mysql_close($db);
}
else
{
echo "Your SQL blows!";
}
?>
Output:
Code:
<table border='1'><tr style='background-color:FFFFCC'><th>1</th><th>2</th><th>3</th></tr></table>
Also, dollar signs should be followed by NUMBERS. Big ones.