phpretard Posted February 16, 2008 Share Posted February 16, 2008 The code below wont give the desired result. while($row = mysql_fetch_array($result)) { $url=$row['url']; $id=$row['id']; $num="0"; $pic="messages[$num] = new Array('../$url');"; echo $pic; $num++; } the desired result is messages[0] = new Array('../$url'); messages[1] = new Array('../$url'); messages[2] = new Array('../$url'); messages[3] = new Array('../$url'); and so on... Can someone please throw a bone here? -Anthony Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 16, 2008 Share Posted February 16, 2008 Try <?php $num=0; while($row = mysql_fetch_array($result)) { $url=$row['url']; $id=$row['id']; $pic="messages[".$num."] = new Array('../$url');"; echo $pic; $num++;} Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted February 16, 2008 Share Posted February 16, 2008 Hello, You can't increment a string, which $num was before. Also, you won't get any results from putting $num inside the while loop either because it'll always reset itself to zero. To do this, you have to put it outside the loop. $num = 0; while($row = mysql_fetch_array($result)) { $url=$row['url']; $id=$row['id']; $pic="messages[$num] = new Array('../$url');"; echo $pic; $num++; } Ken Quote Link to comment Share on other sites More sharing options...
phpretard Posted February 16, 2008 Author Share Posted February 16, 2008 Thank you for the code help and especially the reason why! Quote Link to comment Share on other sites More sharing options...
Barand Posted February 16, 2008 Share Posted February 16, 2008 Hello, You can't increment a string, ... Want to put money on that? <?php $str = 'a'; for($i=0;$i<=25;$i++){ echo $str++; } ?> --> abcdefghijklmnopqrstuvwxyz Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.