Masonjars Posted December 12, 2009 Share Posted December 12, 2009 Hey, i am very new to php and mysql. I have a list of users with "view" links next to each. I want the admin to be able to click the link.. and see all of the users information.. including their pictures. I cannot figure out how to do this or how to specify that the link is for a specific user. help? thanks! Laura Quote Link to comment https://forums.phpfreaks.com/topic/184922-displaying-user-info-from-a-view-link/ Share on other sites More sharing options...
.josh Posted December 12, 2009 Share Posted December 12, 2009 how is the info stored? ideally you would have the info stored in a db and each row (use) would have a unique id associated with it. You would then select the rows from the database, including the id and loop through each row, displaying your link. Each link url would have the id appended to it, and then the target script would pull the user's info based on the id. Example: $sql = "select user, id from table"; $result = mysql_query($sql); while ($users = mysql_fetch_assoc($result)) { echo "<a href='viewInfo.php?id={$users['id']}'>{$users['user']}</a>"; } viewInfo.php $sql = "select * from table where id='{$_GET['id']}'"; $result = mysql_query($sql); $user = mysql_fetch_assoc($result); print_r($user); Quote Link to comment https://forums.phpfreaks.com/topic/184922-displaying-user-info-from-a-view-link/#findComment-976205 Share on other sites More sharing options...
Masonjars Posted December 13, 2009 Author Share Posted December 13, 2009 thanks! it seems like it should work.. but it says that i am calling an undefined function. my info is stored in a database and every user has a unique id. here is my code: // OUTPUT THE TABLE OF CONTACT INFO HERE $sql = 'SELECT id, fname, lname, email FROM users'; require_once 'db_connect.php'; $query_result = query($sql); $altrow = false; echo '<table id="addresses" cellspacing="0">' . "\n"; echo '<tr><th>First name</th><th>Last name</th><th>Email</th><th></th><th></th></tr>' . "\n"; while ($row = mysql_fetch_assoc($query_result)) { echo ($altrow) ? '<tr class="altrow">' : '<tr>'; //this is a compacted if statement above. $altrow = !$altrow; echo '<td>' . $row['fname'] . "</td>\n"; echo '<td>' . $row['lname'] . "</td>\n"; echo '<td>' . $row['email'] . "</td>\n"; echo '<td><a href="admin/view.php?id=' . $row['id'] . '">View</a></td>' . "\n"; echo '<td><a href="admin/edit.php?id=' . $row['id'] . '">Edit</a></td>' . "\n"; echo "</tr>\n"; } and the view.php file code: $sql = 'SELECT * FROM users WHERE id=' . mysql_real_escape_string(trim($_GET['id'])); require_once '../db_connect.php'; $query_result = query($sql); $row = mysql_fetch_assoc($query_result); view_contact($row); i also attached them.. because since i've already started working on this.. i have some different variable names and such.. thanks so much for your help!! you guys are brilliant. Laura [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/184922-displaying-user-info-from-a-view-link/#findComment-976279 Share on other sites More sharing options...
GFXUniverse Posted December 13, 2009 Share Posted December 13, 2009 for view.php <?php require_once '../db_connect.php'; //DB connection first! $id = mysql_real_escape_string(trim($_GET['id'])); $sql = "SELECT * FROM users WHERE id=$id" $query_result = query($sql); $row = mysql_fetch_assoc($query_result); view_contact($row); // make sure this function is defined in your file (or included file) ?> Quote Link to comment https://forums.phpfreaks.com/topic/184922-displaying-user-info-from-a-view-link/#findComment-976295 Share on other sites More sharing options...
Masonjars Posted December 13, 2009 Author Share Posted December 13, 2009 hooray!! thank you so much! it worked!! <3 Quote Link to comment https://forums.phpfreaks.com/topic/184922-displaying-user-info-from-a-view-link/#findComment-976373 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.