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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.