Jump to content

PHP View Profile code?


maxihobbs

Recommended Posts

Ive just set up a members table whereby the user clicks on the the member page and is shown each registered users details (name, email, about etc), like a memberlist page.

 

I now want to able to allow each user to be able to view any profile by selecting view profile on any user they so wish?

 

Ive no idea where to start, can anyone help here

 

Any help would be fantastic!

 

Thanks

Link to comment
Share on other sites

Set up a query that grabs the users data from the database with the given id.

 

example:

$id = mysql_real_escape_string($_GET['user_id']); //Lets say it equals 1
$query = "SELECT * FROM users_table WHERE id = " . $id;
$result = mysql_query($query);
$data = mysql_fetch_array($result);
echo $data['username']; //if the row is a username, it would echo that username

 

I tried to explain as best as possible, I'm not good at explaining. Hope I was at least able to help a little.

 

EDIT: I think I may have misunderstood what you meant. If I did, I apologize.

Link to comment
Share on other sites

Ive just set up a members table whereby the user clicks on the the member page and is shown each registered users details (name, email, about etc), like a memberlist page.

 

I now want to able to allow each user to be able to view any profile by selecting view profile on any user they so wish?

 

Ive no idea where to start, can anyone help here

 

Any help would be fantastic!

 

Thanks

 

xnowandtheworldx has got 90% of what you want - which is retrieving the actual data. Now you just need a link so you know what data to receive.

 

With xnowandtheworldx code you can now view a page liek this and it will retrieve the data:

 

http://domain.com/?user_id=useridnum

 

But approaching that is down to you. You will likely need to separate this so the user link is:

 

/profile/user_id=useridnum

 

or the nicer htaccess way:

 

/profile/useridnum/

 

also, make damn sure to validate whatever variable you use within your sql query. If user_id is a num, use:

 

$id = intval($_GET['user_id']);

 

..eek, probably just did more to confuse you. Read xnowandtheworldx code over and over until you get the gist of how to retrieve specific profiles. Then work on the link your website will use to run the query.

Link to comment
Share on other sites

Thanks for the feedback.

 

Where would this code be input then, I've read it over and over and see how it works but am confused as to where to implement it.

 

Here's my page so far:

 

<div class="dividerA">

<?php

$username="";

$password="";

$database="";

 

mysql_connect(localhost,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM users";

$result=mysql_query($query);

 

$num=mysql_numrows($result);

 

mysql_close();

?>

<table border="0" cellspacing="2" cellpadding="2">

<tr>

<th>Member Number</font></th>

<th>First Name</font></th>

<th>Last Name</font></th>

<th>Email</font></th>

<th>About</font></th>

<th>Profile</font></th>

</tr>

 

<?php

$i=0;

while ($i < $num) {

 

$f1=mysql_result($result,$i,"id");

$f2=mysql_result($result,$i,"first");

$f3=mysql_result($result,$i,"last");

$f4=mysql_result($result,$i,"email");

$f5=mysql_result($result,$i,"about");

?>

 

<tr>

<td><?php echo $f1; ?></font></td>

<td><?php echo $f2; ?></font></td>

<td><?php echo $f3; ?></font></td>

<td><?php echo $f4; ?></font></td>

<td><?php echo $f5; ?></font></td>

<td><?php echo 'View Profile'; ?></font></td>

</tr>

 

 

<?php

$i++;

}

?>

</div>

 

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.