...

View Full Version : Using PHP variable



johnnycabbage
11-18-2012, 12:18 AM
How could this be done? It won't allow me to use the $id variable in the mysql_query() function:

if (isset($_GET["id"]))
{
$id = explode(":",$_GET["id"]);
}

$result = mysql_query("SELECT * FROM Articles WHERE `ID` = $id");

minder
11-18-2012, 01:47 AM
The explode function returns an array. You can't just plug an array of values into an sql query.

What do you want to do? Do you want to have the array values as part of an IN list in your sql query?

johnnycabbage
11-18-2012, 02:20 AM
You're right, well how could I convert the array into an integer?

johnnycabbage
11-18-2012, 02:33 AM
Wait, using my previous Perl knowledge, I managed to figure it out:

if (isset($_GET["id"]))
{
$id = explode(":",$_GET["id"]);
}
$articleid = $id[0];
echo $id['0'];
$result = mysql_query("SELECT * FROM Articles WHERE `ID` ='$articleid'");



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum