Jump to content

SelfObscurity

Members
  • Posts

    41
  • Joined

  • Last visited

About SelfObscurity

  • Birthday 12/14/1982

Profile Information

  • Gender
    Male
  • Location
    Detroit, MI

SelfObscurity's Achievements

Member

Member (2/5)

0

Reputation

  1. I'm unsure what changing what I use as a value for ID will do. When I go to my index.php, I'm displaying all news posts with no problem. I copied the exact PHP/SQL coding for the default news case, so it should be working. I believe I am going to change to if statements, see what I can accomplish.
  2. Colton, That's what I'm going for. The first half of the if statement, is to call information based on if id equals whatever the id field is. The second half of the if statement, calls everything. It's the second half that won't display anything, not even my table, just blank space. I've been literally working at it for 3 days!
  3. ngreenwood6, Thank you for your response. I've re-written the code you posted, and still, it will not show the default news information, but if I put &id=1 after the URL, it shows up. This isn't making sense to me!
  4. Well, the case that calls for the ID in the news section, is the part that actually works. It's the default case that isn't showing any information. The reason I'm using switches instead of an if statement is because I was told it was easier. I'm doubting this.
  5. I'm using a switch with multiple nested switches. I tested the switch and nested switches by setting up the structure, and using basic text for the cases. For example, instead of one of the nested switch cases needing to = $_GET['id'], I just entered two cases, each equaling 1 and 2, then the default case. Once I begin to enter my SQL coding to connect to the databases, only certain information prints. For example; on my switch that is $_GET['page'], I have a case for 'news'. Inside this case, I have a nested switch called $_GET['id'], which will display information if the page=nes&id=whatever. That works, but when I go do the page=news, nothing displays. My coding is omitting displaying the default information if there is no $_GET['id']. Attached, I am going to have my .php file. The reason for not posting it here is because my coding is rather messy. Please help! [attachment deleted by admin]
  6. 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!
  7. I've made attempts to implement this nested switch, but it's not working. The code works until I add this nested switch. Am I overlooking something? <?php switch ($_GET['page']) { // NEWS CASE case 'news'; $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=\"Main-Content\">$row[author]</td> </tr> <tr> <td> </td> <td class=\"Main-Comment\">Comment | (0) Comments</td> </tr> </table><br /> \n"); switch ($_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)) { $id = $_GET['id']; case '$id'; echo ("NEWS POST $row['id']"); 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=\"Main-Content\">$row[author]</td> </tr> <tr> <td> </td> <td class=\"Main-Comment\">Comment | (0) Comments</td> </tr> </table><br /> \n"); } 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=\"Main-Content\">$row[content]</td> </tr> </table><br /> \n"); } 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=\"Main-Content\">$row[author]</td> </tr> <tr> <td> </td> <td class=\"Main-Comment\"><a href=\"index.php?page=news&id=".$row['id'] . "&action=comment\">Comment</a> | <a href=\"index.php?page=news&id=".$row['id'] . "\"> View Comments</a></td> </tr> </table><br /> \n"); } break; } ?>
  8. Morning, I'm working on a web site using a switch to separate different calls from a MySQL database. My style looks like this: <?php switch ($_GET['page']) { case 'news': echo ("NEWS HERE"); } break; case 'schedule'; echo ("SCHEDULE HERE"); } break; default: echo ("MAIN PAGE HERE"); break; } What I am trying to do, is specify that if the page is news, there can be an additional variable for id. I attempted before and after the break; for the news case, to make a new switch, but it isn't taking. I've looked around online, but can't find any information about this. Can anyone offer a hand?
  9. Hmm, maybe if I look at it section by section. <?php if ($_GET['page'] == 'roster') { This should state, if the URL is ?page=roster if ($_GET['id']) { $id = $_GET['id']; $link = mysql_connect ($host, $user, $password); This should identify that if there is an additional variable on the IRL that is ?id=something. $query = "SELECT * FROM roster WHERE id = '$id'"; $result = mysql_db_query ($db, $query, $link); This should tell PHP to choose anything from the roster table, where the id = whatever is in the URL. while ($row = mysql_fetch_array ($result)) { // Blah Blah If such is true, display whatever. Am I misunderstanding something here or am I correct?
  10. I'm currently not having any problem with the DB connection or query, or my other queries would not work, right?
  11. Good Afternoon: My attempt to use the switches for what I want to do is not working, so I'm going back to the if statements, but it's been a while. Below is what I currently have, but it is not working. <?php if ($_GET['page'] == 'about') { $link = mysql_connect ($host, $user, $password); $query = "SELECT * from about"; $result = mysql_db_query ($db, $query, $link); while ($row = mysql_fetch_array ($result)) { echo ("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td class=\"NewsHdr\">About Dangerous Alliance</td> </tr> <tr> <td class=\"NewsContent\">".$row['content'] . "</td> </tr> </table>"); } } if ($_GET['page'] == 'roster') { if ($_GET['id']) { $id = $_GET['id']; $link = mysql_connect ($host, $user, $password); $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\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td colspan=\"8\" class=\"NewsHdr\">[-DA-] ".$row['name'] . "</td> </tr> <tr> <td width=\"12%\" class=\"NewsDetail\">Name</td> <td width=\"11%\" class=\"NewsDetail\">Rank</td> <td width=\"13%\" class=\"NewsDetail\">Status</td> <td width=\"12%\" class=\"NewsDetail\">SteamID</td> <td width=\"16%\" class=\"NewsDetail\">Allies</td> <td width=\"9%\" class=\"NewsDetail\">Axis</td> <td width=\"13%\" class=\"NewsDetail\">Contact</td> <td width=\"14%\" class=\"NewsDetail\">Recruitment Date</td> </tr> <tr> <td class=\"NewsContent\"><a href=\"index.php?page=roster&id=".$row['id'] . "\">".$row['name'] . "</a></td> <td class=\"NewsContent\">".$row['rank'] . "</td> <td class=\"NewsContent\">".$row['status'] . "</td> <td class=\"NewsContent\">".$row['steamid'] . "</td> <td class=\"NewsContent\">".$row['allies'] . "</td> <td class=\"NewsContent\">".$row['axis'] . "</td> <td class=\"NewsContent\">".$row['email'] . "</td> <td class=\"NewsContent\">".$row['recdate'] . "</td> </tr> </table>"); } } else { $link = mysql_connect ($host, $user, $password); $query = "SELECT * FROM roster WHERE approved = 0"; $result = mysql_db_query ($db, $query, $link); while ($row = mysql_fetch_array ($result)) { echo ("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td colspan=\"8\" class=\"NewsHdr\">Roster</td> </tr> <tr> <td width=\"12%\" class=\"NewsDetail\">Name</td> <td width=\"11%\" class=\"NewsDetail\">Rank</td> <td width=\"13%\" class=\"NewsDetail\">Status</td> <td width=\"12%\" class=\"NewsDetail\">SteamID</td> <td width=\"16%\" class=\"NewsDetail\">Allies</td> <td width=\"9%\" class=\"NewsDetail\">Axis</td> <td width=\"13%\" class=\"NewsDetail\">Contact</td> <td width=\"14%\" class=\"NewsDetail\">Recruitment Date</td> </tr> <tr> <td class=\"NewsContent\"><a href=\"index.php?page=roster&id=".$row['id'] . "\">".$row['name'] . "</a></td> <td class=\"NewsContent\">".$row['rank'] . "</td> <td class=\"NewsContent\">".$row['status'] . "</td> <td class=\"NewsContent\">".$row['steamid'] . "</td> <td class=\"NewsContent\">".$row['allies'] . "</td> <td class=\"NewsContent\">".$row['axis'] . "</td> <td class=\"NewsContent\">".$row['email'] . "</td> <td class=\"NewsContent\">".$row['recdate'] . "</td> </tr> </table>"); } } } else { $link = mysql_connect ($host, $user, $password); $query = "SELECT * from news"; $result = mysql_db_query ($db, $query, $link); while ($row = mysql_fetch_array ($result)) { echo ("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td class=\"NewsHdr\">".$row['title'] . "</td> </tr> <tr> <td class=\"NewsDetail\">Posed by ".$row['author'] . " on ".$row['date'] . "</td> </tr> <tr> <td class=\"NewsContent\">".$row['content'] . "</td> </tr> </table>"); } } } ?> The problem is when I go to index.php?page=roster everything looks good. When I click on a roster member, it goes to ?page=roster&id=1 which it should because thats their ID, but it doesn't load anything that I called for the if statement for $_GET['id'].
  12. I've done what I am trying to do in the past using if statements, but I was told the switches are easier and cleaner to use. I just can't figure out how to use them to pull 2 different $_GET in the cases.
  13. Good Morning: I'm working on a few switch statements, and can't find any examples or assistance for what I am doing. I am using switch statements to specify URL variables (e.g. a switch to show case calendar for the URL index.php?page=calendar). This is working fine, but where I come into my problem, is when I need to specify 2 variables (e.g. to specify page=calendar, but id=# also). Below is the current code I have. <?php switch ($_GET['page']) { case about: echo ("Display coding for about page"); break; case roster: echo ("Display coding for team roster"); break; case games: echo ("Display coding for games"); break; default: echo ("Display coding for main page"); } ?> What I need to do, is for roster and games, I need to have an additional variable specified which is $_GET['id']...I tried this: <?php switch ($_GET['page']) { case about: echo ("Display coding for about page"); break; case roster: $id = $_GET['id']; switch ($_GET['page'] = 'roster' && $_GET['id']) { case $id: echo ("Display info specific to ID"); break; default; echo ("Display main team page"); } case games: echo ("Display coding for games"); break; default: echo ("Display coding for main page"); } ?> When I do this and go to index.php?page=roster, it says "Display info specific to ID", instead of the main team page. Can someone help me get this fixed?
  14. Premiso, Thank you for your help. The comments helped greatly.
  15. I mis-read your post, I thought you were talking about the entire string beginning with SELECT...it made no sense to me so I didn't look at the full code you posted! Now, I've never seen this before and forgive me if it's a simple fix. I corrected the " to a ' and now where it should say 1 (because I have 1 row with a result=Win) it says Array ?
×
×
  • 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.