Kays Posted May 22, 2012 Share Posted May 22, 2012 It still doesn't make too much sense. What do you want to accomplish with $ID. Your best bet would be to grab a SQL book and learn basic SQL statements. There is a MySQL Help forum. My guess: $sql = sprintf('SELECT * FROM `articles` WHERE `col_id_field` = %d;', mysql_real_escape_string($ID)); Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1347596 Share on other sites More sharing options...
craygo Posted May 22, 2012 Share Posted May 22, 2012 no need to sort by ID since this is the page that will retrieve the id from your previous list. You would sort that list by ID. <?php $ID = mysql_real_escape_string($_GET['ID']); $sql = "SELECT * FROM articles WHERE ID = '$ID'; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); // no need to loop since you are retrieving only one row $num_rows = mysql_num_rows($res); // check to see if any results were found, just in case someone puts an ID in the url without clicking on your link if($num_rows > 0) { echo $row['ID'].' '.$row['title'].' '.$row['intro']; } else { echo "No results found"; } ?> Try it out Ray Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1347648 Share on other sites More sharing options...
justlukeyou Posted May 22, 2012 Author Share Posted May 22, 2012 Brilliant, thanks ever so much for this. It did create one error so I took out the query and put it in a string and did echo the results which is just test material so its definately getting there. SELECT * FROM articles WHERE ID = ''2 Cats Are Best You will find Cats are the best $query_string= "SELECT * FROM articles WHERE ID = '$ID'"; echo $query_string; $query = mysql_query($query_string); This the error it created: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/ukhomefu/public_html/articles/article.php on line 137 Which refers to this line: echo $row['ID'].' '.$row['title'].' '.$row['intro']; Does the error above mean anything to anyone? Should there be brackets somewhere? Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1347702 Share on other sites More sharing options...
Drummin Posted May 22, 2012 Share Posted May 22, 2012 Could echo this way. echo "{$row['ID']} {$row['title']} {$row['intro']}"; Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1347739 Share on other sites More sharing options...
mrMarcus Posted May 22, 2012 Share Posted May 22, 2012 Could echo this way. echo "{$row['ID']} {$row['title']} {$row['intro']}"; Is no difference. I'm stumped at this line: SELECT * FROM articles WHERE ID = ''2 Cats Are Best You will find Cats are the best What is that and where did it come from? Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1347741 Share on other sites More sharing options...
justlukeyou Posted May 22, 2012 Author Share Posted May 22, 2012 Hi, This line is what was echoed onto the screen when I put the query into a string. SELECT * FROM articles WHERE ID = ''2 Cats Are Best You will find Cats are the best The ID is 2 Title: 2 Cats Are Best Intro: You will find Cats are the best So it does work but only when I put it in a query string which also echoes the query. Does this help at all? Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1347746 Share on other sites More sharing options...
justlukeyou Posted May 24, 2012 Author Share Posted May 24, 2012 Hi, echo $row['ID'].' '.$row['title'].' '.$row['intro']; It creates this error. Does anyone have any suggestions on what I can do to resolve this. This the error it created: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/home/public_html/articles/article.php on line 137 Can I add something like this or die(mysql_error()); to get more information? Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1348215 Share on other sites More sharing options...
Jessica Posted May 24, 2012 Share Posted May 24, 2012 What's the line above that one Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1348270 Share on other sites More sharing options...
justlukeyou Posted May 24, 2012 Author Share Posted May 24, 2012 Please see below all the code I have: <?php $ID = mysql_real_escape_string($_GET['ID']); $sql = "SELECT * FROM articles WHERE ID = '$ID'; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); // no need to loop since you are retrieving only one row $num_rows = mysql_num_rows($res); // check to see if any results were found, just in case someone puts an ID in the url without clicking on your link if($num_rows > 0) { echo $row['ID'].' '.$row['title'].' '.$row['intro']; } else { echo "No results found"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1348343 Share on other sites More sharing options...
Jessica Posted May 24, 2012 Share Posted May 24, 2012 The syntax highlighting shows the error. It's at the end of the 2nd line. Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1348344 Share on other sites More sharing options...
Drummin Posted May 24, 2012 Share Posted May 24, 2012 You probably should make sure GET isset before running query. <?php if (isset($_GET['ID'])){ $ID = mysql_real_escape_string($_GET['ID']); $sql = "SELECT * FROM articles WHERE ID = '$ID'; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); // no need to loop since you are retrieving only one row $num_rows = mysql_num_rows($res); // check to see if any results were found, just in case someone puts an ID in the url without clicking on your link if($num_rows > 0) { echo $row['ID'].' '.$row['title'].' '.$row['intro']; } else { echo "No results found"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1348348 Share on other sites More sharing options...
justlukeyou Posted May 24, 2012 Author Share Posted May 24, 2012 Jesirose, you are a STAR. Now I have nice, tidy links with just the ID number. Fabulous. Quote Link to comment https://forums.phpfreaks.com/topic/262693-struggling-with-get-on-receiving-page/page/2/#findComment-1348424 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.