This question already has an answer here:
I have a javascript array that looks like this, 21,22,22,22,23,23,23,26,27,27 etc. I need to get it into a php array and then use that array to query mysql to search for the values in the array.
I here is my code, I am using this to reload an element with the posted converted array.
$(function() {
$("#deckRefresh").click(function(evt) {
var teset = convertArray(deck_array);
$("#deckTest").load("core/m.deckcontainer.php?cid="+teset)
evt.preventDefault();
})
})
here is the javascript function I am calling to convert the array:
function convertArray(array){
var teset = JSON.stringify(array);
return teset;
}
Converting the array which might have looked like this: 22,22,22,22,23,23,23,23,26,27,28,28 The JSON $_post value returned is this: [22,22,22,22,23,23,23,23,26,27,28,28] After searching stack for answers this is what my code for taking the array and querying mysql looks like:
if($_GET){
$queryTest = str_replace("[","",$_GET['cid']);
$queryTest1 = str_replace("]","",$queryTest);
$esplodCId = explode(',', $queryTest1);
foreach ($esplodCId as $key => $var){
$esplodCId[$key] = (int)$var;
}
$sql = mysql_query("SELECT * FROM cards WHERE cid IN($esplodCId)");
while ($row = mysql_fetch_assoc($sql)){
echo "{$row['img']}<br/>";
}
}
All I want to see for now is just the img info from mysql, when I run this I am getting, "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in...." I can't for the life of me figure out how to get this array into a format in which I can use please help!
deck_array.toString();
instead of thatconvertArray()
– sbeliv01 Jan 15 at 18:34cid
param. – sbeliv01 Jan 15 at 18:36