dannybrazil Posted March 26, 2008 Share Posted March 26, 2008 Hello i have a page that im queiring information from database and placing it in a table then one colum represents something from the database one of the colums is "Title"(of a posting made by a user) this "Title" is a link to another page that i want to display all the information that the user posted by adding to the link the ID from the database and "echo"-ing it in the second page first is the code line used in the first page : $link = "http://www.mywebsite.com/next.php?id=$id"; it all passed good and the address (of the second page) looks like that : http://www.mywebpage.com/next.php?34 now i wanted to know how can i write a code that will help me to retrive all the information i need from the specific ID in the specific table in the DB ? thanks Link to comment https://forums.phpfreaks.com/topic/98024-retriving-information-from-database/ Share on other sites More sharing options...
kevincro Posted March 26, 2008 Share Posted March 26, 2008 I'm not really sure what all you are trying to do. I might need some more info, but the following is a select query that will return all the data associated with $id. <? //The following pulls the variable from the url of the second page. $id = $_GET['id']; //The following begins the select query $result = mysql_query("SELECT * FROM (your db table name) WHERE (column name containing $id) = '$id'"); while ($row = mysql_fetch_array($result)){ //the following sets up the table that will display the data. The while loop will return all rows that have the //same $id. Note that you should the name of the column where it says column name. You can display as //many columns as the db table contains. echo "<TR>"; echo "<TD>$row['column name']</TD>"; echo "<TD>$row['column name']</TD>"; echo "<TD>$row['column name']</TD>"; echo "<TD>$row['column name']</TD>"; echo "</TR>"; } ?> Link to comment https://forums.phpfreaks.com/topic/98024-retriving-information-from-database/#findComment-501559 Share on other sites More sharing options...
soycharliente Posted March 26, 2008 Share Posted March 26, 2008 Make sure that you are sanitizing the data before putting it into the query also to protect against SQL injections. Link to comment https://forums.phpfreaks.com/topic/98024-retriving-information-from-database/#findComment-501562 Share on other sites More sharing options...
kevincro Posted March 26, 2008 Share Posted March 26, 2008 I don't mean to hijack this thread but could you explain how to sanitize the data? Link to comment https://forums.phpfreaks.com/topic/98024-retriving-information-from-database/#findComment-501564 Share on other sites More sharing options...
dannybrazil Posted March 26, 2008 Author Share Posted March 26, 2008 yep that was it , thanks also i would like to know more about the : Make sure that you are sanitizing the data before putting it into the query also to protect against SQL injections. thanks Link to comment https://forums.phpfreaks.com/topic/98024-retriving-information-from-database/#findComment-501568 Share on other sites More sharing options...
soycharliente Posted March 26, 2008 Share Posted March 26, 2008 Escaping the data to protect from injections. JFGI ^ /joke Link to comment https://forums.phpfreaks.com/topic/98024-retriving-information-from-database/#findComment-501571 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.