...

View Full Version : A very silly query question...



stfc_boy
11-10-2007, 02:10 PM
Hello,

I have a query:



$SQL = "SELECT * FROM table WHERE id=".$_GET['id'];


But if I add order by to it:



$SQL = "SELECT * FROM table WHERE id=".$_GET['id'] Order by table_id;


It fails? I know it's something to do with the " being out of place, but surely it has to be there?

Thank you

abduraooft
11-10-2007, 02:33 PM
$SQL = "SELECT * FROM table WHERE id='".$_GET['id']."' Order by table_id";

shedokan
11-10-2007, 09:17 PM
a better way to do it I think is this:

$SQL = "SELECT * FROM table WHERE id='$_GET['id']' Order by table_id";

CFMaBiSmAd
11-10-2007, 09:27 PM
That will actually generate a php parse error, because php needs help in figuring out what part of that is the array variable. This will work however -

$SQL = "SELECT * FROM table WHERE id='{$_GET['id']}' Order by table_id";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum