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.

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
}
}

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?

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.