I am cycling through a return set and trying to capture the result in a concatenated string. I have verified that I get a valid return value and also verified the quantity in the return value.
This works

while ( $i < $num) {
    $bone .=  "<item> <record_num>" . mysql_result($result, $i,'record_num') . "</record_num>" .
		 		"<date_field>" .      mysql_result($result, $i, 'date_field') . "</date_field>" .
		 		"<description>" .     mysql_result($result, $i, 'description') . "</description> </item>";

This does not work

while ($row = mysql_fetch_row($result)){
 $bone .=  "<item> <record_num>" . $row['record_num'] . "</record_num>" .
		 		"<date_field>" .   $row['date_field'] . "</date_field>" .
		 		"<description>" .  $row['description'] . "</description> </item>";

In the code that does not work I get all the information but the actuall variable, $row[‘date_field’] and the like. I have tried mysql_fetch_rows, mysql_fetch_arrays, and mysql_fetch_assoc.
Here is an example of what is returned.

<Item> <record_num></record_num><date_field></date_field><description></description> </item>
<item> <record_num></record_num><date_field></date_field><description></description> </item>
<item> <record_num></record_num><date_field></date_field><description></description> </item>

Please point out what I am doing incorrectly.

8 Years
Discussion Span
Last Post by rouse

The same thing can be done this way properly -

$bone  = '';
while($row = mysql_fetch_array($executed_q))
    $bone .=  "<item> <record_num>" . $row['record_num'] . "</record_num>" .
		 		"<date_field>" .$row['date_field'] . "</date_field>" .
		 		"<description>" .$row['description'] . "</description> </item>";

provided you have 'record_num' , 'date_field' and 'description' as column names in your table.
and $executed_q is the return from your executed query, like
$executed_q = mysql_query('Your query');


Your example is what I was doing given different variable names. I did not check out google, but I have been reading the PHP manual.
I resolved the issue by using UPPER CASE for the variable fields after noticing the spelling in the debugger.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.