mysql_connect ("host", "user", "pass");
mysql_select_db ("DB");
$qryImage = mysql_query ("SELECT strImageURL FROM TableImages WHERE intArtistID = 3 ORDER BY dateCreated DESC");
$numResults = mysql_num_rows ($qryImage);
echo $numResults; // echo is fine... prints the expected result
// the WHILE statement works fine too
while ($row = mysql_fetch_array($qryImage)) {
echo '<pre>';
echo $row['strImageURL'];
echo '</pre>';
}
// why can't I get the results of the query to work in the below example?
$row = mysql_fetch_row ($qryImage);
echo $row[0]['strImageURL'];
echo $row[1]['strImageURL'];
echo $row[2]['strImageURL'];
?>
Is there a means of getting the results by using PHP's ability to handle multidimensional arrays?
<?php
$qryImage = mysql_query ("SELECT strImageURL FROM TableImages WHERE intArtistID = 3 ORDER BY dateCreated DESC");
$numResults = mysql_num_rows ($qryImage);
echo $numResults; // echo is fine... prints the expected result
//******************
// Added this part
// You may want to add some error checking in here also
//******************
$result = mysql_query($qryImage);
// the WHILE statement works fine too
//******************
// Modified the next line
//******************
//while ($row = mysql_fetch_array($qryImage)) {
while ($row = mysql_fetch_array($result)) {
echo '<pre>';
echo $row['strImageURL'];
echo '</pre>';
}
// why can't I get the results of the query to work in the below example?
$row = mysql_fetch_row ($qryImage);
echo $row[0]['strImageURL'];
echo $row[1]['strImageURL'];
echo $row[2]['strImageURL'];
?>
Now you have a query, a query result and an array of result data in the dataset. This should work.
<?php
mysql_connect ("host", "user", "pass");
mysql_select_db ("DB");
$qryImage = mysql_query ("SELECT strImageURL FROM TableImages WHERE intArtistID = 3 ORDER BY dateCreated DESC");
$numResults = mysql_num_rows ($qryImage);
echo $numResults; // echo is fine... prints the expected result
// the WHILE statement works fine too
while ($row = $data[] = mysql_fetch_assoc($qryImage)) {
echo '<pre>';
echo $row['strImageURL'];
echo '</pre>';
}
echo $data[0]['strImageURL'];
echo $data[1]['strImageURL'];
echo $data[2]['strImageURL'];
?>