Trouble embedding PHP variables in a MySQL query...
Posted: Tue Jul 12, 2005 7:21 pm
I know it's simple, but I can't seem to figure this out. I am looping through a few lines of code in order to pull certain data from a mysql table. Each column of the table has a similar name, only differing by a character. I want to have that character change each loop, like the following:
I know I'm not using the correct syntax to get the $aaa variable embedded into the word "first***last". Ideally, the output of this loop would be, for $max=4:
Code: Select all
for($aaa=0; $aaa<=$max; $aaa++){
$sql = "SELECT first{$aaa}last FROM mytable WHERE id=$aaa";
$result = mysql_query($sql);
$myvalue = mysql_result($result,0,0);
}- first0last
first1last
first2last
first3last
first4last