mysql_result; mysql_fetch_row etc. which one?
Posted: Sat Apr 15, 2006 2:57 pm
I've been banging my head against a wall it seems for some time now and
I just don't seem to get my code to work properly. I am trying to read a
record set into some echo statements which produce html output. I create
a SELECT query which can extract about 20 rows of data which contain
a number of fields based on an input statement. So, for an example:
Create the SQL query:
Create the recordset from the query
The variable $land is supposed to hold the recordset output to be appended to an
echo statement later on formatting the output into a table.
My problem is that I am getting no output in the $land variable and have come to
the conclusion that I really don't quite know how to do this. The mysql_result comments
in the PHP manual state that "If you came to this like I did, looking for a function that grabs
info from the result but does not increment it to the next result row, you are out of luck."
With the above code I am simply trying to create output from a single row of the recordset
but based on the fields selected in the query. I use code further down to increment through
the remaining rows of the recordset. But this is not working correctly and I must admit I am
at a loss as to why. I clearly don't understand how the mysql_result function is supposed
to work and I really need some expert advice on how I should structure this code or if
I should be using a different function.
Any help appreciated.
I just don't seem to get my code to work properly. I am trying to read a
record set into some echo statements which produce html output. I create
a SELECT query which can extract about 20 rows of data which contain
a number of fields based on an input statement. So, for an example:
Create the SQL query:
Code: Select all
for ( $i = $xint; $i >= $yint; $i-- ) {
$sqlstring = $sqlstring . "`" . $i . "`";
If ($i > $yint) { $sqlstring = $sqlstring . ","; }
}Code: Select all
$r2=mysql_query("SELECT " . $sqlstring . " FROM Land",$db) or die(mysql_error());Code: Select all
Create the output string for the recordset
for ( $i = $xint; $i >= $yint; $i-- ) {
$land = $land . number_format(mysql_result($r2,$i,$i),0) . "</td><td align='right'>";
If ($i = $yint) { $land = $land . "</tr>"; }
}echo statement later on formatting the output into a table.
My problem is that I am getting no output in the $land variable and have come to
the conclusion that I really don't quite know how to do this. The mysql_result comments
in the PHP manual state that "If you came to this like I did, looking for a function that grabs
info from the result but does not increment it to the next result row, you are out of luck."
With the above code I am simply trying to create output from a single row of the recordset
but based on the fields selected in the query. I use code further down to increment through
the remaining rows of the recordset. But this is not working correctly and I must admit I am
at a loss as to why. I clearly don't understand how the mysql_result function is supposed
to work and I really need some expert advice on how I should structure this code or if
I should be using a different function.
Any help appreciated.