JQuery - Load Info From Database, Into Different Variables?
Basically I can do so it prints out for example one field from the table, but I want to have all of them to different tables or whatever, how would I achieve this? I got this as my
Solution 1:
Looks like Joroen helped you out with the ajax side and hopefully you added the comma he was talking about. The php/mysqli part can be written like this:
<?php
include '../inc/_db.php';
$code = $_GET['code'];
$query = mysqli_query($db, "SELECT * FROM data WHERE code='$code'");
$row = mysqli_fetch_array($query));
print json_encode($row);
?>
In reality this code is scary because you're not cleaning any of the incoming data and using it directly in a SQL statement. Since you already know it's only allowing A-Za-z0-9 characters you should check the value of $_GET['code'] to make sure it's safe to use. I also highly recommend using mysqli prepared statements to avoid some of the funny stuff that can happen with tainted input.
Solution 2:
this is probably a bad programming practice but that is how i would do it.
while($row = mysqli_fetch_array($query)) {
$return = $row['coins'].",".$row['id'; //separate the send the values as a comma-separated string
echo $return;
}
the js would look like this
$('#coins').load('ajax/loadData.php?code=' + $.cookie('code')); //collect the values here
var values = $(#coins).text(); //save the values in a srting
var array_of_values = values.split(","); //split the string at a delimiter and save the values in an array
mind you, this is not likely to work if the query returns multiple rows
Post a Comment for "JQuery - Load Info From Database, Into Different Variables?"