jege Posted May 23, 2012 Share Posted May 23, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263006-php-mysql-webpage-for-each-id-from-a-table/ Share on other sites More sharing options...
mrMarcus Posted May 23, 2012 Share Posted May 23, 2012 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 } } Quote Link to comment https://forums.phpfreaks.com/topic/263006-php-mysql-webpage-for-each-id-from-a-table/#findComment-1348049 Share on other sites More sharing options...
jege Posted May 24, 2012 Author Share Posted May 24, 2012 Haha, thanks Ill try it now Im quite new to php so yeah. Quote Link to comment https://forums.phpfreaks.com/topic/263006-php-mysql-webpage-for-each-id-from-a-table/#findComment-1348252 Share on other sites More sharing options...
jege Posted May 24, 2012 Author Share Posted May 24, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/263006-php-mysql-webpage-for-each-id-from-a-table/#findComment-1348308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.