Hi All,
I'm trying to make a members page, which has personalized content, depending on what's in the URL:members.php?username_here
Just a simple IF statement would suffice...
Thanks,
X96
Hi All,
I'm trying to make a members page, which has personalized content, depending on what's in the URL:members.php?username_here
Just a simple IF statement would suffice...
Thanks,
X96
Last edited by X96 Web Design; 04-22-2009 at 03:27 AM. Reason: solveded
Alex Blackie, X96 Design
My Website
I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration
This won't be a simple IF statment I don't think. Unless you're planning on only having 2 - 3 members. You'll need to query a database to find if said member ID exists, then display relevant data depending on the records returned from the query...
If however you do only plan to have a couple of members then it's pretty simple:
This will be static, and mean that if you want to update the information on a members page you'll need to go and hardcode it in again. =/PHP Code:if(isset($_GET['member'])) {
if($_GET['member'] == 1) {
// All relevant code for this member here, example:
echo "<h1>Welcome to {$membername}'s page!</h1>";
}
elseif($_GET['member'] == 2) {
// All relevant code for this member
}
// And so on...
else {
echo "Member does not exist.";
}
}
Sorry about the formatting, you know how it is when trying to indent online >.<
I have a working registration page and log in set up, so all the database stuff is there, I just need to pull in different content from different tables depending on what the$_GETis set to...
Something like in Wordpress, where it has/index.php?page_id=53and it displays a page depending on thepage_idvariable.
Sorry if I'm not making it very clear...
Thanks,
X96
Alex Blackie, X96 Design
My Website
I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration
Oh I see, you do have a database...
Well then it would be a bit like this:
That's the structure of what I think you're looking for, of course you can build on this with more advanced functions and you'll need to make it look presentablePHP Code:<?php
if(isset($_GET['member'])) {
$member = mysql_real_escape_string($_GET['member']); // Make safe for query
// I'm going to assume you have a table called members
$memberq = mysql_query("SELECT * FROM members WHERE `id` = '$member'");
if(mysql_num_rows($memberq)) { // If any rows are returned
$row = mysql_fetch_row($memberq); // Since Id will be / is a primary key, only one record will be returned
/* So we use mysql_fetch_row as we don't need a while loop to go through multiple records
Only drawback is that the row comes back as a numerical array so we have to use [0] to address columns
We'll say the setup is like this:
[0] = id (Unique identifier)
[1] = name
[2] = bio (biography)
[3] = location
[4] = email
Obviously these are just test columns and you can add different ones if you want
I just don't know what data you'll want on the member's page
Break out of PHP to output HTML
*/
?>
<div id="memberheader"><?php echo $row[1] . '\'s profile.'; ?></div>
<div id="memberinfo">
<h3>About <?php echo $row[1]; ?></h3>
Biography: <?php echo $row[2]; ?>
<p>Location: <?php echo $row[3]; ?></p>
<p>Email: <?php echo $row[4]; ?></p>
</div>
<?php
}
else {
echo "The member you're looking for doesn't exist.";
}
}
?>
Hope this helps you out though.
X96 Web Design (04-22-2009)
Thank you so much Schmoopy! It works exactly like I wanted it to! I've been trying to make something like that for hours - I'm not that great at writing PHP yet...
Cheers,
X96 WD
Alex Blackie, X96 Design
My Website
I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration
No problem, now you've got the structure there it's pretty simple to add more columns, so have fun with it![]()
Bookmarks