Viewing Separate Information

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Arsenal Rule
Forum Commoner
Posts: 26
Joined: Fri Apr 08, 2005 4:13 am

Viewing Separate Information

Post by Arsenal Rule »

I have created a file called testview.php which consists of a table which shows all the data that is in the "user" table in a database. I have created the Username to be a hyperlink, but what i want it to do is view all the information for that particular user on another page when clicking the users respective name.

heres my current code:

Code: Select all

<td><?php 


		$conn = mysql_connect("localhost","root","") or die("Could Not Connect To The Database"); 
		mysql_select_db("aziz",$conn) or die("Could Not Select The Database"); 
		


	$result=mysql_query("SELECT user_id,az_firstname,az_surname,username FROM azizpassword ORDER BY user_id;");
	
	$i=0;
	while( $row=mysql_fetch_array($result) )
	{
		if($i>0)
		{
			echo "<tr valign=top>";
			echo "<td bgcolor=#ffffff background='img/strichel.gif' colspan=6><img src=img/blank.gif wuser_idth=1 height=1></td>";
			echo "</tr>";
		}
		echo "<tr valign=center>";
		echo "<td width=100 class=table><b>".$row['user_id']."</b></td>";
		echo "<td width=100 class=table><a href='view.html'>".$row['az_surname']."</a></td>";
		echo "<td width=100 class=table>".$row['az_firstname']." </td>";
		echo "<td width=100 class=table><i>".$row['username']."</i> </td>";
		
		echo "<td class=table></td>";
		echo "</tr>";
		$i++;

	}

	echo "<tr valign=bottom>";
        echo "<td bgcolor=#fb7922 colspan=6><img src=img/blank.gif wuser_idth=1 height=8></td>";
        echo "</tr>";
			
	 
?></td>
This is the code i have done to create the table that has the user name as a hyperlink.

for now, i would appreciate the help on how to view a particular users details (number, surname, firstname, password) on a different page when clicking on the hyperlink of his surname.

i know that i am just seeing the same information again on a different page (for the time being, but on a different page, however, i will redesign and modify etc.. after. :)

I hope someone could help me with this thank you very much for your time
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

you can use session for that, but if i were you, i would do something like this:

echo"<a href=\"view.php?id=".$row['user_id']."\">".$row['az_surname']."</a>";

then next page:
$user_id = intval($_GET['id']);

use this id to do a query in order to get all info about the user.
Arsenal Rule
Forum Commoner
Posts: 26
Joined: Fri Apr 08, 2005 4:13 am

Viewing Separate Information

Post by Arsenal Rule »

i aint actually created a "view.php" page, do i need to??

what are the actual steps in order to do the job??

at the risk of sounding too demanding for my own good, could you copy and paste in places and construct a working version for me?? i can sort of understand what you mean, but i am a less than advanced user :( i just wanna learn :(

What other steps are there to take in order to get the job done??

Thanks a lot mate for the quick reply, you been a good help so far already!!! cheers mate!!
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

I modified the just a little bit or your code to use the link that hongco suggested.

Code: Select all

while( $row=mysql_fetch_array($result) )
    {
        if($i>0)
        {
            echo "<tr valign=top>";
            echo "<td bgcolor=#ffffff background='img/strichel.gif' colspan=6><img src=img/blank.gif wuser_idth=1 height=1></td>";
            echo "</tr>";
        }
        echo "<tr valign=center>";
        echo "<td width=100 class=table><b>".$row['user_id']."</b></td>";
        echo "<td width=100 class=table><a href=\"view.php?id=".$row['user_id']."\">".$row['az_surname']."</a></td>";
        echo "<td width=100 class=table>".$row['az_firstname']." </td>";
        echo "<td width=100 class=table><i>".$row['username']."</i> </td>";
        
        echo "<td class=table></td>";
        echo "</tr>";
        $i++;
 
    }
so then when the username is clicked you page will go to view.php
view.php

Code: Select all

<?php
if(isset($_REQUEST['user_id']))
{
$user_id = $_REQUEST['user_id'];
//your database connection stuff here.

//sql query somethinglike
$sql = "SELECT * FROM users_table WHERE user_id = '$id'";

//your display stuff here.


}
?>
Arsenal Rule
Forum Commoner
Posts: 26
Joined: Fri Apr 08, 2005 4:13 am

thanks!!

Post by Arsenal Rule »

thanks a lot PHPSCOTT!!!

makes a bit more sense now, the testview.php file is working nicely and is linking to the view.php file.

ive done the design for my view.php file, and its all working well, but, its got a few teething errors, my echo statements wont work.

what i'm trying to get at is, getting a layout for each different user, so when they click on their name in the testview.php table, on the view.php file they see:

- [az_firstname][az_surname] at the top in Bold as a header,
- [user_id] a few spaces below in normal font and
- [password] 2 spaces below user_id in normal font

here is my code for testview.php which works and links nicely to the view.php

Code: Select all

<?php 


		$conn = mysql_connect("localhost","root","") or die("Could Not Connect To The Database"); 
		mysql_select_db("aziz",$conn) or die("Could Not Select The Database"); 
		


	$result=mysql_query("SELECT user_id,az_firstname,az_surname,username FROM azizpassword ORDER BY user_id;");
	
	$i=0;
	while( $row=mysql_fetch_array($result) )
	{
		if($i>0)
		{
			echo "<tr valign=top>";
			echo "<td bgcolor=#ffffff background='img/strichel.gif' colspan=6><img src=img/blank.gif wuser_idth=1 height=1></td>";
			echo "</tr>";
		}
		echo "<tr valign=center>";
		echo "<td width=100 class=table><b>".$row['user_id']."</b></td>";
		echo "<td width=100 class=table><a href=\"view.php?id=".$row['user_id']."\">".$row['az_surname']."</a></td>";
		echo "<td width=100 class=table>".$row['az_firstname']." </td>";
		echo "<td width=100 class=table><i>".$row['username']."</i> </td>";
		
		echo "<td class=table></td>";
		echo "</tr>";
		$i++;

	}

	echo "<tr valign=bottom>";
        echo "<td bgcolor=#fb7922 colspan=6><img src=img/blank.gif wuser_idth=1 height=8></td>";
        echo "</tr>";

		
		
			
	 
?>

here is my code for view.php:

Code: Select all

<?php
			if(isset($_REQUEST['user_id']))
			{
			$user_id = $_REQUEST['user_id'];
			
			$conn = mysql_connect("localhost","root","") or die("Could Not Connect To The Database"); 
		mysql_select_db("aziz",$conn) or die("Could Not Select The Database"); 
			
			//sql query somethinglike
			$sql = "SELECT * FROM users_table WHERE user_id = '$id'"; 
			
			//your display stuff here.  }
			
		
			}
			?>
I've taken all the display stuff out for now, because ive tried everything and i get nothing but errors.

So I need to know is what is the best way to achieve what is wanted above which is the layout of

-[az_firstname][az_surname] at the top in Bold as a header,
- [user_id] a few spaces below in normal font and
- [password] 2 spaces below user_id in normal font

If anyone could show me some examples on how to get this information to appear, it'd be much appreciated!!


Any help would be much appreciated because been stuck on this for a very long time now so it would be greatly appreciated if someone could help me with this problem THANK YOU ALL FOR YOUR TIME :)
Post Reply