PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
if ($_GET["page"] == "open") {
$query = mysql_query("SELECT *
FROM customer, jobs
WHERE customer.customerid = jobs.customerid
AND customer.customerid = '$_SESSION[username]'
AND status = 'Not Delivered'");
}
if ($_GET["page"] == "closed") {
$query = mysql_query("SELECT *
FROM customer, jobs
WHERE customer.customerid = jobs.customerid
AND customer.customer = '$_SESSION[username]'
AND status = 'Delivered'");
}
echo "<table border>";
echo "<td bgcolor = 'FFFFCC' valign = 'top'>";
echo "<h2> <b> <u> Delivery Information </u> </b> </h2> <br>";
while ($res4 = mysql_fetch_array($query)) {
switch ($res4) {
case (empty($res4)):
echo "There are no open deliveries";
break;
case (empty($res4)):
echo "There are no closed deliveries";
break;
}
But nothing is ever returned, whether results are returned or not.
I'm not exactly sure why you would want to do that. Typically we don't want our queries to fail, ever. We simply want to check if any rows were returned.
<?php
// Lets make sure the get var is set first
if (isset($_GET['page'])) {
// Create a generic query to customize in a bit
$sql = "SELECT *
FROM customer, jobs
WHERE customer.customerid = jobs.customerid
AND customer.customerid = '$_SESSION[username]'
AND status = '@@STATUS@@'";
// Now lets figure out what we want to query by
if ($_GET["page"] == "open") {
$status = 'Not Delivered';
} elseif ($_GET["page"] == "closed") {
$status = 'Delivered';
} else {
$status = 'MAKE A DEFAULT VALUE';
}
// Build the query
$sql = str_replace('@@STATUS@@', $status, $sql);
// Try the query
if (!$result = mysql_query($sql))
{
die(mysql_error());
}
// This is your query result
$rows = mysql_fetch_array($result);
// This is the number of row returned in the result
$row_count = mysql_num_rows($result);
// echo some stuff out
echo "<table border>";
echo "<td bgcolor = 'FFFFCC' valign = 'top'>";
echo "<h2> <b> <u> Delivery Information </u> </b> </h2> <br>";
}
?>
Dude, all I can say is 'doh! what was I thinking?' I must have been tired, because I have l never done it the way I coded the example. In almost all cases I do it like Jcart did it.
Man, I really need to make sure I have coffee in me before I post code again.