Jump to content

[SOLVED] Put SQL into an array


wwfc_barmy_army

Recommended Posts

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.

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;";
    }
  }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.