Jump to content

Grumble...Unknown Problem


SelfObscurity

Recommended Posts

So I've been working on this site for a few days now, and it's coming along slow but well.  I'm trying to learn as much as possible about the coding I'm doing because it's a bit outside my skill range, so I'm taking my time.

 

I'm using a switch statement to dictate navigation, and netsted switches inside as well.  Everything was going great until I started continuing to add code to each case of the switch, then all of a sudden 2 of the cases show up blank, but nothing else is affected.  I spend an hr last night and this morning, looking and redoing, to get the same result.  Can someone take a look at this and advise please?

 

<?php

switch ($_GET['page']) {
     case 'news':
           switch ($_GET['id']) {
              case $_GET['id']:
                    $id = $_GET['id'];
                  $link = mysql_connect ($host, $user, $pass);
                    mysql_select_db ($db, $link);
                    $query = "SELECT * from news WHERE id = '$id'";
                      $result = mysql_db_query ($db, $query, $link);
                      while ($row = mysql_fetch_array($result)){
                    echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
                    <tr>
                      <td colspan=\"2\" class=\"Main-Header\"><a href=\"index.php?page=news&id=".$row['id'] . "\">".$row['title'] . "</a></td>
                    </tr>
                    <tr>
                         <td colspan=\"2\" class=\"Main-PostInfo\">Posted By: $row[author] on $row[date]</td>
                    </tr>
                    <tr>
                      <td colspan=\"2\" class=\"Side-Content\">$row[content]</td>
                    </tr>
                  </table><br />
                  "); }
                  break;
             default:
                  $link = mysql_connect ($host, $user, $pass);
                    mysql_select_db ($db, $link);
                    $query = "SELECT * from news'";
                      $result = mysql_db_query ($db, $query, $link);
                      while ($row = mysql_fetch_array($result)){
                    echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
                    <tr>
                      <td colspan=\"2\" class=\"Main-Header\"><a href=\"index.php?page=news&id=".$row['id'] . "\">".$row['title'] . "</a></td>
                    </tr>
                    <tr>
                         <td colspan=\"2\" class=\"Main-PostInfo\">Posted By: $row[author] on $row[date]</td>
                    </tr>
                    <tr>
                      <td colspan=\"2\" class=\"Side-Content\">$row[content]</td>
                    </tr>
                  </table><br />
                  "); }
                  break;
           }
           break;
     case 'about';
          $link = mysql_connect ($host, $user, $pass);
          mysql_select_db ($db, $link);
          $query = "SELECT * from aboutvow";
            $result = mysql_db_query ($db, $query, $link);
            while ($row = mysql_fetch_array($result)){
          echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
              <tr>
              <td class=\"Main-Header\">$row[title]</td>
                </tr>
                  <tr>
                      <td class=\"Side-Content\">$row[content]</td>
                    </tr>
                  </table><br />
                  "); }
                 break;
     case 'roster':
           switch ($_GET['id']) {
              case $_GET['id']:
                    $id = $_GET['id'];
                  $link = mysql_connect ($host, $user, $pass);
                    mysql_select_db ($db, $link);
                    $query = "SELECT * from roster WHERE id = '$id'";
                      $result = mysql_db_query ($db, $query, $link);
                      while ($row = mysql_fetch_array($result)){
                    echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td width=\"30\" colspan=\"2\" class=\"Main-Header\">-VoW- $row[gamename]</td>
  </tr>
  <tr>
    <td colspan=\"2\" class=\"Main-PostInfo\">SECTION 1: PERSONAL INFORMATION</td>
  </tr>
  <tr>
    <td class=\"Side-Content-Left\">Name</td>
    <td class=\"Side-Content-Right\">$row[firstname] $row[lastname]</td>
  </tr>
  <tr>
    <td class=\"Side-Content-Left\">Location</td>
    <td class=\"Side-Content-Right\">$row[location]</td>
  </tr>
  <tr>
    <td class=\"Side-Content-Left\">Age</td>
    <td class=\"Side-Content-Right\">");
    date_default_timezone_set('America/New_York');

    function calculateAge($dob){
   
    return floor((time() - strtotime($dob))/31556926);
   
    }
    $age = calculateAge("$row[dob]");
    echo ("$age</td>
  </tr>
  <tr>
    <td class=\"Side-Content-Left\">Connection</td>
    <td class=\"Side-Content-Right\">$row[connection]</td>
  </tr>
  <tr>
    <td colspan=\"2\" class=\"Main-PostInfo\">SECTION 2: CONTACT INFORMATION</td>
  </tr>
  <tr>
    <td class=\"Side-Content-Left\">Email</td>
    <td class=\"Side-Content-Right\">$row[email]</td>
  </tr>
  <tr>
    <td class=\"Side-Content-Left\">Steam</td>
    <td class=\"Side-Content-Right\">$row[steamfriends] ($row[steamemail])</td>
  </tr>
  <tr>
    <td class=\"Side-Content-Left\">Xfire</td>
    <td class=\"Side-Content-Right\">$row[xfire]</td>
  </tr>
  <tr>
    <td colspan=\"2\" class=\"Main-PostInfo\">SECTION 3: DAY OF DEFEAT INFORMATION</td>
  </tr>
  <tr>
    <td class=\"Side-Content-Left\">DoD Experience</td>
    <td class=\"Side-Content-Right\">");
    date_default_timezone_set('America/New_York');

    function calculateExp($exp){
   
    return floor((time() - strtotime($exp))/31556926 + ;
   
    }
    $exp = calculateExp("$row[dodexp]");
    echo ("$exp Years</td>
  </tr>
  <tr>
    <td class=\"Side-Content-Left\">Class</td>
    <td class=\"Side-Content-Right\">$row[class]</td>
  </tr>
  <tr>
    <td class=\"Side-Content-Left\">SteamID</td>
    <td class=\"Side-Content-Right\">$row[steamid]</td>
  </tr>
  <tr>
    <td colspan=\"2\" class=\"Main-PostInfo\">SECTION 4: MATCH INFORMATION</td>
  </tr>
  <tr>
    <td colspan=\"2\" class=\"Main-Content\">-VoW- $row[gamename] has no match history</td>
  </tr>
</table><br />
                  "); }
                 break;
              default:
                      $link = mysql_connect ($host, $user, $pass);
                        mysql_select_db ($db, $link);
                        $query = "SELECT * from roster";
                          $result = mysql_db_query ($db, $query, $link);
                          while ($row = mysql_fetch_array($result)){
                     echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td colspan=\"5\" class=\"Main-Header\">Roster</td>
  </tr>
  <tr>
    <td width=\"101\" class=\"Main-Roster-Left\">Name</td>
    <td width=\"124\" class=\"Main-Roster\">Status</td>
    <td width=\"241\" class=\"Main-Roster\">SteamID</td>
    <td width=\"175\" class=\"Main-Roster\">Class</td>
    <td width=\"452\" class=\"Main-Roster\">Recruitment Date</td>
  </tr>
  <tr>
    <td class=\"Main-Roster-Content-Left\"><a href=\"index.php?page=roster&id=".$row['id'] . "\">".$row['gamename'] . "</a></td>
    <td class=\"Main-Content-Roster\">$row[status]</td>
    <td class=\"Main-Content-Roster\">$row[steamid]</td>
    <td class=\"Main-Content-Roster\">$row[class]</td>
    <td class=\"Main-Content-Roster\">$row[admin_recdate]</td>
  </tr>
</table>"); }
                  break;
           }
           break;
     case 'servers':
           switch ($_GET['id']) {
              case 1:
                  echo "ID is 1";
                  break;
              case 2:
                  echo 'ID is 2';
                  break;
              default:
                  echo 'No ID - display main servers';
                  break;
           }
           break;
     case 'forum';
          echo ("FORUM HERE"); 
          break;
     default:
           $link = mysql_connect ($host, $user, $pass);
          mysql_select_db ($db, $link);
          $query = "SELECT * from news ORDER BY date DESC LIMIT 5";
            $result = mysql_db_query ($db, $query, $link);
            while ($row = mysql_fetch_array($result)){
          echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td colspan=\"2\" class=\"Main-Header\"><a href=\"index.php?page=news&id=".$row['id'] . "\">".$row['title'] . "</a></td>
  </tr>
  <tr>
    <td colspan=\"2\" class=\"Main-PostInfo\">Posted By: $row[author] on $row[date]</td>
  </tr>
  <tr>
    <td colspan=\"2\" class=\"Side-Content\">$row[content]</td>
  </tr>
</table><br />
"); }
     break;
     case 'recruitment':
           switch ($_GET['action']) {
              case 'apply':
                  echo "APPLICATION HERE";
                  break;
              case 'submit':
                  echo 'SUBMIT APPLICATION';
                  break;
              case 'status':
                  echo 'APPLICATION STATUS';
                  break;
              default:
                  echo 'No ACTION - display main recruitment';
                  break;
           }
           break;
}

?>

 

The problem I am having is getting the default news case and default roster case to print.  Everything else shows up properly.  Sorry for the messy code, I"m working on it!

Link to comment
Share on other sites

To clarify KP's post, that is effectively the same as

 

if ($x == $x) { ... }

 

So it will always be true and will always be the case that gets executed. 

 

It looks like you are wanting to create a query if id exists, if not, make it a generic query. Try something like

 

case (isset($_GET['id'])||($_GET['id']!=null)||($_GET['id']!='')): 

 

You can probably remove one or more of those conditions depending on how you have your links setup...

 

p.s.- on a sidenote, you should sanitize all input being used in a query.  At the absolute minimum you should do something like

 

(assuming id is a number):

$id = (int) $_GET['id'];

 

 

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.