akelly65 Posted September 13, 2007 Share Posted September 13, 2007 hi there I am quite new with php, my goal is to have a template styled page which displays all my database rows separately, for example for the 5th row, the relevant record would be displayed on www.example.com/index.php?id=5 I have done the below code, this parses only the first record and does not do any more or change by changing ?id=5 / ?id=4 etc, PLEASE PLEASE PLEASE help me do this as I have made a massive database and it is currently pointless as I cant display any of it. I don't really know what I am doing and havn't seen a tutorial which shows what I am trying to achieve, I have been looking around the internet for hours. <?php // Connects to your Database mysql_connect("localhost", "login", "password") or die(mysql_error()); mysql_select_db("news") or die(mysql_error()); // Query $id = $_GET['id']; $data = mysql_query("SELECT * FROM `news` WHERE `id`='.$id.'") or die(mysql_error()); // Results while($info = mysql_fetch_array( $data )) { Print "<center><b>".$info['title'] . " </b> - Flash Games<br>"; Print "<center><b>".$info['id'] . " </b>"; } Print "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/69229-please-please-help-template-variable-in-query/ Share on other sites More sharing options...
recklessgeneral Posted September 13, 2007 Share Posted September 13, 2007 Hi, It's getting pretty late and my eyes aren't as sharp as they are at other times of the day, but it looks like you have some unnecessary dots in your sql query. Try: $data = mysql_query("SELECT * FROM `news` WHERE `id`='$id'") or die(mysql_error()); Let me know what that does for you. Cheers, Darren. Quote Link to comment https://forums.phpfreaks.com/topic/69229-please-please-help-template-variable-in-query/#findComment-347989 Share on other sites More sharing options...
hostfreak Posted September 13, 2007 Share Posted September 13, 2007 The "dots" are what is known as the concatenation operator (http://www.php.net/manual/en/language.operators.string.php), which is perfectly fine. However, he isn't using it right. This should work (as well as should recklessgeneral's) : $data = mysql_query("SELECT * FROM `news` WHERE `id`='" . $id . "'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/69229-please-please-help-template-variable-in-query/#findComment-347991 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.