I was wondering if someone could help - I'm having trouble getting my sql results into an array which I can then print with a loop.
$scales is an array, and each value in the array gets broken down and put in $scale for the first loop - this works fine. The SQL runs and should return as many rows are there are with that scale in the table. But for some reason, with this setup, I'm only getting one value in $row per loop. Any ideas why it's not returning more?
Any advice appreciated
Many thanks
Code:
//Add the words to each scale array if any were selected
foreach ($scales as $key => $scale) {
$query = "SELECT word FROM words WHERE resultid = ".$resultsid." AND scale = '".$scale."'";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
if (mysql_num_rows($result) != 0 ) {
${$scale . "WordsList"} = "<ul>";
//Add each word to the scaleWordsList array
foreach ($row as $words => $value) {
${$scale . "WordsList"} .= "<li>" . $value."</li>";
}
${$scale . "WordsList"} .= "</ul>";
${$scale . "WordsCount"} = count($row);
} else {
${scale . "WordsCount"} = 0;
}
}
$scales is an array, and each value in the array gets broken down and put in $scale for the first loop - this works fine. The SQL runs and should return as many rows are there are with that scale in the table. But for some reason, with this setup, I'm only getting one value in $row per loop. Any ideas why it's not returning more?
Any advice appreciated
Many thanks