I have this section of my PHP script that loops through a recordset and stores the data into variables.
$sql_result5 = mysql_query("SELECT * FROM turfs WHERE city = '$city'", $db); $query++;
while ($rs5 = mysql_fetch_array($sql_result5)) {
if ($rs5[plot] != "") {
${$rs5[plot].'_exist'} = 1;
${'$p_color_'.$rs5[plot]} = $rs5[color];
${$rs5[plot].'_1'} = $rs5[color1];
}
}
I then use this data to populate a 20×20 grid, so that loop would be going through 400 records storing data for each, and for each record (box in the grid) there needs to be about 5 or so variables.
Is it a bad idea creating so many variables? Is there a better way to do this? Maybe an array?
Creating variables, as you’ve done, isn’t the best way to do this. Instead, either use an
array, or create the grid within thewhileloop.Create an Array
Then…
Or, Create Grid Within
while