Forum Moderators: coopster
I cannot figure where my error is
Greatly appreciate any help
Regards
<?
include("dbinfo.inc.php");
mysql_connect ($host,$username,$password);
@mysql_select_db($database) or die("unable to select database");
$query = "SELECT page_content from web_pages WHERE $page_id=2";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<table border="2">
<?
$i=0;
while ($i<$num)
{
$page_id=mysql_result($result,$i,$page_id)";
?>
<tr>
<td>
<?
echo "$page_id";
?>
</tr></td>
<?
++$i;
}
echo "</table>";
?>
echo $query;
before you do your mysql_query you may notice that your query is wrong. This may be better
$query = "SELECT page_content from web_pages WHERE page_id=2";
you had a dollar sign before page_id which will prompt php to put the var value in that spot.
you also use mysql_close before you do mysql_result which will cause mysql_result to not have access to the db, therefore not returning the desired result.
I also think
$page_id=mysql_result($result,$i,$page_id)";
should be
$page_id=mysql_result($result,$i,"page_content.page_id");
I removed the double quote and the dollar sign.
Also as mentioned here
[php.net...]
When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than mysql_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.
here is the modified script
<?
include("dbinfo.inc.php");
mysql_connect ($host,$username,$password);
@mysql_select_db($database) or die("unable to select database");
$query = "SELECT page_content from web_pages WHERE page_id=2";
$result=mysql_query($query);
$num=mysql_numrows($result);
?>
<table border="2">
<?
$i=0;
while ($i<$num)
{
$page_id=mysql_result($result,$i)";
mysql_close();
?>
<tr>
<td>
<?
echo "$query";
?>
</tr></td>
<?
++$i;
}
echo "</table>";
?>
include("dbinfo.inc.php");
mysql_connect ($host,$username,$password);
mysql_select_db($database) or die("unable to select database");
$query = "SELECT page_content from web_pages WHERE page_id=2";
$result=mysql_query($query);
echo "<table border=\"2\">";
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>",$row['page_content'],"</tr></td>";
}
echo "</table>";