Select data help...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • syoung69
    New Member
    • Sep 2011
    • 19

    #1

    Select data help...

    Im fairly new to programming and am all self taught but i have managed to get the basics. My biggest problem is the select data line.

    Below i am trying to pull stats from a db showing only the stats requested from the team id. There is another database where the team id is pulled from ( season11 )

    Any help? Here is what i have....

    Code:
    <?php
    // Connects to your Database 
    $teamid = $_GET["id"]; 
    if (!is_numeric($teamid)){die();} 
    
    
    $sql = "SELECT Team, Num, Name, Pos, Salary, Contract, 11/12 Salary, 12/13 Salary, 13/14 Salary, Protected, Rookie  FROM playerslist11 WHERE Team = " . $teamid . " "; 
    
     
    $data = mysql_query($sql)
    or die(mysql_error());
    
    Print "<table width = 775>";
    Print "<th width=20 align = left bgcolor=#ebf0f6>TEAM</th>";
    Print "<th bgcolor=#ebf0f6>#</th>";
    Print "<th bgcolor=#ebf0f6>NAME</th>";
    Print "<th bgcolor=#ebf0f6>POS</th>";
    Print "<th bgcolor=#ebf0f6>SALARY</th>";
    Print "<th bgcolor=#ebf0f6>CONTRACT</th>";
    Print "<th bgcolor=#ebf0f6>STATUS</th>";
    Print "<th bgcolor=#ebf0f6>11/12 SALARY </th>";
    Print "<th bgcolor=#ebf0f6>12/13 SALARY</th>";
    Print "<th bgcolor=#ebf0f6>13/14 SALARY</th>";
    Print "<th bgcolor=#ebf0f6>PROTECTED</th>";
    Print "<th bgcolor=#ebf0f6>ROOKIE</th>";
    
    
    
    
    Print "<tr>"; 
    Print "<td align = left width=80>".$info['Team'] . "</td> ";
    Print "<td align = center>".$info['Num'] . "</td> ";     
    Print "<td align = center>".$info['Name'] . "</td> ";
    Print "<td align = center>".$info['Pos'] . "</td> ";
    Print "<td align = center>".$info['Salary'] . "</td> ";
    Print "<td align = center>".$info['Contract'] . "</td> ";
    Print "<td align = center>".$info['11/12_Salary'] . "</td> ";
    Print "<td align = center>".$info['12/13_Salary'] . "</td> ";
    Print "<td align = center>".$info['13/14_Salary'] . "</td> ";
    Print "<td align = center>".$info['Protected'] . "</td> ";
    Print "<td align = center>".$info['Rookie'] . "</td> ";
    
    
    }
    
    
    Print "</table>"; 
    ?> 
    
    <?php
    include 'closedb.php';
    ?>
    Last edited by Niheel; Sep 10 '11, 10:53 PM. Reason: use code tags please
  • syoung69
    New Member
    • Sep 2011
    • 19

    #2
    UPDATED...

    Ive gotten abit farther. Got all info but getting all players in the system...


    Code:
    </php
    include 'connect.php';
    ?>
    <?php
    // Connects to your Database
    $teamid = $_REQUEST["id"];
    
    $data = mysql_query("SELECT * FROM teams WHERE newsid=$teamid; ")
    or die(mysql_error());
    Print "<table valign=left  >";
    
    
    
    
    Print "<tr>";
    
    while($info = mysql_fetch_array( $data ))
    
    
    $data2 = mysql_query("SELECT * FROM playerslist11; ")
    or die(mysql_error());
    
             Print "<td>";
    ?>
    
            <table width =780" border ="0">
            <tr>
    
    		<th align=middle width=30 bgcolor=#ffffff>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><u>PLAYER</u></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
            <th align=middle bgcolor=#ffffff><b><u>TEAM</u></b></th>
    		
    		<th align=middle width=30 bgcolor=#ffffff><b><u>#</u></b></th>
    		<th align=middle width=15 bgcolor=#ffffff><b><u>POS</u></b></th>
            <th align=middle width=30 bgcolor=#ffffff>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><u>SALARY</u></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
            <th align=middle width=30 bgcolor=#ffffff><b><u>CONTRACT</u></b></th>  
    		<th align=middle width=30 bgcolor=#ffffff>&nbsp;&nbsp;&nbsp;&nbsp;<b><u>STATUS</u></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
    		<th align=middle bgcolor=#ffffff>&nbsp;&nbsp;<b><u>09/10 SALARY</u></b>&nbsp;&nbsp;&nbsp;</th>
    		<th align=middle bgcolor=#ffffff>&nbsp;&nbsp;<b><u>09/10 SALARY</u></b>&nbsp;&nbsp;&nbsp;</th>
    		<th align=middle bgcolor=#ffffff><b><u>PROTECTED</u></b></th>
    		<th align=middle bgcolor=#ffffff><b><u>ROOKIE</u></b></th>
    		
    		
    		</tr>
            <tr>
    <?php
    while($info2 = mysql_fetch_array( $data2 ))
    {
    $playername1 = $playername['Name'];
    
    
    
    ?>
            
            <td><center><?php print $playername ?></center></td>
    		<td><center><?php print $info2['Team']?></center></td>
    		<td><center><?php print $info2['Num'] ?></center></td>
    		<td><center><?php print $info2['Pos'] ?></center></td>
            <td><center><?php print $info2['Salary'] ?></center></td>
            <td><center><?php print $info2['Contract'] ?></center></td>
    		<td><center><?php print $info2['Status'] ?></center></td>
    		<td><center><?php print $info2['09/10 Salary'] ?></center></td>
    		<td><center><?php print $info2['10/11 Salary'] ?></center></td>
    		<td><center><?php print $info2['Protected'] ?></center></td>
            <td><center><?php print $info2['Rookie'] ?></center></td>
    
    
            </tr>
    
    
    
    <?php
    
    }
    
    ?>
       </table>
    <?php
    
            Print "</td>";
    
    Print "</table>";
    ?>
    
    <?php
    include 'closedb.php';
    ?>
    Last edited by Niheel; Sep 10 '11, 10:53 PM. Reason: use code tags please

    Comment

    • deric
      New Member
      • Dec 2007
      • 92

      #3
      I think your first post is already okay, only for these 2 reasons:

      1. The field names you indicated in the query is wrong

      Code:
      $sql = "SELECT Team, Num, Name, Pos, Salary, Contract, [B]11/12 Salary, 12/13 Salary, 13/14 Salary[/B], Protected, Rookie  FROM playerslist11 WHERE Team = " . $teamid . " ";
      From this code
      Code:
      Print "<td align = center>".$info['11/12_Salary'] . "</td> ";
      Print "<td align = center>".$info['12/13_Salary'] . "</td> ";
      Print "<td align = center>".$info['13/14_Salary'] . "</td> ";
      it says that the concerned field names have underscores but in your query they have not.

      2. You did not loop through the result of the query.

      And hey, you might want to consider following some conventions on naming database table fields... just my 2 cents. ;)

      Comment

      Working...