MySQLi Query Builder only returning one match when other matches are available + how to add an "any" option
I have an events search facility with two search options - Type of Event and Keyword.
Type of Event is database driven and I'm checking for events that have a specific ID when searched. Keyword is obvious enough.
This is my search form:
<form class="form-horizontal" name="searcheventsFORM" id="searcheventsFORM" method="post" action="traditional-music-events-search.php">
<div class="form-group">
<label for="searchTYPE" class="col-sm-4 control-label">Type of Event:</label>
<div class="col-sm-8">
<select id="searchTYPE" name="searchTYPE" class="form-control" tabindex="1">
<option value="">Any</option>
<?php
while(!$rsEVENTTYPE->atEnd()) {
?>
<option value="<?php echo($rsEVENTTYPE->getColumnVal("tmsaeventtypeID")); ?>"><?php echo($rsEVENTTYPE->getColumnVal("tmsaeventtype")); ?></option>
<?php
$rsEVENTTYPE->moveNext();
}
$rsEVENTTYPE->moveFirst(); //return RS to first record
?>
</select>
</div>
</div>
<div class="form-group">
<label for="searchKEYWORD" class="col-sm-4 control-label">Search:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="searchKEYWORD" name="searchKEYWORD" placeholder="Keyword/s, town/city, region..." maxlength="100" tabindex="2">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<button type="submit" class="btn btn-default" name="searcheventsBTN" tabindex="3"><span class="glyphicon glyphicon-search"></span> Search</button>
</div>
</div><!-- end form-group -->
</form>
This is my MySQLi Query Builder recordset:
<?php
$rsEVENTS = new WA_MySQLi_RS("rsEVENTS",$csdbmysqli,0);
$rsEVENTS->setQuery("SELECT TMSAevent.tmsaeventID, TMSAevent.tmsaeventtypeID, TMSAevent.tmsaevent, TMSAevent.tmsastartdate, TMSAevent.tmsaenddate, TMSAevent.tmsavenueID, TMSAevent.tmsaeventsummary, TMSAevent.tmsaeventdesc, TMSAevent.tmsaeventDELETE, TMSAevent.tmsaeventPHONE, TMSAevent.tmsaeventEMAIL, TMSAevent.tmsaeventWEB, TMSAvenues.tmsavenuename, TMSAvenues.tmsaorgname, TMSAvenues.tmsavenuecontactname, TMSAvenues.tmsavenueaddress, TMSAvenues.tmsavenuetown, TMSAvenues.tmsavenuepostcode, TMSAcountry.tmsacountry, TMSAregions.tmsaregion FROM TMSAevent INNER JOIN TMSAvenues ON TMSAevent.tmsavenueID = TMSAvenues.tmsavenueID INNER JOIN TMSAcountry ON TMSAvenues.tmsacountryID = TMSAcountry.tmsacountryID INNER JOIN TMSAregions ON TMSAvenues.tmsaregionID = TMSAregions.tmsaregionID WHERE TMSAevent.tmsaeventtypeID = ? AND TMSAevent.tmsastartdate >= ? AND (TMSAevent.tmsaevent LIKE ? OR TMSAevent.tmsaeventsummary LIKE ? OR TMSAevent.tmsaeventdesc LIKE ? OR TMSAvenues.tmsavenuename LIKE ? OR TMSAvenues.tmsaorgname LIKE ? OR TMSAvenues.tmsavenuecontactname LIKE ? OR TMSAvenues.tmsavenueaddress LIKE ? OR TMSAvenues.tmsavenuetown LIKE ? OR TMSAregions.tmsaregion LIKE ? OR TMSAcountry.tmsacountry LIKE ?)");
$rsEVENTS->bindParam("i", "".(isset($_POST['searchTYPE'])?$_POST['searchTYPE']:"") ."", "-1"); //WAQB_Param1
$rsEVENTS->bindParam("t", "".(isset($_SESSION['todaySESH'])?$_SESSION['todaySESH']:"") ."", "-1"); //WAQB_Param2
$rsEVENTS->bindParam("c", "".(isset($_POST['searchKEYWORD'])?$_POST['searchKEYWORD']:"") ."", "-1"); //WAQB_Param3
$rsEVENTS->bindParam("c", "".(isset($_POST['searchKEYWORD'])?$_POST['searchKEYWORD']:"") ."", "-1"); //WAQB_Param4
$rsEVENTS->bindParam("c", "".(isset($_POST['searchKEYWORD'])?$_POST['searchKEYWORD']:"") ."", "-1"); //WAQB_Param5
$rsEVENTS->bindParam("c", "".(isset($_POST['searchKEYWORD'])?$_POST['searchKEYWORD']:"") ."", "-1"); //WAQB_Param6
$rsEVENTS->bindParam("c", "".(isset($_POST['searchKEYWORD'])?$_POST['searchKEYWORD']:"") ."", "-1"); //WAQB_Param7
$rsEVENTS->bindParam("c", "".(isset($_POST['searchKEYWORD'])?$_POST['searchKEYWORD']:"") ."", "-1"); //WAQB_Param8
$rsEVENTS->bindParam("c", "".(isset($_POST['searchKEYWORD'])?$_POST['searchKEYWORD']:"") ."", "-1"); //WAQB_Param9
$rsEVENTS->bindParam("c", "".(isset($_POST['searchKEYWORD'])?$_POST['searchKEYWORD']:"") ."", "-1"); //WAQB_Param10
$rsEVENTS->bindParam("c", "".(isset($_POST['searchKEYWORD'])?$_POST['searchKEYWORD']:"") ."", "-1"); //WAQB_Param11
$rsEVENTS->bindParam("c", "".(isset($_POST['searchKEYWORD'])?$_POST['searchKEYWORD']:"") ."", "-1"); //WAQB_Param12
$rsEVENTS->execute();
?>
You can try this out here...
http://www.nathonjoneswebdesign.co.uk/tmsa/traditional-music-events-Scotland.php
Here are the problems with it...
1. When I select "Any" as the Type of Event, and leave the Keyword field blank no results are returned. This should return all of the events.
2. When I select a Type of Event, for example "Festival", and leave the keyword field blank only one result is returned yet there is more than one Festival event in the database.
3. If I select "Festival" as the Type of Event and type the Keyword "Newton" I am shown a festival event that doesn't appear in the search in step 2 above?
Something is clearly wrong with the MySQLi Query Builder or, more likely, my understanding of how this should work. Either way I'd appreciate some help resolving it as it's pretty useless in its current format.
Appreciate it. Thank you.
NJ