Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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 01:38 AM. Reason: forgot a word

  • #2
    Banned
    Join Date
    Oct 2012
    Posts
    81
    Thanks
    0
    Thanked 4 Times in 4 Posts
    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?

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts
    You're right, well how could I convert the array into an integer?

  • #4
    New Coder
    Join Date
    Nov 2011
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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'"); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •