Jump to content

Transfer ID to new query??


JackW

Recommended Posts

I think I have a duh question. I am attaching an ID number to the url
Example someurl?variable1. The ID number is there and I can retrieve it.  How do I get it into my select * from query?


Here is my code:

// open data base
@ $db = mysql_pconnect('someserver.net', 'somedatabase', ' My password');
mysql_select_db('somedatabase1') or die( "Unable to select database");
//fetch Row ID number
$var1 = $_GET['variable1'];
echo $var1;
{
$query= 'SELECT * FROM `sometable` WHERE `ID` LIKE [color=red]??[/color]  LIMIT 0, 5 ';
$query_results=mysql_query($query);
$match_results=mysql_num_rows($query_results);
}

for ($i=0; $i < $match_results; $i++)
{
$row=mysql_fetch_array($query_results);
echo ($row ['body'] );

}

mysql_close($db);

The variable I want is being transferred and it shows up at echo $var1 just fine.  How do I get it to be where the [color=red]??[/color] is in:
$query= 'SELECT * FROM `sometable` WHERE `ID` LIKE [color=red]??[/color]  LIMIT 0, 5 ';

Everything I have tried has presented me with an error message.

If I replace the ?? with the ID number I do get the results I want, but how do I get it place the ID number in the select line automatically?  ???
Link to comment
Share on other sites

Depends what you want...
If you want to select the rows where the ID column is equal to $var1, do this:
$query="SELECT * FROM `sometable` WHERE `ID`='$var1'  LIMIT 0, 5";

Btw, you should read about SQL injections and about mysql_real_escape_string()

Orio.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.