icezapp Posted May 24, 2011 Share Posted May 24, 2011 Hello =) I'm trying to create a javascript array which should be filled with data from a mysql database. so what i wannt to do is to loop out a new array element for each row in my database. I should also say that i'm working in a php file. I tried (and failed) to do it like this: <?php include('databbaseconnect.php'); ?> <script type="text/javascript"> var StoreDetails = [ ['Please select an option','','','','',''], <?php mysql_select_db("alltomboule_se", $db); $result = mysql_query("SELECT * FROM spelare"); while($row = mysql_fetch_array($result)) { echo "['".$row['namn'].$row['enamn']."','".$row['namn'].",'".$row['enamn']."','".$row['klubb']."','".$row['licensnr']."','".$row['id']."'],"; } ?> ['','','','','',''] // Note: no comma for last row ]; I wannt the array to look like this: var StoreDetails = [ ['Please select an option','','','','',''], ['Oscar Andersson','Oscar','Andersson','BON','16643','2'], ['Olle Johansson','Olle','Johansson','BFT','14443','3'], ['Ingvar Andersson','Ingvar','Andersson','BON','14333','4'], ['Kalle Kula','Kalle','Kula','BON','34576','5'], ['','','','','',''] ]; Quote Link to comment Share on other sites More sharing options...
trq Posted May 24, 2011 Share Posted May 24, 2011 Just use json_encode and be done with it. Quote Link to comment Share on other sites More sharing options...
icezapp Posted May 24, 2011 Author Share Posted May 24, 2011 I'm not very familiar to json but I tested some. With the json_encode() I get it in php format but I wannt it in javascript format. so basicly i want to reciev all rows form my database and convert it into a javascript array with the format below. var StoreDetails = [ ['Please select an option','','','','',''], ['Oscar Andersson','Oscar','Andersson','BON','16643','2'], ['Olle Johansson','Olle','Johansson','BFT','14443','3'], ['Ingvar Andersson','Ingvar','Andersson','BON','14333','4'], ['Kalle Kula','Kalle','Kula','BON','34576','5'], ['','','','','',''] ]; as i said i'm new to Json and pretty new to Javascript so i'm greatful for help Quote Link to comment Share on other sites More sharing options...
trq Posted May 25, 2011 Share Posted May 25, 2011 json_encode does not produce a php formatted anything. It produces a JavaScript object which will in turn contain your array. Quote Link to comment Share on other sites More sharing options...
slots6 Posted April 28, 2013 Share Posted April 28, 2013 карточная игра ответ поле чудес nevosoft Игровые Автоматы Император букс казино еще игровые автоматы играть бесплатно онлайн за интерес чайковский Автоматы онлайн казино покер техасский правила! 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.