Jump to content

var dump = String (0)"" empty query? help...


Recommended Posts

 

  // Build search query and embed filters
  $strSQL = sprintf(
    'SELECT
          r.id
          ,r.name
          ,r.image
       FROM
          stores r
         %s
         %s
         %s'
     ,$boolIncludeZipCodes === true?'INNER JOIN zip_codes z ON r.id = z_id':''
     ,empty($arrSQLFilters)?'':' WHERE '.implode(' AND ',$arrSQLFilters)  
     ,$boolIncludeZipCodes === true?'GROUP BY r.id':''
    );
    
     
    
    $arrResult = mysql_query($strSQL);
    while($arrRow = mysql_fetch_assoc($arrResult)) {
        $arrRestaurants[] = $arrRow;
    }
        
}
?>

 

I have var Dump the above query and it display

 

string(0) ""

 

Why if the tables fields above has information or data inside?

Link to comment
https://forums.phpfreaks.com/topic/183543-var-dump-string-0-empty-query-help/
Share on other sites

The posted code does not produce that error.

 

You are either -

A) Not executing the same file on your server that you are looking in (i.e. the file did not get uploaded onto your server),

B) Looking at the wrong source file,

C) Looking at the wrong query in the file,

D) That is not your whole code and something you removed for the post is causing the problem,

E) The variable $strSQL that you are setting is not the same as the one you are putting into the mysql_query(), either because you are using a Word Processor or a non-English keyboard and the variable name contains some odd character that is resulting in two separate variables that 'appear' to be the same.

 

Think about it and investigate the possible reasons why you can be assigning something to a variable at one point in your code but that variable has no value at another point in your code.

 

Best guess it that you actually have another query right before the code you posted or right after the code you posted and it is this other query that is producing the 'empty query' error.

A- is not an option since I have the same file name in the browser.

B- Might be since I don't know what is looking at the source file.

C-might be because there are a couple of queries beside that one but them working in relation with the one I have post it above.

 

i.e

  $strSQL = sprintf(
    'SELECT
          r.restaurants_id
          ,r.restaurantname
          ,r.image
       FROM
          restaurants r
         %s
         %s
         %s'
     ,$boolIncludeZipCodes === true?'INNER JOIN zip_codes z ON r.restaurants_id = z.restaurants_id':''
     ,empty($arrSQLFilters)?'':' WHERE '.implode(' AND ',$arrSQLFilters)  
     ,$boolIncludeZipCodes === true?'GROUP BY r.restaurants_id':''
    );

 

Ifi you see the $arrSQLFilters variable which it's content are the following queries

 

    if(!empty($arrFoodTypes) && !empty($arrFoodTypes[0])) {
    $arrSQLFilters[] = sprintf(
          'r.restaurants_id IN
               (SELECT
                     DISTINCT restaurants_id
                  FROM
                     restaurants_restaurant_food_types
                 WHERE
                     restaurants_food_types_id IN (%s)
                 GROUP
                    BY
                     restaurants_id
                HAVING 
                     COUNT(DISTINCT restaurants_id) = %u)'
            ,/*mysql_real_escape_string(*/ implode(',',$arrFoodTypes) /*)*/
            ,count($arrFoodTypes)
        );
    }

    // Offerings Filter ie. eat-in, lunch, dinner, etc
    if(!empty($arrOfferings)) {
      $arrSQLFilters[] = sprintf(
          'r.restaurants_id IN
               (SELECT
                     DISTINCT restaurants_id
                  FROM
                     restaurants_to_restaurant_offerings
                 WHERE
                     restaurant_offerings_id IN (%s)
                 GROUP
                    BY
                     restaurants_id
                HAVING 
                     COUNT(DISTINCT restaurants_id) = %u)'
            ,/*mysql_real_escape_string(*/ implode(',',$arrOfferings) /*)*/
            ,count($arrOfferings)
        );
    }

 

are two array values  $arrSQLFilters[] used in two similar queries that has different content? is that a problem to use the same $variable in different queries? Well  you need to see the whole context of the script to determine that I imagine.

 

D- might be a option since the whole code is posted below....

E- is not an option since I am using the same $strSQL variable in at mysql_query()

 

 

  // Build search query and embed filters
  $strSQL = sprintf(
    'SELECT
          r.restaurants_id
          ,r.restaurantname
          ,r.image
       FROM
          restaurants r
         %s
         %s
         %s'
     ,$boolIncludeZipCodes === true?'INNER JOIN zip_codes z ON r.restaurants_id = z.restaurants_id':''
     ,empty($arrSQLFilters)?'':' WHERE '.implode(' AND ',$arrSQLFilters)  
     ,$boolIncludeZipCodes === true?'GROUP BY r.restaurants_id':''
    );
    
     
    
    $arrResult = mysql_query($strSQL);
    while($arrRow = mysql_fetch_assoc($arrResult)) {
        $arrRestaurants[] = $arrRow;
    }
        
}

 

And onto your Best Guess you have suggested at the bottom of your post that might be an option as I have said since there are a couple of queries before and after the that bit of script but something to say those queries uses differents variables.

 

The entire php logic goes as follow

 

<?php
$strSQL = '';
$arrRestaurants = array();

// place holder form data variables
$strName = '';
$strZipCode = '';
$strState = '';
$arrFoodTypes = array();
$arrOfferings = array();

// food types and offerings drop down build arrays
$arrRestaurantsFoodTypes = array('values'=>array(),'output'=>array());
$arrStates = array('','AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA','HI','ID','IL','IN','IA','KS','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY',);
$arrRestaurantsOfferings = array();

$arrResult = mysql_query('SELECT restaurant_food_types_id,name FROM RESTAURANT_FOOD_TYPES');
while($arrRow = mysql_fetch_assoc($arrResult)) {
    $arrRestaurantsFoodTypes['values'][] = $arrRow['restaurant_food_types_id'];
    $arrRestaurantsFoodTypes['output'][] = $arrRow['name'];
}


$arrResult = mysql_query('SELECT restaurant_offerings_id,name FROM RESTAURANT_OFFERINGS');
while($arrRow = mysql_fetch_assoc($arrResult)) {
    $arrRestaurantsOfferings[] = $arrRow;
}




// reset form
$boolReset = isset($_POST['frmSearch']) && isset($_POST['frmSearch']['reset'])?true:false;

if($boolReset === true && isset($_POST['frmSearch'])) {

    // Extract POST variables and escape
    $strName = isset($_POST['frmSearch']['name'])?/*mysql_real_escape_string(*/$_POST['frmSearch']['name']/*)*/:'';
    $strZipCode = isset($_POST['frmSearch']['zipcode'])/*mysql_real_escape_string(*/?$_POST['frmSearch']['zipcode']/*)*/:'';
    $strState = isset($_POST['frmSearch']['state'])/*mysql_real_escape_string(*/?$_POST['frmSearch']['state']/*)*/:'';
    $arrFoodTypes = isset($_POST['frmSearch']['food_types'])?$_POST['frmSearch']['food_types']:array();
    $arrOfferings = isset($_POST['frmSearch']['offerings'])?$_POST['frmSearch']['offerings']:array();

    // WHERE clause filters
    $arrSQLFilters = array();
    
    // whether or not zip codes table needs to be included
    $boolIncludeZipCodes = false;


    // Zipcode filter
    if(!empty($strZipCode)) {
        $boolIncludeZipCodes = true;
    
        $arrSQLFilters[] = sprintf(
            "z.zip LIKE '%s'"
            ,"%$strZipCode%"
        );
    }
    
    // State filter
    if(!empty($strState)) {
        $boolIncludeZipCodes = true;
    
        $arrSQLFilters[] = sprintf(
            "z.state = '%s'"
            ,$strState
        );
    }

    // Restaurants name filter
    if(!empty($strName)) {
    
        $arrSQLFilters[] = sprintf(
            "r.restaurantname LIKE '%s'"
            ,"%$strName%"
        );
    }

    // Food types filter
    if(!empty($arrFoodTypes) && !empty($arrFoodTypes[0])) {
    $arrSQLFilters[] = sprintf(
          'r.restaurants_id IN
               (SELECT
                     DISTINCT restaurants_id
                  FROM
                     restaurants_restaurant_food_types
                 WHERE
                     restaurants_food_types_id IN (%s)
                 GROUP
                    BY
                     restaurants_id
                HAVING 
                     COUNT(DISTINCT restaurants_id) = %u)'
            ,/*mysql_real_escape_string(*/ implode(',',$arrFoodTypes) /*)*/
            ,count($arrFoodTypes)
        );
    }

    // Offerings Filter ie. eat-in, lunch, dinner, etc
    if(!empty($arrOfferings)) {
      $arrSQLFilters[] = sprintf(
          'r.restaurants_id IN
               (SELECT
                     DISTINCT restaurants_id
                  FROM
                     restaurants_to_restaurant_offerings
                 WHERE
                     restaurant_offerings_id IN (%s)
                 GROUP
                    BY
                     restaurants_id
                HAVING 
                     COUNT(DISTINCT restaurants_id) = %u)'
            ,/*mysql_real_escape_string(*/ implode(',',$arrOfferings) /*)*/
            ,count($arrOfferings)
        );
    }

    // Build search query and embed filters
  $strSQL = sprintf(
    'SELECT
          r.restaurants_id
          ,r.restaurantname
          ,r.image
       FROM
          restaurants r
         %s
         %s
         %s'
     ,$boolIncludeZipCodes === true?'INNER JOIN zip_codes z ON r.restaurants_id = z.restaurants_id':''
     ,empty($arrSQLFilters)?'':' WHERE '.implode(' AND ',$arrSQLFilters)  
     ,$boolIncludeZipCodes === true?'GROUP BY r.restaurants_id':''
    );
    
     
    
    $arrResult = mysql_query($strSQL);
    while($arrRow = mysql_fetch_assoc($arrResult)) {
        $arrRestaurants[] = $arrRow;
    }
        
}


?>

 

 

My own analysis as below thought it could help and I might be wrong.

 

<?php
$strSQL = '';
$arrRestaurants = array();

// place holder form data variables
$strName = '';
$strZipCode = '';
$strState = '';
$arrFoodTypes = array();
$arrOfferings = array();

// food types and offerings drop down build arrays
$arrRestaurantsFoodTypes = array('values'=>array(),'output'=>array());
$arrStates = array('','AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA','HI','ID','IL','IN','IA','KS','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY',);
$arrRestaurantsOfferings = array();

$arrResult = mysql_query('SELECT restaurant_food_types_id,name FROM RESTAURANT_FOOD_TYPES');
while($arrRow = mysql_fetch_assoc($arrResult)) {
    $arrRestaurantsFoodTypes['values'][] = $arrRow['restaurant_food_types_id'];
    $arrRestaurantsFoodTypes['output'][] = $arrRow['name'];
}

// reset form
$boolReset = isset($_POST['frmSearch']) && isset($_POST['frmSearch']['reset'])?true:false;

if($boolReset === true && isset($_POST['frmSearch'])) {

    // Extract POST variables and escape
    $strName = isset($_POST['frmSearch']['name'])?/*mysql_real_escape_string(*/$_POST['frmSearch']['name']/*)*/:'';
    $strZipCode = isset($_POST['frmSearch']['zipcode'])/*mysql_real_escape_string(*/?$_POST['frmSearch']['zipcode']/*)*/:'';
    $strState = isset($_POST['frmSearch']['state'])/*mysql_real_escape_string(*/?$_POST['frmSearch']['state']/*)*/:'';
    $arrFoodTypes = isset($_POST['frmSearch']['food_types'])?$_POST['frmSearch']['food_types']:array();
    $arrOfferings = isset($_POST['frmSearch']['offerings'])?$_POST['frmSearch']['offerings']:array();

    // WHERE clause filters
    $arrSQLFilters = array();
    
    // whether or not zip codes table needs to be included
    $boolIncludeZipCodes = false;


    // Zipcode filter
    if(!empty($strZipCode)) {
        $boolIncludeZipCodes = true;
    
        $arrSQLFilters[] = sprintf(
            "z.zip LIKE '%s'"
            ,"%$strZipCode%"
        );
    }
    
    // State filter
    if(!empty($strState)) {
        $boolIncludeZipCodes = true;
    
        $arrSQLFilters[] = sprintf(
            "z.state = '%s'"
            ,$strState
        );
    }

    // Restaurants name filter
    if(!empty($strName)) {
        $arrSQLFilters[] = sprintf(
            "r.restaurantname LIKE '%s'"
            ,"%$strName%"
        );
    }
// Food types filter
    if(!empty($arrFoodTypes) && !empty($arrFoodTypes[0])) {
    $arrSQLFilters[] = sprintf(
          'r.restaurants_id IN
               (SELECT
                     DISTINCT restaurants_id
                  FROM
                     restaurants_restaurant_food_types
                 WHERE
                     restaurants_food_types_id IN (%s)
                 GROUP
                    BY
                     restaurants_id
                HAVING 
                     COUNT(DISTINCT restaurants_id) = %u)'
            ,/*mysql_real_escape_string(*/ implode(',',$arrFoodTypes) /*)*/
            ,count($arrFoodTypes)
        );
    }

    // Offerings Filter ie. eat-in, lunch, dinner, etc
    if(!empty($arrOfferings)) {
      $arrSQLFilters[] = sprintf(
          'r.restaurants_id IN
               (SELECT
                     DISTINCT restaurants_id
                  FROM
                     restaurants_to_restaurant_offerings
                 WHERE
                     restaurant_offerings_id IN (%s)
                 GROUP
                    BY
                     restaurants_id
                HAVING 
                     COUNT(DISTINCT restaurants_id) = %u)'
            ,/*mysql_real_escape_string(*/ implode(',',$arrOfferings) /*)*/
            ,count($arrOfferings)
        );
    }

    // Build search query and embed filters
  $strSQL = sprintf(
    'SELECT
          r.restaurants_id
          ,r.restaurantname
          ,r.image
       FROM
          restaurants r
         %s
         %s
         %s'
     ,$boolIncludeZipCodes === true?'INNER JOIN zip_codes z ON r.restaurants_id = z.restaurants_id':''
     ,empty($arrSQLFilters)?'':' WHERE '.implode(' AND ',$arrSQLFilters)  
     ,$boolIncludeZipCodes === true?'GROUP BY r.restaurants_id':''
    );
    
     
    
    $arrResult = mysql_query($strSQL);
    while($arrRow = mysql_fetch_assoc($arrResult)) {
        $arrRestaurants[] = $arrRow;
    }
        
}


?>

 

So the query we have been trying to var_dump, echo etc is all the way at the bottom of the above script, Now you can see that the query trying to be var_dump has a variable $boolIncludeZipCodes and has to be === true? it means that the user has enter a zipcode to [HIGHLIGHT=SQL]'INNER JOIN zip_codes z ON r.restaurants_id = z.restaurants_id':''[/HIGHLIGHT]?

 

right?

 

and again to [HIGHLIGHT=SQL]GROUP BY r.restaurants_id':''

    );[/HIGHLIGHT]

 

if that's true then I have enter a zip code but still is displaying the $strSQL variable as

string(0) ""

 

well then it means that the filters

 

 // WHERE clause filters
    $arrSQLFilters = array();
    
    // whether or not zip codes table needs to be included
    $boolIncludeZipCodes = false;


    // Zipcode filter
    if(!empty($strZipCode)) {
        $boolIncludeZipCodes = true;
    
        $arrSQLFilters[] = sprintf(
            "z.zip LIKE '%s'"
            ,"%$strZipCode%"
        );
    }
    
    // State filter
    if(!empty($strState)) {
        $boolIncludeZipCodes = true;
    
        $arrSQLFilters[] = sprintf(
            "z.state = '%s'"
            ,$strState
        );
    }

    // Restaurants name filter
    if(!empty($strName)) {
        $arrSQLFilters[] = sprintf(
            "r.restaurantname LIKE '%s'"
            ,"%$strName%"
        );
    }

 

has some kind of set up which it's not letting $strSQL to pull up the data from the database.

 

And I think it's the $boolIncludeZipCodes variable that won't let user to get the results if the $boolIncludeZipCodes variable is not exactly true? what is true in this sense?

 

Take a look at the $boolResset variable set up at the script too that $boolReset, at the top of the script and it maybe not letting some value to pass.

 

$boolReset = isset($_POST['frmSearch']) && isset($_POST['frmSearch']['reset'])?true:false;

if($boolReset === true && isset($_POST['frmSearch'])) {

So the query we have been trying to var_dump, echo etc is all the way at the bottom of the above script,

 

In everything you just posted, you don't show the code that is doing that.

 

However, in looking at your previous threads, you are testing if $strSQL is not empty and echoing it OUTSIDE of the conditional logic that is setting $strSQL.

 

So, it would appear that you should actually be trying to find out why the conditional logic surrounding the code that is setting $strSQL is evaluating as FALSE. And that would be this code -

 

$boolReset = isset($_POST['frmSearch']) && isset($_POST['frmSearch']['reset'])?true:false;

if($boolReset === true && isset($_POST['frmSearch'])) {

 

What do you get when you put the following lines of code immediately before that -

 

echo "<pre>";
echo "POST:";
print_r($_POST);
echo "</pre>";

The lines you gave me above ouput the following

POST:Array
(
)

_

you are right I was trying to var_dump everything outside the variables scope Now if I var_dump inside the variable scope There is not result in the screen. I don't see any data below is how I have set up the var_dump function inside the variable scope.

 

  <?php  // Build search query and embed filters
  $strSQL = sprintf(
    'SELECT
          r.restaurants_id
          ,r.restaurantname
          ,r.image
       FROM
          restaurants r
         %s
         %s
         %s'
     ,$boolIncludeZipCodes === true?'INNER JOIN zip_codes z ON r.restaurants_id = z.restaurants_id':''
     ,empty($arrSQLFilters)?'':' WHERE '.implode(' AND ',$arrSQLFilters)  
     ,$boolIncludeZipCodes === true?'GROUP BY r.restaurants_id':''
    );
    
     
    
    $arrResult = mysql_query($strSQL);
    while($arrRow = mysql_fetch_assoc($arrResult)) {
        $arrRestaurants[] = $arrRow;
    }
        var_dump($strSQL);
var_dump($arrResult);
var_dump($arrRow);
}
?>

 

 

entire code for references as below

<?php
$strSQL = '';
$arrRestaurants = array();

// place holder form data variables
$strName = '';
$strZipCode = '';
$strState = '';
$arrFoodTypes = array();
$arrOfferings = array();

// food types and offerings drop down build arrays
$arrRestaurantsFoodTypes = array('values'=>array(),'output'=>array());
$arrStates = array('','AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA','HI','ID','IL','IN','IA','KS','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY',);
$arrRestaurantsOfferings = array();

$arrResult = mysql_query('SELECT restaurant_food_types_id,name FROM RESTAURANT_FOOD_TYPES');
while($arrRow = mysql_fetch_assoc($arrResult)) {
    $arrRestaurantsFoodTypes['values'][] = $arrRow['restaurant_food_types_id'];
    $arrRestaurantsFoodTypes['output'][] = $arrRow['name'];
}


$arrResult = mysql_query('SELECT restaurant_offerings_id,name FROM RESTAURANT_OFFERINGS');
while($arrRow = mysql_fetch_assoc($arrResult)) {
    $arrRestaurantsOfferings[] = $arrRow;
}




// reset form
$boolReset = isset($_POST['frmSearch']) && isset($_POST['frmSearch']['reset'])?true:false;

if($boolReset === false && isset($_POST['frmSearch'])) {

    // Extract POST variables and escape
    $strName = isset($_POST['frmSearch']['name'])?/*mysql_real_escape_string(*/$_POST['frmSearch']['name']/*)*/:'';
    $strZipCode = isset($_POST['frmSearch']['zipcode'])/*mysql_real_escape_string(*/?$_POST['frmSearch']['zipcode']/*)*/:'';
    $strState = isset($_POST['frmSearch']['state'])/*mysql_real_escape_string(*/?$_POST['frmSearch']['state']/*)*/:'';
    $arrFoodTypes = isset($_POST['frmSearch']['food_types'])?$_POST['frmSearch']['food_types']:array();
    $arrOfferings = isset($_POST['frmSearch']['offerings'])?$_POST['frmSearch']['offerings']:array();

    // WHERE clause filters
    $arrSQLFilters = array();
    
    // whether or not zip codes table needs to be included
    $boolIncludeZipCodes = false;


    // Zipcode filter
    if(!empty($strZipCode)) {
        $boolIncludeZipCodes = true;
    
        $arrSQLFilters[] = sprintf(
            "z.zip LIKE '%s'"
            ,"%$strZipCode%"
        );
    }
    
    // State filter
    if(!empty($strState)) {
        $boolIncludeZipCodes = true;
    
        $arrSQLFilters[] = sprintf(
            "z.state = '%s'"
            ,$strState
        );
    }

    // Restaurants name filter
    if(!empty($strName)) {
    
        $arrSQLFilters[] = sprintf(
            "r.restaurantname LIKE '%s'"
            ,"%$strName%"
        );
    }

    // Food types filter
    if(!empty($arrFoodTypes) && !empty($arrFoodTypes[0])) {
    $arrSQLFilters[] = sprintf(
          'r.restaurants_id IN
               (SELECT
                     DISTINCT restaurants_id
                  FROM
                     restaurants_restaurant_food_types
                 WHERE
                     restaurants_food_types_id IN (%s)
                 GROUP
                    BY
                     restaurants_id
                HAVING 
                     COUNT(DISTINCT restaurants_id) = %u)'
            ,/*mysql_real_escape_string(*/ implode(',',$arrFoodTypes) /*)*/
            ,count($arrFoodTypes)
        );
    }

    // Offerings Filter ie. eat-in, lunch, dinner, etc
    if(!empty($arrOfferings)) {
      $arrSQLFilters[] = sprintf(
          'r.restaurants_id IN
               (SELECT
                     DISTINCT restaurants_id
                  FROM
                     restaurants_to_restaurant_offerings
                 WHERE
                     restaurant_offerings_id IN (%s)
                 GROUP
                    BY
                     restaurants_id
                HAVING 
                     COUNT(DISTINCT restaurants_id) = %u)'
            ,/*mysql_real_escape_string(*/ implode(',',$arrOfferings) /*)*/
            ,count($arrOfferings)
        );
    }

    // Build search query and embed filters
  $strSQL = sprintf(
    'SELECT
          r.restaurants_id
          ,r.restaurantname
          ,r.image
       FROM
          restaurants r
         %s
         %s
         %s'
     ,$boolIncludeZipCodes === true?'INNER JOIN zip_codes z ON r.restaurants_id = z.restaurants_id':''
     ,empty($arrSQLFilters)?'':' WHERE '.implode(' AND ',$arrSQLFilters)  
     ,$boolIncludeZipCodes === true?'GROUP BY r.restaurants_id':''
    );
    
     
    
    $arrResult = mysql_query($strSQL);
    while($arrRow = mysql_fetch_assoc($arrResult)) {
        $arrRestaurants[] = $arrRow;
    }
        var_dump($strSQL);
var_dump($arrResult);
var_dump($arrRow);
}


?>

<div id="wrapper">
<form class="abajo"  name="frmSearch" action="<?php echo $_SERVER['PHP_SELF'];?>"

method="POST">

<fieldset class="primero">
	<legend class="primerosub">Find A Restuarant</legend>
        <fieldset class="segundo1" style="border-color:#FFFFFF" >  
<legend>Location Details</legend>
        <ol>
            <li class="restaurants-name">
                <label for="restaurants-name">Name</label>
                <input type="text" name="frmSearch[name]" value="<?php echo $strName; ?>" id="restaurants-name">
            </li>
            <li class="restaurants-zipcode">
                <label for="restaurants-zipcode">Zip</label>
                <input type="text" name="frmSearch[zipcode]" value="<?php echo $strZipCode; ?>" maxlength="5" id="restaurants-name">
            </li>
            
            <?php if(!empty($arrStates)) { ?>
                <li class="restaurants-state">
                    <label for="restaurants-state">State</label>
                    <select name="frmSearch[state]" id="restaurants-state">
                        <?php
                        foreach($arrStates as $strStateAbb) {
                            printf(
                                '<option value="%s"%s>%s</option>'
                                ,$strStateAbb
                                ,strcmp($strState,$strStateAbb) == 0?' selected="selected"':''
                                ,strcmp($strStateAbb,'')==0?'--':$strStateAbb
                            );
                        }    
                        ?>
                    </select>
                </li>
            <?php } ?>
            
            <?php if(!empty($arrRestaurantsFoodTypes)) { ?>
                <li class="restaurants-food-types">
                    <label for="restaurants-food-types">Food Type</label>
                    <select name="frmSearch[food_types][]" id="restaurants-food-types">
                        <?php
                        foreach($arrRestaurantsFoodTypes['values'] as $intIndex=>$intFoodTypesId) {
                            printf(
                                '<option value="%s"%s>%s</option>'
                                ,$intFoodTypesId
                                ,in_array($intFoodTypesId,$arrFoodTypes)?' selected="selected"':''
                                ,$arrRestaurantsFoodTypes['output'][$intIndex]
                            );
                        }    
                        ?>
                    </select>
                </li>
                </ol>
            <?php } ?>
            </fieldset>
            
            <?php if(!empty($arrRestaurantsOfferings)) { ?>
<fieldset class="tercero" style="" >
<legend>Services</legend>

         
                
                    <?php
                    foreach($arrRestaurantsOfferings as $arrRestaurantsOffering) {
                        printf(
                            '<ol><li class="restaurants-offerings-%u">
                                  <input type="checkbox" name="frmSearch[offerings][]" value="%u" id="restaurants-offerings-%u"%s>
                                  <span for="restaurants-offerings-%u" class="checkboxes23">%s</span>
                            </li></ol>'
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,in_array($arrRestaurantsOffering['restaurant_offerings_id'],$arrOfferings)?' checked="checked"':''
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['name']
                        );
                    }
                ?>
                
         
                        <?php } ?></fieldset>
            
            <li class="submit">
                <input type="submit" value="Submit" name="frmSearch[submit]">
            </li>
            
            <li class="reset">
                <input type="submit" value="reset" name="frmSearch[reset]">
            </li>
            
        </ul>
    </fieldset>
</form>
</div>
<?php 

echo "<pre>";
echo "POST:";
print_r($_POST);
echo "</pre>"; 

?>

The form in the code you posted, submits data to the form processing code and produces a var_dump($strSQL) that looks like this (tested) -

 

"SELECT r.restaurants_id ,r.restaurantname ,r.image FROM restaurants r INNER JOIN zip_codes z ON r.restaurants_id = z.restaurants_id WHERE z.zip LIKE '%123456%' AND z.state = 'KS' AND r.restaurantname LIKE '%name%' GROUP BY r.restaurants_id"

 

Are you submitting the form on that page to reach that page or are you using some other form/page to get to that page?

 

Also, are you including that code in another page or redirecting to different pages?

 

Short-version: Your $_POST array is empty for some reason, but submitting the form on that page does set the $_POST array and produces 'something' in $strSQL, so how you are submitting to that page is not using that form. It is also possible that your browser is requesting that page twice and you are only seeing the result of the second request, when the $_POST array is empty.

How do I realize if the browser is requesting the page twice?

 

Are you submitting the form on that page to reach that page or are you using some other form/page to get to that page?

 

the action form is set up to submit the form on the same page

<form class="abajo"  name="frmSearch" action="<?php echo $_SERVER['PHP_SELF'];?>"

 

at least that's what I understand the

<?php echo $_SERVER['PHP_SELF'];?>

is for.

 

Also, are you including that code in another page or redirecting to different pages?

 

There is one include at the top of the page that is used for multiple pages but no more than that.

 

I have place the bit of code you gave before inside the script but submitting the form this time and it display a different result.

 

The bit of code given above

 <?php 

echo "<pre>";
echo "POST:";
print_r($_POST);
echo "</pre>"; 

?>

 

As you can see it will print what the POST variable is generating.

 

Well after I enter a value in the zipcode field in the form and press sumit then The POST variables display the following

 

POST:Array

(

    [frmSearch] => Array

        (

            [name] =>

            [zipcode] => 01561

            [state] =>

            [food_types] => Array

                (

                    [0] => 1

                )

 

            [submit] => Submit

        )

 

)

 

The query and it's dynamism also display in the screen.

 

SELECT r.restaurants_id ,r.restaurantname ,r.image FROM restaurants r INNER JOIN zip_codes z ON r.restaurants_id = z.restaurants_id WHERE z.zip LIKE '%01561%' AND r.restaurants_id IN (SELECT DISTINCT restaurants_id FROM restaurants_restaurant_food_types WHERE restaurants_food_types_id IN (1) GROUP BY restaurants_id HAVING COUNT(DISTINCT restaurants_id) = 1) GROUP BY r.restaurants_id

 

You saying that the code is just populating arrays only so it means I have to set up some HTML and to set it up to display the data desired.

 

WEll I have hard code some html and I use the and use the $strSQL that contain the array list of restaurants to display it but it is not working at all and I don't know if I am actually scripting properly in HTML and PHP terms.

 

HTML and PHP to display the array list of restaurants.

 

// print search query
if(!empty($strSQL)) { printf('<p>%s</p>',$strSQL);
$i = 1;
foreach($arrRestaurants as $arrRestaurant) {

  echo "<div class=\"shoeinfo1\">
   <img src=\"images/spacer.gif\" alt=\"spacer\" class=\"spacer2\" />
      <h2 class=\"infohead\">". $arrRestaurant['restaurantname'] . "</h2>
      <div class=\"pic\"><img class=\"line\" src= ". $arrRestaurant['image'] ." alt=\"picture\" width=\"100%\" height=\"100%\" /></div>

      
    </div>";
$i++; 
}
if ($i > 1 && $i % 3 == 0 ) 
{
  echo "<div class=\"clearer\"></div>";

}

}



?>
</div>
</div>

 

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.