wwfc_barmy_army Posted June 10, 2008 Share Posted June 10, 2008 Hey, i have this code: $sql = mysql_query("SELECT name FROM type") or die(0); while ($array = mysql_fetch_array($sql)) { //what goes here? } How do i get the values into an array now? something like $myarray[] = $array[]; ? Thanks for any help? Quote Link to comment Share on other sites More sharing options...
trq Posted June 10, 2008 Share Posted June 10, 2008 Depends what outcome you want. The following will get you a multidimensional array. <?php if ($sql = mysql_query("SELECT name FROM type")) { if (mysql_num_rows($sql)) { while ($array = mysql_fetch_array($sql)) { $a[] = $array; } } } ?> Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted June 10, 2008 Author Share Posted June 10, 2008 Well the whole code i have is: <?php if ($sql = mysql_query("SELECT name FROM type")) { if (mysql_num_rows($sql)) { while ($array = mysql_fetch_array($sql)) { $a[] = $array; } } } for($i = 0; $i < sizeof($a); $i++){ echo "var " . $a[$i] . "= document.getElementById('" . $a[$i] ."').value;"; } ?> It is currently just outputting 'Array' into each of the outputs. Any ideas? Thanks. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 10, 2008 Share Posted June 10, 2008 Why not put the echo statement inside the same loop? Then you have no need for the array. e.g. <?php if ($sql = mysql_query("SELECT name FROM type")) { if (mysql_num_rows($sql) > 0) { while ($array = mysql_fetch_array($sql)) { echo "var " . $array['name'] . " = document.getElementById('" . $array['name'] . "').value;"; } } } ?> Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted June 10, 2008 Author Share Posted June 10, 2008 Ah. Yeah. Thats great. I've got one more problem to solve: How can i add this part of the code into the loop: var queryString = "?1=" + 1 + "&2=" + 2; etc? Any ideas? Thanks. 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.