Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-18-2012, 12:18 AM   PM User | #1
johnnycabbage
New Coder

 
Join Date: Nov 2011
Posts: 41
Thanks: 2
Thanked 0 Times in 0 Posts
johnnycabbage is an unknown quantity at this point
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"); 

Last edited by johnnycabbage; 11-18-2012 at 12:38 AM.. Reason: forgot a word
johnnycabbage is offline   Reply With Quote
Old 11-18-2012, 01:47 AM   PM User | #2
minder
Banned

 
Join Date: Oct 2012
Posts: 81
Thanks: 0
Thanked 4 Times in 4 Posts
minder can only hope to improve
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?
minder is offline   Reply With Quote
Old 11-18-2012, 02:20 AM   PM User | #3
johnnycabbage
New Coder

 
Join Date: Nov 2011
Posts: 41
Thanks: 2
Thanked 0 Times in 0 Posts
johnnycabbage is an unknown quantity at this point
You're right, well how could I convert the array into an integer?
johnnycabbage is offline   Reply With Quote
Old 11-18-2012, 02:33 AM   PM User | #4
johnnycabbage
New Coder

 
Join Date: Nov 2011
Posts: 41
Thanks: 2
Thanked 0 Times in 0 Posts
johnnycabbage is an unknown quantity at this point
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'"); 
johnnycabbage is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:58 PM.


Advertisement
Log in to turn off these ads.