Simple php link code

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

User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

redhair wrote:Your link that calls user nr one should(..or could) look like http://you.com/user.php?user_id=1
I3lade
Forum Commoner
Posts: 70
Joined: Wed Jun 04, 2003 4:20 pm

Post by I3lade »

Ok,but how do i make it so it finds the user id automactily? Like so they click bob user id 1 and then click joe with user id 2
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

You should retreive the id's and names from the database first, with that create a list, like this example.

Code: Select all

<?php

$query = "SELECT id,login FROM user_table ORDER BY id DESC";

$result = MYSQL_QUERY($query);

while ($row = mysql_fetch_array($result)) {
	$id = $row['id'];
	$login = $row['login'];

	$users .= "<a href='user.php?user_id=" . $id . "'>" . $login . "</a><br>\n";
	}

print $users;

?>
I3lade
Forum Commoner
Posts: 70
Joined: Wed Jun 04, 2003 4:20 pm

Post by I3lade »

I cant find my variable !

<?
mysql_connect("localhost","bladegames", "***");
mysql_select_db("bladegames");
echo "<table>
<tr><td>Number</td><td>Username</td><td>Email</td></tr>
";
$query = mysql_query("SELECT * FROM members ORDER BY id");
while($row=mysql_fetch_array($query))

{
echo "<tr><td>$row[id]</td><td>$row
<a href=\"lookup.php?memberid=<?=$row[login]->id?\"> $row[login] </a></td><td>
$row[email] </td></tr>";
}
}else{
printf("Your not logged in, plz login again");
};
?>

I think its in the link not sure.. The link is:
Code:
a href=\"lookup.php?memberid=<?=$row[login]->id?\"> $row[login] </a
I3lade
Forum Commoner
Posts: 70
Joined: Wed Jun 04, 2003 4:20 pm

Post by I3lade »

Anyone please?
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

Did you ever bothered to read what people wrote to you :?: Because I think you did not.

I've told you that there is an mistake here:

Code: Select all

<a href="lookup.php?memberid=<?=$row[login]->id?"> $row[login] </a>
it should be something like this:

Code: Select all

<a href="lookup.php?memberid=".$row[id]."">".$row[login]."</a>
if you want to find the user by its id.

But of course user redhair already wrote something similar and equaly good...
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

trying

Post by phpScott »

from RedHair
<?php

$query = "SELECT id,login FROM user_table ORDER BY id DESC";

$result = MYSQL_QUERY($query);

while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$login = $row['login'];

$users .= "<a href='user.php?user_id=" . $id . "'>" . $login . "</a><br>\n";
}

print $users;

?>
will create a list of links like
bob login
joe login
bill login
which in html code look like

Code: Select all

&lt;a href='user.php?user_id=bob'&gt;bob login&lt;/a&gt;&lt;br&gt;
&lt;a href='user.php?user_id=joe'&gt;joe login&lt;/a&gt;&lt;br&gt;
&lt;a href='user.php?user_id=bill'&gt;bill login&lt;/a&gt;&lt;br&gt;
So now because you have dynamically created the links each individual link will now pass along the value of each individual user_id as a parameter to the next page.

say the page is called user.php same name as in the link you would do something like

Code: Select all

<?php
$user_id=$GET['user_id'];
print "welcome $user_id to this page";

?>
which would print out
welcom bob to this page
assuming that you orginaly clicked on the link that said bob login

is that any help of what is going on.

phpScott

Please read twigletmac link on posting questions and asking for help.
It is good reading and will allow us to help you better.


ps. thanks twig for lock some of the other posts as it seemed to be getting a little out of hand.
I3lade
Forum Commoner
Posts: 70
Joined: Wed Jun 04, 2003 4:20 pm

Post by I3lade »

It still dosnt work.. its my page, lookup.php thats the problem...
lookup.php:

Code: Select all

<?php
session_start(); 
if($logged==1)&#123; 
?> 

<? 
mysql_connect("localhost","bladegames", "***"); 
mysql_select_db("bladegames");
$query = mysql_query("SELECT * FROM members where id='$id'");
&#123;
echo "
<center> $row&#1111;login] 's Look Up </center
<font color="black" size=2>Hobbies: $row&#1111;phob] <br>
<font color="black" size=2>Other Information: $row&#1111;profile] <br>";
&#125;
&#125;else&#123; 
printf("Your not logged in, please login again, or register today!");  
&#125;;
?>
Otherwise thanks for the help with the link, now that thats working i got to make this work otherwise it dsiplays Hobbies: Profile:
with nothing there.. Oh and thanks for locking those other threads i tried to delte them but i guess i cant...
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

It's getting amusing now..
Wait..let me try this..
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

I3lade ARE YOU READING ANY OF THIS?
I3lade
Forum Commoner
Posts: 70
Joined: Wed Jun 04, 2003 4:20 pm

Post by I3lade »

Im going to use one of your eiarly posts:

Supposed you have these fields in your table
user_id, fname, lname

To get a certain user from the db, you could try:

user.php
PHP:

Code: Select all

<?php 
if (isset($_get&#1111;'user_id'])) 


&#123;$mysqlquery = "SELECT * FROM user_table WHERE user_id = "$user_id""; 

      $result = MYSQL_QUERY($query); 

      while ($row = mysql_fetch_array($result)) &#123; 

      $fname = $row&#1111;'fname']; 
      $lname = $row&#1111;'lname']; 
&#125; 
print "$user_id: fname $lname"; 

?>



Your link that calls user nr one should look like http://you.com/user.php?user_id=1
Yea i just went back and read all of it i missed im really sorry evryone, im just trying to get some help ok redhiar im going to try to use on of the eairlyier posts u posted to help The post im talking about is:
[/quote]
I3lade
Forum Commoner
Posts: 70
Joined: Wed Jun 04, 2003 4:20 pm

Post by I3lade »

Hopfuily it will help my code to work thanks and sorry again
I3lade
Forum Commoner
Posts: 70
Joined: Wed Jun 04, 2003 4:20 pm

Post by I3lade »

Hrm i cant get it to work could you please give me another chance and try to help me fix my lookup.php? I fixed the link thanks to you guys... please just give me one more chance..
I3lade
Forum Commoner
Posts: 70
Joined: Wed Jun 04, 2003 4:20 pm

Post by I3lade »

Well if you don't want to help ill understand but im sorry and i really need help, im a newb to php..
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

<?php
session_start();
if($logged==1){
?>

<?
mysql_connect("localhost","bladegames", "***");
mysql_select_db("bladegames");
$query = mysql_query("SELECT * FROM members where id='$id'");
{
echo "
<center> $row[login] 's Look Up </center
<font color=\"black\" size=2>Hobbies: $row[phob] <br>
<font color=\"black\" size=2>Other Information: $row[profile] <br>";
}
}else{
printf("Your not logged in, please login again, or register today!");
};
?>
first thing you are missing a > after your closing center tag.
second try this

Code: Select all

$sql="SELECT * FROM members where id='$id'";
$query = mysql_query($sql);
echo "sql is $sql<br />";
to see your sql query and run that agianst the db directly to see if there is a problem with your query.

you have a $query then you jump right into $row[phob]
There needs to be some sort of transition between the two
read http://www.mysql.com/doc/en/mysql_query.html
to understand mysql_query()

You now need to fecht the data
as in

Code: Select all

$phob=mysql_result($query, 0, 'phob');
read
http://ca2.php.net/manual/en/function.mysql-result.php

phpScott

get to know http://www.mysql.com and http://www.php.net as they are wonderful resources for research and learning

phpScott
Post Reply