Muncey Posted March 6, 2007 Share Posted March 6, 2007 Im fairly new to PHP but ive learnt it fast and ive worked very hard learning it. I have made a few simple things but i need help with something very simple that i have yet to learn. Can someone please tell me how i can get something from a database and turn it into a variable. Not anything like a table or anything, something like a persons ID.. if there is a table for members and then there is a field called ID asweell as things like username, email ect... how do i get the ID and use it. I do not want a certain ID, i want the ID of a person logged in at that time, so say they left a message on a guestbook, i could display there ID next to them by simply putting a variable like $member_id. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted March 6, 2007 Share Posted March 6, 2007 You could run a query in your guestbook page looking for the users id and using the $_SESSION['username'] to get the id. Then in your script that posts the data in the guestbook add an extra td to insert the id. Quote Link to comment Share on other sites More sharing options...
fert Posted March 6, 2007 Share Posted March 6, 2007 http://us3.php.net/mysql_query http://us3.php.net/manual/en/function.mysql-fetch-array.php Quote Link to comment Share on other sites More sharing options...
SammyGunnz Posted March 6, 2007 Share Posted March 6, 2007 <?php $db->connect(); $query = $db->query("SELECT * FROM users WHERE userid = '$userid'"); $userinfo = $db->fetch_array($query); $db->close(); echo' <table class="users"> <tr><td>'.$userinfo[id].'</td></tr> <tr><td>'.$userinfo[name].'</td></tr> </table>'; ?> Quote Link to comment Share on other sites More sharing options...
simcoweb Posted March 6, 2007 Share Posted March 6, 2007 The display of the guestbook entries is done using a MySQL query then displaying the data by parsing HTML in the output. I would assume this is done using a 'while' loop so it displays all the entries of your guestbook (or so many per page). So, in that query it's probably asking for all the info in the guestbook entries like this: "SELECT * FROM guestbooks"; Then display it with a while look and in the HTML output you'd specify where their ID would be located in your HTML $results = mysql_query($sql); while ($row = mysql_fetch_array($results) { echo "<table><tr> <td>" . $row['member_id'] . "</td><td>" . $row['member_name'] . "</td> </td> </table><br/>\n"; } Quote Link to comment Share on other sites More sharing options...
Muncey Posted March 6, 2007 Author Share Posted March 6, 2007 Thanks everybody, i think ive got it now. Quote Link to comment 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.