btd117 Posted November 20, 2006 Share Posted November 20, 2006 I am trying to set up a page like this:ex: /index.php?id=2and was given this code by someone here, yet it still yields a blank page...<?phpinclude 'admin/global.php';$result = mysql_query("SELECT * FROM ncaa ORDER BY id WHERE id='{$_GET['id']}'");while($row=mysql_fetch_array($result)) { print '<p>' .$row['id']. '</p>'; }?>When I remove the WHERE id='{$_GET['id']}', it queries the table results correctly. Do i have a problem with my dB? The table has 3 entries in there for sure with ID set to auto_increment, primary key, and unique. Link to comment https://forums.phpfreaks.com/topic/27834-passing-variables-in-url/ Share on other sites More sharing options...
JasonLewis Posted November 20, 2006 Share Posted November 20, 2006 i'm not tottally sure but doesn't the WHERE clause have to come before the ORDER? and i would add an if statement like this:[code=php:0]if(!isset($_GET['id'])){ $id = 1; }else{ $id = $_GET['id']; }[/code]that, obviously, sets a variable ID with the value of 1 if they didnt specify it in the url, otherwise it sets ID as the one in the url.then change your mysql query to this:[code=php:0]$result = mysql_query("SELECT * FROM `ncaa` WHERE `id`='{$id}' ORDER BY `id` DESC");[/code] Link to comment https://forums.phpfreaks.com/topic/27834-passing-variables-in-url/#findComment-127359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.