sford999 Posted February 26, 2007 Share Posted February 26, 2007 I have the following code: if(isset($_POST['Submit'])) { $club_name = mysql_real_escape_string($_POST['club_name']); $town = mysql_real_escape_string($_POST['town']); $county = mysql_real_escape_string($_POST['county']); $postcode = mysql_real_escape_string($_POST['postcode']); $price_low = mysql_real_escape_string($_POST['price_low']); $price_high = mysql_real_escape_string($_POST['price_high']); $disabled = mysql_real_escape_string($_POST['disabled']); $carp = mysql_real_escape_string($_POST['carp']); $night_fishing = mysql_real_escape_string($_POST['night_fishing']); $closed_season = mysql_real_escape_string($_POST['closed_season']); $opm = mysql_real_escape_string($_POST['opm']); $species = $_POST['species']; if($club_name){ $whereParts[] = "club_name LIKE '%$club_name%'"; } if($town){ $whereParts[] = "town LIKE '%$town%'"; } if($county){ $whereParts[] = "county = '$county'"; } if($postcode){ $whereParts[] = "postcode LIKE '%$postcode%'"; } if($price_low){ $whereParts[] = "price_low LIKE '%$price_low%'"; } if($price_high){ $whereParts[] = "price_high LIKE '%$price_high%'"; } if($disabled){ $whereParts[] = "disabled_access = '$disabled'"; } if($carp){ $whereParts[] = "carp_syndicate = '$carp'"; } if($night_fishing){ $whereParts[] = "night_fishing_allowed = '$night_fishing'"; } if($closed_season){ $whereParts[] = "close_season = '$closed_season'"; } if($opm){ $whereParts[] = "open_membership = '$opm'"; } //var_dump($whereParts); if (isset($species) && is_array($species)) { $search_cid = array(); foreach($species as $cid) { if (intval($cid) != 0) array_push($search_cid, intval($cid)); } if (count($search_cid) > 0) { $search = implode(',', $search_cid); array_push($whereParts[], 'species LIKE %$search_cid%'); } } $whereClause = implode(' AND ', $whereParts); $sql = "SELECT * FROM fisheries WHERE " . $whereClause; //var_dump($whereParts); // Normally the SQL query would go here, but I want it to echo out the query bore I build the rest of the script echo "<br />"; echo $sql; exit(); } else { //show_header($title = "Search Angling Clubs"); echo "<form id=\"clubs_search\" name=\"clubs_search\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."?p=clubs\"> <table width=\"100%\" border=\"0\" class=\"tablea\"> <tr> <td colspan=\"2\" class=\"tablec\"><div align=\"center\"> <h3>Search Angling Clubs</h3> </div></td> </tr> <tr> <td width=\"50%\" class=\"tablec\">Club Name </td> <td width=\"50%\" class=\"tablec\"><input name=\"club_name\" type=\"text\" id=\"club_name\" /></td> </tr> <tr> <td width=\"50%\" class=\"tablec\">Town</td> <td width=\"50%\" class=\"tablec\"><input name=\"town\" type=\"text\" id=\"town\" /></td> </tr> <tr> <td width=\"50%\" class=\"tablec\">County</td> <td width=\"50%\" class=\"tablec\"><select name=\"county\" class=\"textfield\"> <option value=\"1\" selected=\"selected\">Avon</option> <option value=\"2\">Bedfordshire</option> <option value=\"3\">Berkshire</option> <option value=\"4\">Buckinghamshire</option> <option value=\"5\">Cambridgeshire</option> <option value=\"6\">Cheshire</option> <option value=\"7\">Cleveland</option> <option value=\"8\">Cornwall</option> <option value=\"9\">Cumbria</option> <option value=\"10\">Derbyshire</option> <option value=\"11\">Devon</option> <option value=\"12\">Dorset</option> <option value=\"13\">Durham</option> <option value=\"14\">East Sussex</option> <option value=\"15\">Essex</option> <option value=\"16\">Gloucestershire</option> <option value=\"17\">Gt London</option> <option value=\"18\">Gt Manchester</option> <option value=\"19\">Hampshire</option> <option value=\"20\">Hereford and Worcester</option> <option value=\"21\">Hertfordshire</option> <option value=\"22\">Humberside</option> <option value=\"23\">Kent</option> <option value=\"24\">Lancashire</option> <option value=\"25\">Leicestershire</option> <option value=\"26\">Lincolnshire</option> <option value=\"27\">Merseyside</option> <option value=\"28\">Norfolk</option> <option value=\"29\">Northamptonshire</option> <option value=\"30\">Northumberland</option> <option value=\"31\">Nottinghamshire</option> <option value=\"32\">Oxfordshire</option> <option value=\"33\">Scotland</option> <option value=\"34\">Shropshire</option> <option value=\"35\">Somerset</option> <option value=\"36\">Staffordshire</option> <option value=\"37\">Suffolk</option> <option value=\"38\">Surrey</option> <option value=\"39\">Tyne and wear</option> <option value=\"40\">Wales</option> <option value=\"41\">Warwickshire</option> <option value=\"42\">West Sussex</option> <option value=\"43\">Wiltshire</option> <option value=\"44\">Yorkshire</option> </select> </td> </tr> <tr> <td width=\"50%\" class=\"tablec\">Postcode</td> <td width=\"50%\" class=\"tablec\"><input name=\"postcode\" type=\"text\" id=\"postcode\" /></td> </tr> <tr> <td width=\"50%\" class=\"tablec\">Price (low > high) </td> <td width=\"50%\" class=\"tablec\">£ <input name=\"price_low\" type=\"text\" size=\"8\" maxlength=\"6\" /> To £ <input name=\"price_high\" type=\"text\" size=\"8\" maxlength=\"6\" /></td> </tr> <tr> <td width=\"50%\" class=\"tablec\">Disabled Access</td> <td width=\"50%\" class=\"tablec\"><input name=\"disabled\" type=\"radio\" value=\"1\" /> Yes <input name=\"disabled\" type=\"radio\" value=\"0\" /> No</td> </tr> <tr> <td width=\"50%\" class=\"tablec\">Carp Syndicate </td> <td width=\"50%\" class=\"tablec\"><input name=\"carp\" type=\"radio\" value=\"1\" /> Yes <input name=\"carp\" type=\"radio\" value=\"0\" /> No</td> </tr> <tr> <td width=\"50%\" class=\"tablec\">Night Fishing Allowed </td> <td width=\"50%\" class=\"tablec\"><input name=\"night_fishing\" type=\"radio\" value=\"1\" /> Yes <input name=\"night_fishing\" type=\"radio\" value=\"0\" /> No</td> </tr> <tr> <td width=\"50%\" class=\"tablec\">Enforced Closed Season </td> <td width=\"50%\" class=\"tablec\"><input name=\"closed_season\" type=\"radio\" value=\"1\" /> Yes <input name=\"closed_season\" type=\"radio\" value=\"0\" /> No</td> </tr> <tr> <td width=\"50%\" class=\"tablec\">Open For Membership </td> <td width=\"50%\" class=\"tablec\"><input name=\"opm\" type=\"radio\" value=\"1\" /> Yes <input name=\"opm\" type=\"radio\" value=\"0\" /> No</td> </tr> <tr> <td width=\"50%\" class=\"tablec\">Species Available </td> <td width=\"50%\" class=\"tablec\"> <select name=\"species[]\" size=\"5\" multiple=\"multiple\"> <option value=\"1\">Barbel</option> <option value=\"2\">Bleak</option> <option value=\"3\">Bream</option> <option value=\"4\">Carp</option> <option value=\"5\">Carp (Crucian)</option> <option value=\"6\">Carp (Grass)</option> <option value=\"7\">Catfish</option> <option value=\"8\">Chub</option> <option value=\"9\">Dace</option> <option value=\"10\">Eel</option> <option value=\"11\">Grayling</option> <option value=\"12\">Gudgeon</option> <option value=\"13\">Minnow</option> <option value=\"14\">Orfe</option> <option value=\"15\">Perch</option> <option value=\"16\">Pike</option> <option value=\"17\">Roach</option> <option value=\"18\">Rudd</option> <option value=\"19\">Salmon</option> <option value=\"20\">Sturgeon</option> <option value=\"21\">Tench</option> <option value=\"22\">Trout</option> <option value=\"23\">Trout (Blue)</option> <option value=\"24\">Trout (Brook)</option> <option value=\"25\">Trout (Brown)</option> <option value=\"26\">Trout (Rainbow)</option> <option value=\"27\">Trout (Tiger)</option> <option value=\"28\">Zander</option> </select> </td> </tr> <tr> <td width=\"50%\" class=\"tablec\">Image Verification</td> <td width=\"50%\" class=\"tablec\"><img src=\"visual.php\" width=\"200\" height=\"60\" alt=\"Visual CAPTCHA\" /><br /> (Copy the code from the image above into the box below)<br /> <input name=\"usercode\" type=\"text\" id=\"usercode\" /></td> </tr> <tr> <td colspan=\"2\" class=\"tablec\"><div align=\"center\"> <input type=\"reset\" name=\"Reset\" value=\"Reset Form\" /> <input type=\"Submit\" name=\"Submit\" value=\"Start Search\" /> </div></td> </tr> </table> </form>"; //show_footer(); } When I do a var_dump before and after the "if(isset($species) && is_array($species))" I get the following array(6) { [0]=> string(12) "county = '4'" [1]=> string(21) "disabled_access = '1'" [2]=> string(20) "carp_syndicate = '1'" [3]=> string(27) "night_fishing_allowed = '1'" [4]=> string(18) "close_season = '1'" [5]=> string(21) "open_membership = '1'" } Warning: array_push(): First argument should be an array in C:\Server\xampp\htdocs\fisheries\search.php on line 279 array(7) { [0]=> string(12) "county = '4'" [1]=> string(21) "disabled_access = '1'" [2]=> string(20) "carp_syndicate = '1'" [3]=> string(27) "night_fishing_allowed = '1'" [4]=> string(18) "close_season = '1'" [5]=> string(21) "open_membership = '1'" [6]=> NULL } Line 279 is: array_push($whereParts[], 'species LIKE %$search_cid%'); Can someone take a look and help me out here as its really bugging me now Thanks Link to comment https://forums.phpfreaks.com/topic/40127-warning-array_push-first-argument-should-be-an-array/ Share on other sites More sharing options...
btherl Posted February 26, 2007 Share Posted February 26, 2007 You can use either $whereParts[] = 'blah'; or array_push($whereParts, 'blah'); What you have there is a mixture of the two. Link to comment https://forums.phpfreaks.com/topic/40127-warning-array_push-first-argument-should-be-an-array/#findComment-194168 Share on other sites More sharing options...
sford999 Posted February 26, 2007 Author Share Posted February 26, 2007 I changed it like you said $whereParts[] = "species LIKE '%$search_cid%'"; Now the problem is when I echo the query, its not showing the selected items, its showing Array instead. SELECT * FROM fisheries WHERE county = '1' AND species LIKE '%Array%' I`m beginning to think I should`ve gone with checkboxes instead Link to comment https://forums.phpfreaks.com/topic/40127-warning-array_push-first-argument-should-be-an-array/#findComment-194171 Share on other sites More sharing options...
btherl Posted February 26, 2007 Share Posted February 26, 2007 That's because you used the old variable name after imploding: $search = implode(',', $search_cid); array_push($whereParts[], 'species LIKE %$search_cid%'); That $search_cid in the second line should be just $search Link to comment https://forums.phpfreaks.com/topic/40127-warning-array_push-first-argument-should-be-an-array/#findComment-194198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.