dezkit Posted July 24, 2008 Share Posted July 24, 2008 i have this code <?php mysql_connect("localhost", "admin", "pw") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $q = mysql_query("SELECT * FROM example") or die(mysql_error()); echo "<table border='0'>"; while($row = mysql_fetch_array( $q )) { echo "<tr><td><a href='index.php?page=profiles&id=$id'>"; echo $row['name']; echo "</a></td></tr>"; } echo "</table>"; ?> how do i do so each person in my database has its own page for example, website.com/index.php?page=profiles&id=1 for a person with an ID in the database of 1. and in each profile it just says the persons name, thats all, the rest i will do thanks guys Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 24, 2008 Share Posted July 24, 2008 You make links exactly how you are doing page=profiles&id=1 Now you just take the "id" part of the URL and put it in the query. SELECT * FROM example WHERE id='{$_GET['id']}' Now you have all the information selected for that specific person. Just make sure you sanatize your $_GET['id'] variable before using it in the query, I didn't just for the example. Quote Link to comment Share on other sites More sharing options...
dezkit Posted July 25, 2008 Author Share Posted July 25, 2008 please elaborate Quote Link to comment Share on other sites More sharing options...
dezkit Posted July 25, 2008 Author Share Posted July 25, 2008 bump it up Quote Link to comment Share on other sites More sharing options...
peranha Posted July 25, 2008 Share Posted July 25, 2008 You make links exactly how you are doing page=profiles&id=1 Now you just take the "id" part of the URL and put it in the query. SELECT * FROM example WHERE id='{$_GET['id']}' Now you have all the information selected for that specific person. Just make sure you sanatize your $_GET['id'] variable before using it in the query, I didn't just for the example. Just as he said. Use $_GET['id'] and that will get the id from the url. Then use that in the SQL query to get all the info from the database that has that id. SELECT * FROM tablehere WHERE tableidfield = '{$_GET['id']}' that will collect all data from that specific table with the id of the url id. Do you know how to insert the id into the url, or do you need to know how to do that?? All that will go in the profile page. and the display it how you want it. Quote Link to comment Share on other sites More sharing options...
dezkit Posted July 25, 2008 Author Share Posted July 25, 2008 i am very very stupid and un-logical can somebody update my script? thanks a bunch and sorry Quote Link to comment Share on other sites More sharing options...
peranha Posted July 25, 2008 Share Posted July 25, 2008 what is your table name, and what is the id field?? Quote Link to comment Share on other sites More sharing options...
dezkit Posted July 25, 2008 Author Share Posted July 25, 2008 my database name = test my table name = users my id field = 1 Quote Link to comment Share on other sites More sharing options...
TransmogriBenno Posted July 25, 2008 Share Posted July 25, 2008 I'm pretty sure that the name of the field that stores the ID value is not '1'. Check again. Quote Link to comment Share on other sites More sharing options...
peranha Posted July 25, 2008 Share Posted July 25, 2008 <?php mysql_connect("localhost", "admin", "pw") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $q = mysql_query("SELECT * FROM users WHERE id = '{$_GET['id']}'") or die(mysql_error()); echo "<table border='0'>"; while($row = mysql_fetch_array( $q )) { echo "<tr><td><a href='index.php?page=profiles&id=$id'>"; echo $row['name']; echo "</a></td></tr>"; } echo "</table>"; ?> Also, I was woundering what the id column is called, if it is just id, then the above will work. Quote Link to comment 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.