law Posted March 6, 2008 Share Posted March 6, 2008 I'm sure this can be done but obviously I have the syntax wrong! here is my fetch array command $fieldq="SELECT * FROM fieldnames WHERE id = 1"; $fieldsql=mysql_query($fieldq); $fieldrow = mysql_fetch_array($fieldsql); //------------------Variables------------ $slot1=$fieldrow['slot1']; I would like to generate a while () loop to produce something like $num=1; while ( $num < 30){ $slot.$num=$fieldrow['slot$num']; $num++; } The above code doesn't work so obviously i am making a newbie mistake somewhere.. im sure this has been answered before but i didn't know what to search for to find my answer.. soo sorry in advance, Thanks Link to comment https://forums.phpfreaks.com/topic/94638-variable-within-variables-for-querys/ Share on other sites More sharing options...
kenrbnsn Posted March 6, 2008 Share Posted March 6, 2008 Variables inside single quotes are not evaluated. You want to do something like this: <?php $num=1; while ( $num < 30){ ${slot.$num}=$fieldrow['slot' .$num]; $num++; }?> You may want to consider using an array here: <?php $slot = array(); for ($num=1;$num<30;$num++) $slot[$num] = $fieldrow['slot' . $num]; ?> Ken Link to comment https://forums.phpfreaks.com/topic/94638-variable-within-variables-for-querys/#findComment-484610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.