Jump to content

Displaying Information from a Database Problems


jedney

Recommended Posts

Hello.

 

I am trying to display information from a database, based upon what is called from the tablle.  I have a page called "roster.php", and this is supposed to show a table, with a list of the team roster basically.  Then, I have the player names linked to their various id's in the table (for example, one name is linked to roster.php?id=". $row['id] ."

 

The problem i am having is getting the main roster.php to show when the page is gone to, and the individual detailed pages to show when a name is clicked.  Here is the code, any guidence would be great.

 

<?php if ($_GET['id'] == "". $row['id'] ."")
  {
  $query = "SELECT * FROM roster WHERE id = '{$_GET['id']}'"; 
    $result = mysql_query($query) or die(mysql_error()); 
    while ($row = mysql_fetch_array($result)) {
        echo" <tr>
    
        <td valign=\"top\" class=\"NewsHeader\">     <echo ". $row['name'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">Clan Rank: ". $row['rank'] ."</td>
        </tr>
      <tr>
        <td class=\"norm\">Allied Perfered Class: ". $row['allies'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">Axis Perfered Class: ". $row['axis'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">Favorite Map: ". $row['favmap'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">Recruitment Date: ". $row['joindate'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">SteamID: ". $row['steamid'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\"> </td>
      </tr>
      <tr>
        <td class=\"norm\">Email Address: ". $row['email'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\"><p>AIM: ". $row['aim'] ."</p>          </td>
      </tr>
      <tr>
        <td class=\"norm\">Yahoo: ". $row['yahoo'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">MSN: ". $row['msn'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">Steam: ". $row['steam'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\"> </td>
      </tr>
      <tr>
        <td class=\"norm\">Scrim Stats</td>
      </tr>
      <tr>
        <td class=\"norm\">No stats to report</td>
      </tr>
      <tr>
        <td class=\"norm\"> </td>
      </tr>
      <tr>
        <td class=\"norm\">Match Stats</td>
      </tr>
      <tr>
        <td class=\"norm\">No Stats to report</td>
      </tr><? } 
  } else {
  
  <tr>;
    
        <td colspan=\"6\" valign=\"top\" class=\"NewsHeader\">Squad Roster</td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td class=\"normbold\">Name</td>";
        echo "<td class=\"normbold\">Rank</td>";
        echo "<td class=\"normbold\">SteamID</td>";
        echo "<td class=\"normbold\">Allies</td>";
        echo "<td class=\"normbold\">Axis</td>";
        echo "<td class=\"normbold\">Recruitment Date</td>";
      echo "</tr>";
      // DISPLAY NEWS INFORMATION 
    $query = "SELECT * FROM roster"; 
    $result = mysql_query($query) or die(mysql_error()); 
    while ($row = mysql_fetch_array($result)) {
        echo "<tr><td class=\"norm\"><a href=\"roster.php?id=". $row["id"] ."\">". $row["name"] ."</a></td>";
	echo "<td class=\"norm\">". $row['rank'] ."</td>";
        echo "<td class=\"norm\">". $row['steamid'] ."</td>";
        echo "<td class=\"norm\">". $row['allies'] ."</td>";
        echo "<td class=\"norm\">". $row['axis'] ."</td>";
        echo "<td class=\"norm\">". $row['joindate'] ."</td>";
      echo "</tr>"; } 
  }
  }
  ?>

 

The above code is only the middle cell of the page, here is the full-page source:

<?php include('connect.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 1 September 2005), see www.w3.org" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Next Level Gaming :: A Professional Day of Defeat Gaming Team</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" class="MainTable">
  <tr>
    <td colspan="2"><img src="images/header.gif" alt="Next Level Gaming" width="800" height="100" longdesc="Next Level Gaming - A Professional Day of Defeat Team" /></td>
  </tr>
  <tr>
    <td colspan="2"> </td>
  </tr>
  <tr>
    <td class="MainLeftCol"><table width="175" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="images/navhdr.gif" alt="Navigation" width="200" height="15" /></td>
      </tr>
      <tr>
        <td><div class="norm"><?php 
             // SET UP DATABASE CONNECTION 
    $link = mysql_connect('host', 'user, 'pass') 
       or die('Could not connect: ' . mysql_error()); 
    mysql_select_db('db') or die('Could not select database'); 

    // DISPLAY NAVIGATION INFORMATION 
    $query = "SELECT * FROM navigation WHERE type='1'"; 
    $result = mysql_query($query); 
    while ($row = mysql_fetch_array($result)){ 
    $link = $row["link"] ;
    $url = $row["url"] ;
    echo "<div class=\"norm\"><a href=". $row["url"] .">". $row["link"] ."</a><br /></div>"; 
    } 
    ?></div></td>
      </tr>
      <tr>
        <td> </td>
      </tr>
      <tr>
        <td><img src="images/dodhdr.gif" alt="Day of Defeat Resources" width="200" height="15" /></td>
      </tr>
      <tr>
        <td><span class="norm">
          <?php 
             // SET UP DATABASE CONNECTION 
    $link = mysql_connect('host', 'user, 'pass') 
       or die('Could not connect: ' . mysql_error()); 
    mysql_select_db('db') or die('Could not select database');  

    // DISPLAY NAVIGATION INFORMATION 
    $query = "SELECT * FROM navigation WHERE type='2'"; 
    $result = mysql_query($query); 
    while ($row = mysql_fetch_array($result)){ 
    $link = $row["link"] ;
    $url = $row["url"] ;
    echo "<a href=\"". $row["url"] ."\">". $row["link"] ."</a><br />"; 
    } 
    ?>
        </span></td>
      </tr>
      <tr>
        <td> </td>
      </tr>
      <tr>
        <td><img src="images/serverhdr.gif" alt="Day of Defeat 1.3 Server" width="200" height="15" /></td>
      </tr>
      <tr>
        <td><a href="http://www.gametracker.com/server_info/8.12.19.10:27015/">
<img class="noborderimg" src="http://cache.www.gametracker.com/server_info/8.12.19.10:27015/b_160x400_T0_F-1-2-3_CFFFFFF-C5C5C5-FFFFFF-434736.png" alt="" />
</a></td>
      </tr>
    </table></td>
    <td valign="top" class="MainCol"><table width="600" border="0" cellspacing="0" cellpadding="0">
      <tr>
    
        <?php if ($_GET['id'] == "". $row['id'] ."")
  {
  $query = "SELECT * FROM roster WHERE id = '{$_GET['id']}'"; 
    $result = mysql_query($query) or die(mysql_error()); 
    while ($row = mysql_fetch_array($result)) {
        echo" <tr>
    
        <td valign=\"top\" class=\"NewsHeader\">     <echo ". $row['name'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">Clan Rank: ". $row['rank'] ."</td>
        </tr>
      <tr>
        <td class=\"norm\">Allied Perfered Class: ". $row['allies'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">Axis Perfered Class: ". $row['axis'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">Favorite Map: ". $row['favmap'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">Recruitment Date: ". $row['joindate'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">SteamID: ". $row['steamid'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\"> </td>
      </tr>
      <tr>
        <td class=\"norm\">Email Address: ". $row['email'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\"><p>AIM: ". $row['aim'] ."</p>          </td>
      </tr>
      <tr>
        <td class=\"norm\">Yahoo: ". $row['yahoo'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">MSN: ". $row['msn'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\">Steam: ". $row['steam'] ."</td>
      </tr>
      <tr>
        <td class=\"norm\"> </td>
      </tr>
      <tr>
        <td class=\"norm\">Scrim Stats</td>
      </tr>
      <tr>
        <td class=\"norm\">No stats to report</td>
      </tr>
      <tr>
        <td class=\"norm\"> </td>
      </tr>
      <tr>
        <td class=\"norm\">Match Stats</td>
      </tr>
      <tr>
        <td class=\"norm\">No Stats to report</td>
      </tr><? } 
  } else {
  
  <tr>;
    
        <td colspan=\"6\" valign=\"top\" class=\"NewsHeader\">Squad Roster</td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td class=\"normbold\">Name</td>";
        echo "<td class=\"normbold\">Rank</td>";
        echo "<td class=\"normbold\">SteamID</td>";
        echo "<td class=\"normbold\">Allies</td>";
        echo "<td class=\"normbold\">Axis</td>";
        echo "<td class=\"normbold\">Recruitment Date</td>";
      echo "</tr>";
      // DISPLAY NEWS INFORMATION 
    $query = "SELECT * FROM roster"; 
    $result = mysql_query($query) or die(mysql_error()); 
    while ($row = mysql_fetch_array($result)) {
        echo "<tr><td class=\"norm\"><a href=\"roster.php?id=". $row["id"] ."\">". $row["name"] ."</a></td>";
	echo "<td class=\"norm\">". $row['rank'] ."</td>";
        echo "<td class=\"norm\">". $row['steamid'] ."</td>";
        echo "<td class=\"norm\">". $row['allies'] ."</td>";
        echo "<td class=\"norm\">". $row['axis'] ."</td>";
        echo "<td class=\"norm\">". $row['joindate'] ."</td>";
      echo "</tr>"; } 
  }
  }
  ?>
      
    </table></td>
  </tr>
  <tr>
    <td colspan="2" class="MainLeftCol"><div class="copyright">Web Design & Development by Lev | © 2008, Next Level Gaming<br />
      <br />
        <img src="images/xhtml10.gif" alt="Validated as XHTML 1.0 Strict" width="50" height="18" /><img src="images/vcss.gif" alt="Validated as Valid CSS" width="50" height="18" /><br />
    </div></td>
  </tr>
</table>
</body>
</html>

Link to comment
Share on other sites

Change this

 

if ($_GET['id'] == "". $row['id'] ."")

 

to this

 

if (isset($_GET['id']))

 

This checks if the id param has been passed (which it will have once you click the link) and executes the show detail code instead of th e squad list code

 

HTH

Dave

 

Link to comment
Share on other sites

Dave,

 

Thank you kindly sir.  Half my problem is gone.  I thought isset only worked if you was calling two variables (example: roster.php?squad=1&id=2).

 

roster.php displays nothing, and when I go to the link id=1, it displays the detailed information as well as the main roster information.  You can view the page here; I'm lost.

 

http://www.nlgaming.net/nlgb1/roster.php

 

Link to comment
Share on other sites

The problem is here i think

 

      <td class=\"norm\">No Stats to report</td>
      </tr><? } 
  } else {
  
  <tr>;
    
        <td colspan=\"6\" valign=\"top\" class=\"NewsHeader\">Squad Roster</td>";

 

You are using <? short tags - can you do that??  I would change to a <?php for future portability even if your sever can.

 

Once you change that you will probably find that you need to echo the <tr> and the <td> statements also!

 

Hope it works

 

Cheers

Dave

 

l

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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