Jump to content

Roster Script


Boerboel649

Recommended Posts

Hi there everyone!

 

It's been a LONG time since I've been here... well not quite a year, but it seems like a while. :P  Anyways, it's also been a while since I've worked with PHP, and I need you guys' help.

 

What I want to do is this...  I have a MySQL table (at least I think I do...  I can't get into the clients control panel right now) named players with the following oh what do you call it (I told you it's been a while...)  fields? 

 

fname

lname

nickname

number

position

height

weight

other

 

I already have a form which posts info to a PHP script which puts it into the table.  Here's the code for the form...

 

<?
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$nickname = $_POST['nickname'];
$number = $_POST['number'];
$position = $_POST['position'];
$height = $_POST['height'];
$weight = $_POST['weight'];
$other = $_POST['other'];
   $query = "INSERT INTO players (fname, lname, nickname, number, position, height, weight, other)";
   $query .= "VALUES('$fname', '$lname', '$nickname', '$number', '$position', '$height', '$weight', '$other')";
   mysql_query($query, $dbh) or die("MySQL Error: <br /> {$query} <br /> ". mysql_error());
   echo $query; 

?>

 

As you may be able to tell, it's for a roster (a football roster to be exact), and what I'd like to have is a page which pulls up all the players first name (fname) and last name (lname) and lists them.  I want each players name to be a link, so that when the players name is clicked on, it will go to another page which brings up the players statistics. 

 

In the old days, I may have been able to come up with at least a start, but it's been so long since I've really worked with PHP... So if anyone is kind enough to maybe write a script for me for this, I'd be VERY happy.  Or at least give me a start on it.

Thanks so very much!

Link to comment
https://forums.phpfreaks.com/topic/43748-roster-script/
Share on other sites

What format is the link for the stats page? You would need to know that before you could do this.

 

You would want to run a query;

 

<?php
$query = mysql_query("SELECT fname, lname FROM players");
while ($result = mysql_fetch_array($query)) {
     echo '<a href="linktostats.htm">';
     echo $result['fname'];
     echo " ";
     echo $result['lname'];
     echo '</a><br>';
}
?>

 

That is very basic and not as neat or clean as some might do, but it should work none the less.

Link to comment
https://forums.phpfreaks.com/topic/43748-roster-script/#findComment-212452
Share on other sites

Thanks so much for your reply!!! 

 

However, I don't quite understand what you mean when you say "What format is the link for the stats page."

 

So it looks like this code will pull up the first and last names of the player, but how do I pass the fir and last name variables along to the next page so it can pull up the rest of the information?

 

Thanks so much!!!!!

Link to comment
https://forums.phpfreaks.com/topic/43748-roster-script/#findComment-212484
Share on other sites

Pass their fname in a URL.

 

<?php

$query = mysql_query("SELECT id, fname, lname FROM players");

while ($result = mysql_fetch_array($query)) {

 

    $fname = $result['fname'];

    $lname = $result['lname'];

 

    echo "<a href=\"info.php?fname=$fname&lname=$lname\">$fname $lname</a>";

 

}

?>

 

 

On the next page, info.php, use $_GET['fname'] to gather their fname and $_GET['lname'] for their lname... You can then use this in a query.

 

$query = mysql_query("SELECT * FROM players WHERE fname = '$fname' AND lname = '$lname'");

 

This query will gather all their details from that table.

 

 

It's best to pass over an ID rather then fname and lname though.

Link to comment
https://forums.phpfreaks.com/topic/43748-roster-script/#findComment-212495
Share on other sites

OK, thanks, good idea about using the ID instead. So would the code look something like this?...

 

Code for page which pulls up players names...

<?php

$query = mysql_query("SELECT id, fname, lname FROM players");
while ($result = mysql_fetch_array($query)) {
    $id= $result['id'];
    $fname = $result['fname'];
    $lname = $result['lname'];
    echo $fname;
    echo " ";
    echo $lname;
    echo '</a><br>';
    echo "<a href=\"info.php?id=$id\">$fname $lname[/url]";
}
?>

However, I know up there I'm having it list the first and last name twice and that one of them will be a link. My question is if I just keep this part

 

echo "<a href=\"info.php?fname=$fname&lname=$lname\">$fname $lname[/url]";

 

And delete this part

 

    echo $fname;
    echo " ";
    echo $lname;
    echo '</a><br>';

Will it still list on the players in the database (one name per line?)

 

And on the info.php page:

<?php
$query = mysql_query("SELECT * FROM players WHERE id = '$id'");

$_GET ['fname']
$_GET ['lname']
$_GET ['number']
?>

etc. etc. I know I don't have the echoes there, but I'll mess with that later, to achieve the order that I want.

 

Thank you guys so much for being patient with a rusty PHP person (not that I was all that good before, but I used to be a bit better. :P)

 

EDIT:  Not sure why it's putting all that extra stuff in the first section of code (all those 160's and stuff) anybody know why?

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/43748-roster-script/#findComment-213189
Share on other sites

OK, here's the code I'm experimenting with right now...

 

<?php require_once('Connections/steam.php');

 

 

 

$query = mysql_query("SELECT id, fname, lname FROM players");

while ($result = mysql_fetch_array($query)) {

 

  $fname = $result['fname'];

  $lname = $result['lname'];

 

 

  echo "<a href=\"info.php?fname=$fname&lname=$lname\">$fname $lname[/url]";

 

}

?>

The problem is.... I'm not getting anything showing up when I test it! I even tried adding in

 

echo $fname

 

to see if it would even give me that, and it isn't giving me anything! Could someone please help me with this? I know I have one player in the table.

 

Could someone please help me!?!?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/43748-roster-script/#findComment-213768
Share on other sites

All right, I have it showing the player name on a page that I have named "rostertest.php"

Here's the code:

 

<?php

$query = mysql_query("SELECT id, fname, lname FROM players");

while ($result = mysql_fetch_array($query)) {

$id = $result ['id'];

$fname = $result['fname'];

$lname = $result['lname'];

 

    echo $id; 

    echo '<a href="info.php?id=$id">';

    echo $fname;

    echo " ";

    echo $lname;

    echo '</a><br>';

}

?>

I have it echoing the id there just to make sure it's getting it.  Now the problem is the info.php page.  For some reason, when I click on the link in the address bar instead of showing the one section of the address as info.php?id=1  (the id for the player is 1) it keeps the $id there instead of the 1.  So it doesn't seem to be passing over the id variable to the link.  Anyone know why it's not doing this?

 

Here's the info.php code

 

<?php

$_GET['id'];

$query = mysql_query("SELECT * FROM players WHERE id = '$id'");

while ($result = mysql_fetch_array($query)) {

echo $fname;

echo $lname;

}

?>

Link to comment
https://forums.phpfreaks.com/topic/43748-roster-script/#findComment-213791
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.