savagenoob Posted December 14, 2010 Share Posted December 14, 2010 I am using a htmltable() function in FPDF and while in a MySQL While() loop I need to change the variable name each time it loops through. So basically $html needs to be $html1 on the next loop, $html2 on the next, and so on. Its probably simple, but its late and I'm tired, I can't seem to figure this one out. Here is my unfinished attempt: $htmlnum = 0; $endo = mysql_query("SELECT * FROM endorse WHERE endonum = '$endonum' AND agency = '$agency' ORDER BY ID DESC LIMIT 1"); while($endofetch = mysql_fetch_array($endo)){ $endotype = $endofetch['type']; $htmlnum = $htmlnum++; $p->htmltable($html); } Link to comment https://forums.phpfreaks.com/topic/221604-change-variable-name-in-each-loop/ Share on other sites More sharing options...
RichardRotterdam Posted December 14, 2010 Share Posted December 14, 2010 So basically $html needs to be $html1 on the next loop, $html2 on the next, and so on. You could use variables.variable But why would you want this? There is usualy a better way other then variable variables. Link to comment https://forums.phpfreaks.com/topic/221604-change-variable-name-in-each-loop/#findComment-1147098 Share on other sites More sharing options...
harristweed Posted December 14, 2010 Share Posted December 14, 2010 this is how I would create a changeable variable <?php for($i=0;$i<=10;$i++){ $GLOBALS['html'.$i]=$i; } echo "two=$html2<br />\n"; echo "three=$html3<br />"; ?> Link to comment https://forums.phpfreaks.com/topic/221604-change-variable-name-in-each-loop/#findComment-1147099 Share on other sites More sharing options...
trq Posted December 14, 2010 Share Posted December 14, 2010 This is what arrays are for. Link to comment https://forums.phpfreaks.com/topic/221604-change-variable-name-in-each-loop/#findComment-1147100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.