little help with $row

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
xwhitchx
Forum Commoner
Posts: 38
Joined: Mon Jun 21, 2010 4:30 pm

little help with $row

Post by xwhitchx »

ok im using $row and while to display all the users on the page. and i want to make it so there is a link for each user that if you click it, it will have you go to a new page with only that users states and info is displays.



Here is the code i have for the users page.


Code: Select all

<?

$userlist = mysql_query("SELECT * FROM users");

echo '<table border="1" width=100%>

<tr>

<th width="50">Picture</th>

<th width="50">ID#</th>

<th>Username</th>

<th>LVL</th>

<th>Rank</th>

<th width="100"><center>Click to Fight.</center></th>

</tr>';

while($row = mysql_fetch_array($userlist))

  {

  echo "<tr>";

  echo '<td width="50"><center><img width="50" height="50" src="' . $row['pictures'] .'"/></center> </td>';

  echo '<td width="50"><center>' . $row['id'] . "</center></td>";

  echo "<td><center>" . $row['username'] . "</center></td>";

  echo "<td><center>" . $row['lvl'] . "</center></td>";

  echo "<td><center>" . $row['rank'] . "</center></td>";

  echo '<td width="100"><center><a href="index.php?page=fightpage">Fight <br/>'.$row['username'].'</a></center></td>';

 

 

  echo "</tr>";

  }

echo "</table>";

 

?>
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Re: little help with $row

Post by liljester »

soooo whats your question?

do the users display? is there an error? or are you just asking how to turn the user info into a link?
xwhitchx
Forum Commoner
Posts: 38
Joined: Mon Jun 21, 2010 4:30 pm

Re: little help with $row

Post by xwhitchx »

liljester wrote:soooo whats your question?

do the users display? is there an error? or are you just asking how to turn the user info into a link?
sorry if i was not clear, the users display fine, what im wanting to do is make it so the link for each user that is displayed goes to there stats and info.

so lets say there is a user named "12":
there is a link next to the username's called fight
if i click it it will take me to a page with all there stats on it and i can fight them (one click type of fighting)


so each link is going to need some sort of cookie of somthing so it will only get that users info for the next page.


that is what im wanting to do.

so its basicly like going to anuther users home page.

if you need me to go more in to detail let me know
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Re: little help with $row

Post by liljester »

ok. so basically you need to create a link to the stats page and use $_GET vars to pass the user to it. like so:

Code: Select all

print"<a href='www.site.com/stats.php?userid=". $row['userid'] ."'>click to see stats</a>";
then on your stats page use the $_GET['userid'] var passed to it to pull all the stats info from the database and display it.

hope that helps.
xwhitchx
Forum Commoner
Posts: 38
Joined: Mon Jun 21, 2010 4:30 pm

Re: little help with $row

Post by xwhitchx »

all right that seems to work for putting the user name in to the http so i can you the get var but i have one more problem, the whole site is set up bassed of the index page so it just reloads with new content in it every time you click a link, so my question is how do i use this code with my index page?


this is how i have all the links on the website, so is there a way to use it this way?

Code: Select all

index.php?page=userspage
this is your code after i put it with mine.

Code: Select all

  echo '<td><a href="stats.php?userid='. $row['username'] .'">Fight <br/>'.$row['username'].'</a></center></td>';
and if i use the index.php?page='.$row['username'] i just get an error saying that there is no such file called, username.php
Post Reply