CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Using PHP variable (http://www.codingforums.com/showthread.php?t=282472)

johnnycabbage 11-18-2012 12:18 AM

Using PHP variable
 
How could this be done? It won't allow me to use the $id variable in the mysql_query() function:
PHP Code:

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:
PHP Code:

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



All times are GMT +1. The time now is 01:16 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.