Jump to content

profiles


dezkit

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/116477-profiles/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/116477-profiles/#findComment-598980
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/116477-profiles/#findComment-599166
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/116477-profiles/#findComment-599180
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.