Jump to content

empty results check not working...


rbrown

Recommended Posts

Been trying to find an answer and keep running around in circles...

I have: ( left test echos in there)

        if ($r['left_house_number'] != '') {
            /* Now see what they are supposed to get */
            $left_customer_query = "SELECT * FROM customer WHERE house_number ='".$r['left_house_number']."' AND street = '".$r['left_house_street']."' AND route_number = '".$_SESSION['route_number']."'";
// echo "SELECT * FROM customer WHERE house_number ='".$r['left_house_number']."' AND street = '".$r['left_house_street']."' AND route_number = '".$_SESSION['route_number']."'";
            $left_customer_result = mysql_query($left_customer_query) or die(mysql_error());
                $left_customer_result_count = mysql_num_rows($left_customer_result);
echo $r['left_house_number'].' =lhn1';
            while ($lrow = mysql_fetch_array($left_customer_result)) {
echo $r['left_house_number'].' =lhn2';
                /* See if there is any customer if not display blank row */
echo $left_customer_result_count.' = count ';
                if ($left_customer_result_count < 1) {
echo $r['left_house_number'].' =lhn3';
                    echo '<span class="delivery_nothing">'.$r['left_house_number'].' </span> 1<span class="delivery_nothing">'.$r['left_house_street'].' ';
                } else {
                    /* Have a customer, now check to see if they are supposed to get something */
                    if ($lrow['status'] != "AC" && $lrow['status'] != "VH") {
                        /* Customer is stopped or on vacation so show house number and street not bolded */
                        echo '<span class="delivery_nothing">'.$r['left_house_number'].'</span>2<span class="delivery_nothing">'.$r['left_house_street'];
echo $r['left_house_number'].' =lhn4';
                    } else {
                        /* Now check for correct delivery day and return data */
                        if (Show_Product($lrow['product']) == '1') {
echo $r['left_house_number'].' =lhn5';
                            echo '<span class="delivery_bold">'.$lrow['house_number'].'</span><span class="delivery_bold">'.$lrow['placement'].'</span><span class="delivery_bold">'.$lrow['street'].'</span>';
                            echo Product_Formater($lrow['product']);
                        }

I have tried...

if ($left_customer_result_count < 1) {

if ($left_customer_result_count == 0) {

if ($left_customer_result_count == '') {

if ($left_customer_result_count === 0) {

 

And I can't get it to work.

the count "test echo" is either blank or 1

 

If I echo the sql statement with values I know aren't in the db and paste it into phpmyadmin:

SELECT * FROM customer WHERE house_number = '3333' AND street = 'Chili Avenue' AND route_number = '68-24-630'

 

I get:

"MySQL returned an empty result set"

 

And if I change it to something that is in the db:

SELECT * FROM customer WHERE house_number = '3019' AND street = 'Chili Avenue' AND route_number = '68-24-630'

 

I get:

"Showing rows 0 - 0 (1 total, Query took 0.0012 sec)"

 

 

So what do I have to do to get this to work right?

What does it actually output when there are no results returned?

thanks,

Link to comment
Share on other sites

If there are zero rows in the result set, mysql_fetch_array($left_customer_result) will be false and the code inside your while(){} loop will be skipped over. The code you have inside your while(){} loop that is testing or displaying $left_customer_result_count won't ever be executed.

 

You would want to test $left_customer_result_count before the start of your while(){} loop.

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.