For and While loop in php mysql -
i have following code. there way combine , simplify it?
the output in json.html file should this: ["abc","def","ghi"].
<?php // make mysql connection mysql_connect("localhost", "root", "admin") or die(mysql_error()); mysql_select_db("test1") or die(mysql_error()); // data "example" table $result = mysql_query("select * test_auto_complete") or die(mysql_error()); $menu = array(); while($row = mysql_fetch_assoc($result)) { $menu[] = array("id" => $row['username'],); } foreach($menu $key=>$value) { $menu[$key] = $value['id']; } $my_json_content = json_encode($menu); $file = 'json.html'; $current = file_get_contents($file); file_put_contents($file, $my_json_content); ?> i know code looks bad, so, can me?
thanks
haan
if want put content in file use file_put_contents
$my_json_content = json_encode($menu); $file = 'json.html'; file_put_contents($file, $my_json_content); and use while loop without foreach
while($row = mysql_fetch_assoc($result)) { $menu[] = $row['username']; }
Comments
Post a Comment