Jump to content

PHP & MySQL - Webpage for each "id" from a table


jege

Recommended Posts

Hello.

I got a table which has userprofiles, they are like. id, username, nickname, email, skype, bla bla bla.

So, like many websites has its like eg: profile.php?id=xxx

I would want to create something similar to that. (I'm not master at php but,) I believe it should be done. Converting the database content to an array, and making an foreach of the array, and make the foreach loop something like this.

if($_GET['id']=='<the id from database>'){
the data here. skype, email etc.
}

If you could help me make this.

Thanks in advance.

Link to comment
Share on other sites

You logic is redundant.  You will simply grab the 'id' from the URL and check it against a table in the database.

 

if (isset($_GET['id']) && !empty($_GET['id'])) {
$id = $_GET['id']; // from example URL: http://www.example.com/profile.php?id=xxx

$sql = "SELECT * FROM `table` WHERE `id` = ". mysql_real_escape_string($id) ." LIMIT 1";
if ($result = mysql_query($sql)) {
	if (mysql_num_rows($result) == 1) {
		$res = mysql_fetch_assoc($result);

		// do stuff here
	}
	else {
		echo 'Record not found.';
	}
}
else {
	trigger_error(mysql_error()); // remove in production
}
}

Link to comment
Share on other sites

Ok, It works after I tweaked it a little for my purpose. Thanks!

I would now want to do an like &function=<something here> eg, an moderator would have an button to remove the profile like, profile.php?id=1&function=delete

So, I tried to do this but It didn't really work.

I did

if(@$_GET['function']=='delete'){
bla bla bla, checking if hes moderator etc etc.
}

But it didn't really work, since it could be run anywhere in the profile.php file. How could I make it work properly?

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.