Greetings all,
I have a mysql database that right now I am just spitting all the data from it's only table back to a web page to report it. It contains user data from a software download page for our campus IT department. I thought about making a page that would allow the user to have some selection criteria they could define.
Here is the form:
And here is the follow up page with the SELECT statements:
Couple questions...
1. I get an error in the apache log:
[error] PHP Parse error: syntax error, unexpected T_BOOLEAN_OR in reporttest.php on line 11
I am trying to use an OR statement that says if either field has something besides include all, that a WHERE will be put into the query. I have tried | and || and get the same error. Any thoughts?
2. In general, is there a better way to do this? I just went through this in my mind and did the code, and I don't have a ton of PHP experience.
Thanks for your time.
- Dan
I have a mysql database that right now I am just spitting all the data from it's only table back to a web page to report it. It contains user data from a software download page for our campus IT department. I thought about making a page that would allow the user to have some selection criteria they could define.
Here is the form:
Code:
<html>
<h2>Software Downloads Report Page</h2>
<form action="reporttest.php" method="post">
<h3>Search for options where:</h3>
<p>Software equals
<select name="softwaretitle">
<option value="testfile">Test</option>
<option value="all">All Software</option>
</select>
<p>Affiliation equals
<select name="affiliation">
<option value="student">Student</option>
<option value="staff">Fact/Staff</option>
<option value="affall">Both Groups</option>
</select>
<p>
Sort by:
<select name="sort">
<option value="login">Login</option>
<option value="software_title">Software Title</option>
<option value="affiliation">Affiliation</option>
<option value="date_dload">Date</option>
</select>
<p>
<input name="Create Report" type="submit" value="Create Report">
</form>
</html>
And here is the follow up page with the SELECT statements:
Code:
<?php
// Make connection
include("inc/connect.php");
// Take information from form and get data
$software = $_POST['softwaretitle'];
$affiliation = $_POST['affiliation'];
$sort = $_POST['sort'];
if ($affiliation != 'affall' || $software != 'all')
{
$where = "WHERE";
}
if $software != "all"
{
$wheresoft = "software_title = $software";
}
if $affiliation != "affall"
{
$whereaff = "affiliation = $affiliation";
}
if ($affiliation != "affall") && ($software != "all")
{
$or = "or";
}
$query = (SELECT * FROM downloads '$where' '$wheresoft' '$or' '$whereaff' ORDER BY '$sort');
$result = mysql_query( $query )
or die(mysql_error());
echo "<table border='4'>";
echo "<tr> <th>Login</th> <th>Software Title</th> <th>Affiliation</th> <th>Date</th> <th>Time</th> </tr>";
// keeps getting the next row until there are none left
while ($row = mysql_fetch_array( $result )) {
// print out the contents of each row into a table
echo "<tr><td>";
echo $row['login'];
echo "</td><td>";
echo $row['software_title'];
echo "</td><td>";
echo $row['affiliation'];
echo "</td><td>";
echo $row['date_dload'];
echo "</td><td>";
echo $row['time'];
echo "</td></tr>";
}
echo "</table>";
?>
Couple questions...
1. I get an error in the apache log:
[error] PHP Parse error: syntax error, unexpected T_BOOLEAN_OR in reporttest.php on line 11
I am trying to use an OR statement that says if either field has something besides include all, that a WHERE will be put into the query. I have tried | and || and get the same error. Any thoughts?
2. In general, is there a better way to do this? I just went through this in my mind and did the code, and I don't have a ton of PHP experience.
Thanks for your time.
- Dan