[SOLVED] IF statements and cases
Posted: Fri Jul 28, 2006 1:34 pm
feyd | Please use
If you enter a username, you'll see it goes the way it is supposed to.
If you enter a date, it applies the username AND the date fields.
If you select the problem type, it applies username, date, and problem fields.
I'm really confused... Can someone clarify?
-Mike
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
OK, so I'm trying to get some IF statements to work so I can do a total of 4 cases (If only the field USERNAME is filled, if only the field WEEKLY is filled, if only the PROBLEMS are used, and if none of them selected [to display the page html to make a selection]).
However, with the code I'm using, all 3 cases are displayed... You can see it here: http://169hamilton.kicks-ass.net:8088/c ... _admin.php
The code isCode: Select all
<body>
<?php
// Declare The Needed Variables - DO NOT MODIFY!
$host = "localhost";
$user = "root";
$pass = "mypass";
$db = "mydb";
$table = "mytable";
$problems = array('Printing (Hardware)','Printing (Software)','Print Retrieval', 'Account Problems', 'Password Changes', 'File Storage/Retrieval', 'Personal Equipment', 'Internet/Networking', 'Dorm/Resnet', 'Wireless', 'Info/Directions', 'IMLs', 'Email', 'Policy', 'Class-Related', 'Phone Support', 'Supplies', 'Hardware', 'Software', 'Other (Must Comment!)');
// Connect to the Server with Specified Username and Password - DO NOT MODIFY!
mysql_connect($host, $user, $pass) or die("Connection Failed! " . mysql_error());
// Connect to the Specified Database - DO NOT MODIFY!
mysql_select_db($db) or die("DB Select Failed! " . mysql_error());
if (isset($_POST['username']))
{
$name = $_POST['username'];
// Make the Query - DO NOT MODIFY!
$sql = 'SELECT * FROM data_02 WHERE Username=\''.$name.'\'';
$data = mysql_query($sql) or die ("Query Failed! " . mysql_error());
$out1 = "Displaying all entries from ".$name."\n";
echo nl2br($out1);
while($info = mysql_fetch_array($data))
{
$out2 = "\nSubmission on ".$info['Date']." at ".$info['Time'];
$out3 = "\n--Problem: ".$info['Problem'];
$out4 = "\n--Comments: ".$info['Comments']."\n";
echo nl2br($out2);
echo nl2br($out3);
echo nl2br($out4);
}
}
else if (isset($_POST['weekly']))
{
$weekly = $_POST['weekly'];
$out1 = "Displaying all submissions received from FROM to TO.";
echo nl2br($out1);
}
else if (isset($_POST['problems']))
{
$out1 = "Displaying all submissions of type PROBLEM.";
echo nl2br($out1);
}
else
{
?>
<div class="main">
...HTML...
<p>Last Updated: <?php print date("F d, Y. g:i a", getlastmod()); ?>, msantang<br></p>
</div>
<?php
}
?>
</body>
</html>If you enter a date, it applies the username AND the date fields.
If you select the problem type, it applies username, date, and problem fields.
I'm really confused... Can someone clarify?
-Mike
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]