Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/184922-displaying-user-info-from-a-view-link/
Share on other sites

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);

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]

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)
?>

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.