mercredi 1 avril 2015

JavaScript Arrays and MySQL

I am trying to connect to a database with PHP and then put all the values returned from the MySQL query into a JavaScript string array.


Here is the code that I have so far.


JavaScript Code:



var noDressing = document.getElementById("temp1").innerHTML;
var noDressingNew = noDressing.split(',');
alert(NoDressingNew);


I am alerting the list for debugging purposes.


Here is the PHP Code (I know that it connects to the database successfully):



<div id="temp1" style="display: none;">
<?php
include "/home/pi/config.php";
$toPrint = "";
$connect = mysqli_connect("localhost", $name, $pass, "items");
if(mysqli_connect_errno()){
echo "<p>Failed to connect to products database!</p>";
}
$result = mysqli_query($connect, "SELECT * FROM products WHERE options=''");
while($row = mysqli_fetch_array($result)){
$id = $row['id'];
$toPrint .= $id . ",";
}
echo rtrim($toPrint, ",");
?>
</div>


This is what my table looks like in the database:



ID | NAME | DESCRIPTION | PRICE | TYPE | OPTIONS


I would like to get all of the records that have an OPTIONS value of "" (an empty string) and then put their IDs into a list.


However, when I run this code, no Alert Box is Displayed at all.


Thanks,





Aucun commentaire:

Enregistrer un commentaire