Web Analytics Made Easy -
StatCounter Problem with "select" and displaying info... - CodingForum

Announcement

Collapse
No announcement yet.

Problem with "select" and displaying info...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with "select" and displaying info...

    I have this code that gives me a selection box of a list of players from a certain team. The team is selected from a pull down box on an earlier page.

    The problem is that it cannot find the number of a player. Everyway I try to do it it cannot find it. However if I move "number AS number" to the beginning just after the "select" call it find the number and stores it as the firstname.

    What is wrong here?
    PHP Code:
      <form name="findplayer" method="post" action="teams.php?ax=editteam">
       
      <div align="center"> 
        <?php
    $query 
    mysql_query("select firstname AS firstname, lastname AS lastname, number AS number from hockeystats_players WHERE team='$team' ORDER BY lastname");
    echo 
    "<select name=playersname>";
    if (!isset(
    $firstname)) { echo "<option value=null selected>Choose a Player</option>n";}
    while(list(
    $firstname,$lastname) = mysql_fetch_row($query))
    {
    echo 
    "<option value=$number";
    if (
    $firstname == $firstname) { echo ""; }
    echo 
    ">$lastname$firstname</option>";
    }
    echo 
    "</select>";?>
        <br>
        <input type="submit" name="Submit" value="Submit">
      </div>


    </form>
    My tables are set up as:

    number team firstname lastname gp goals
    --------- --------- ------------- ------------ --- -------
    16 thunder dawson irvine 50 32

    there are more fields but I don't need those selected yet. Just the name and number so I can select the players without confusion, incase there are two with the same name.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #2
    First off
    PHP Code:
    $query mysql_query("select firstname AS firstname, lastname AS lastname, number AS number from hockeystats_players WHERE team='$team' ORDER BY lastname"); 
    That's wrong, it should be
    PHP Code:
    $query mysql_query("SELECT firstname, lastname, number FROM hockeystats_players WHERE team='$team' ORDER BY lastname ASC"); 
    Just added the caps also, to make things clearer

    PHP Code:
    if (!isset($firstname)) { echo "<option value=null selected>Choose a Player</option>n";} 
    That bit will always echo the option, so why take it off the if statement. So just have
    PHP Code:
    echo "<option value=null selected>Choose a Player</option>\n"
    Now this bit
    PHP Code:
    while(list($firstname,$lastname) = mysql_fetch_row($query))
    {
    echo 
    "<option value=$number";
    if (
    $firstname == $firstname) { echo ""; }
    echo 
    ">$lastname$firstname</option>";

    Just simply change it to
    PHP Code:
    while($row mysql_fetch_array($query))
    {
    echo 
    "<option value='" .$row['number']. "'>"$row['lastname']. ", " .$row['firstname']. "</option>";

    I really don't see what this
    PHP Code:
    if ($firstname == $firstname) { echo ""; } 
    is meant to do?
    Last edited by Nightfire; Feb 20, 2004, 12:20 PM.

    Comment


    • #3
      PHP Code:
      $query mysql_query("SELECT number, firstname, lastname FROM hockeystats_players WHERE team='".$team."' ORDER BY lastname ASC"); 
      This may not fix the problem, but it does cut out some unrequired code. You do not have to use AS if you want the data selected as its original name.

      Also, with ORDER BY, you should use ASC or DESC (ascending or descening)
      PHP Weekly - A PHP Developers Resource
      PHP 5.1.4 and Ruby on Rails web hosting
      Moderator of PHP and Work offers and Requests
      Install Apache/PHP/MySQL
      (by marek_mar) | TinyPlugin Architecture

      Comment


      • #4
        Thanks nightfire
        Dawson Irvine
        CEO - DNI Web Design
        http://www.dniwebdesign.com

        Comment

        Working...
        X