JTapp Posted May 25, 2010 Share Posted May 25, 2010 I'm struggling with a % wildcard. Specifically.. the line item that has "City Lodge is Located In".. is not reporting "Oklahoma City" if the person types "Oklahoma". Can anybody help me with a quick fix on wildcard functionality? <select name="metode" size="6"> <option value="tblLodges.strLodgeName" selected>Name of Lodge</option> <option value="tblLodges.intLodgeNumber">Lodge Number</option> <option value="tblLodges.intDistrictID">District Lodge Is In</option> <option value="tblLodges.strLodgeLocationCity">City Lodge Is Located In</option> <option value="tblLodges.strLodgeLocationZIP">Zip Code of Lodge Location</option> <option value="tblLodges.strLodgeCounty">Lodge County</option> Quote Link to comment https://forums.phpfreaks.com/topic/202877--/ Share on other sites More sharing options...
kenrbnsn Posted May 25, 2010 Share Posted May 25, 2010 The code snippet you posted doesn't seem to relate to your question. Please post more code. Ken Quote Link to comment https://forums.phpfreaks.com/topic/202877--/#findComment-1063202 Share on other sites More sharing options...
JTapp Posted May 25, 2010 Author Share Posted May 25, 2010 The code snippet you posted doesn't seem to relate to your question. Please post more code. Ken Hey Ken: <form name="form1" method ="post" action="http://www.gloklahoma.com/lodgelocator/3results.php" target="_blank"> <table width="849" border="0" align="center"> <tr> <th width="812" bgcolor="#fff" class="form_1" scope="col"> <p class="style1"><img src="../images/lodgelocator.jpg" width="478" height="176"></p> <p class="style1"><img src="../images/line.gif" width="327" height="23"></p> <p class="text_1"><a href="9results.php">Click Here For A List Of Lodges</a></p> <p class="style1"> <select name="metode" size="6"> <option value="tblLodges.strLodgeName" selected>Name of Lodge</option> <option value="tblLodges.intLodgeNumber">Lodge Number</option> <option value="tblLodges.intDistrictID">District Lodge Is In</option> <option value="tblLodges.%strLodgeLocationCity">City Lodge Is Located In</option> <option value="tblLodges.strLodgeLocationZIP">Zip Code of Lodge Location</option> <option value="tblLodges.strLodgeCounty">Lodge County</option> </select> <span class="text_1">Search Value:</span><span class="copy_1"> <input name="search" type="text" class="form" size="25"> </span> </p> <p class="style1"> <input type="submit" value="Click Here To Search Our Lodge Locator!!" name="GOTWO2"> </p> <p class="style1"> </p> <p class="style1"> </p></th> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/202877--/#findComment-1063206 Share on other sites More sharing options...
kenrbnsn Posted May 25, 2010 Share Posted May 25, 2010 What you have posted is not PHP, it's straight HTML. Please post the code that processes the form between tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/202877--/#findComment-1063227 Share on other sites More sharing options...
JTapp Posted May 25, 2010 Author Share Posted May 25, 2010 <?php $username = "***********"; $password = "***********"; $hostname = "**********; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("*******",$dbhandle) or die("Could not select ******"); $id = $_GET['id']; $query = mysql_query("SELECT a.strLodgeName, a.intLodgeNumber, a.intDistrictID, a.strLodgeWEB, a.strLodgeCounty, a.dtChartered, a.strLodgeMeetingPlace, a.strLodgeLocationCity, a.strLodgeLocationState, a.strLodgeLocationZIP, a.strLodgeEmail, a.strLodgePhone, a.strLodgeFax, a.strDrivingDirectons, a.dtMeetingTime, a.strMeetingCodes, a.dtMealTime, a.strFloorSchool, a.strLodgeNews, a.strLodgePhotoPathAndName, b.strOfficerTitle, b.strFirstName, b.strLastName, b.BusinessPhone, b.PersEmail FROM tblLodges a LEFT JOIN tblOfficers b ON a.lngLodgeID = b.lngLodgeID WHERE a.intLodgeNumber=$id GROUP BY a.strLodgeName LIMIT 50")or die(mysql_error()); while ($row = @mysql_fetch_array($query)) { $variable1=$row["strLodgeName"]; $variable2=$row["intLodgeNumber"]; $variable3=$row["intDistrictID"]; $variable4=$row["strLodgeWEB"]; $variable5=$row["strLodgeCounty"]; $variable6=$row["dtChartered"]; $variable7=$row["strLodgeMeetingPlace"]; $variable8=$row["strLodgeLocationCity"]; $variable9=$row["strLodgeLocationState"]; $variable10=$row["strLodgeLocationZIP"]; $variable12=$row["strLodgeEmail"]; $variable13=$row["strLodgePhone"]; $variable14=$row["strLodgeFax"]; $variable15=$row["strDrivingDirectons"]; $variable16=$row["dtMeetingTime"]; $variable17=$row["dtMealTime"]; $variable18=$row["strFloorSchool"]; $variable19=$row["strLodgeNews"]; $variable20=$row["strLodgePhotoPathAndName"]; $variable21=$row["strMeetingCodes"]; $imagesFolder = '/lodgeimages/'; //table layout for results echo "<center>\n"; echo "<p><H2>Name of Lodge: $variable1</H2></p>"; if (file_exists($_SERVER['DOCUMENT_ROOT'].$imagesFolder.$row['intLodgeNumber'].".jpg")) { echo "<img src='" . $imagesFolder . $row['intLodgeNumber'] . ".jpg' /></p>"; } else { //just because it was on the end of your line... echo the </p> if no image echo "</p>"; } $file = $imagesFolder . $row['intLodgeNumber'] . '.jpg'; if (file_exists($file)){ echo "<img src='" . $imagesFolder . $row['intLodgeNumber'] . ".jpg' /></p>"; } else { echo "<img src='/Images/footerbar.GIF' /></p>"; } echo "<p><H2>Lodge Number: $variable2</H2></p>"; echo "<p><H2>District:</b> $variable3</p>"; echo ($variable4 != '') ? "<a href=\"$variable4\">Click Here To Go To The Lodge Website</a>" : ''; echo "<p><H2>Lodge County: $variable5</H2></p>"; echo "<p><H2>Lodge Chartered On: $variable6</H2></p>"; echo "<p><H2>Lodge Address: $variable7</H2></p>"; echo "<p><H2>$variable8 $variable9, $variable10</H2></p>"; echo ($variable12 != '') ? "<a href=\"mailto:$variable12\">Click Here To Email The Lodge</a>" : ''; echo "<p><H2>Lodge Phone Number: $variable13</H2></p>"; echo ($variable14 != '') ? "<p><H2>Lodge FAX Number: $variable14</H2></p>" : ''; echo "<p><H2>Lodge Driving Directions:</b><a href='http://maps.google.com/maps?saddr=&daddr=".$variable7.", ".$variable8.", ".$variable9."' target='_blank'>Link</a></p>"; echo ($variable21 != '') ? "<p><H2>Lodge Meetings: $variable21</H2></p>" : ''; echo ($variable16 != '') ? "<p><H2>Meeting Time: $variable16</H2></p>" : ''; echo ($variable17 != '') ? "<p><H2>Meal Time: $variable17</H2></p>" : ''; echo ($variable18 != '') ? "<p><H2>Lodge Floor School: $variable18</H2></p>" : ''; echo ($variable19 != '') ? "<p><H2>Lodge News: $variable19</H2></p>" : ''; echo "</center>\n"; } ?> </p> <hr> <p> <?php //query details table begins $query = mysql_query("SELECT tblLodges.strLodgeName, tblLodges.intLodgeNumber, tblLodges.intDistrictID, tblLodges.strLodgeLocationCity, tblLodges.strLodgeLocationZIP, tblLodges.strLodgeCounty, tblOfficers.lngLodgeID, tblOfficers.strOfficerTitle, tblOfficers.strFirstName, tblOfficers.strLastName, tblOfficers.BusinessPhone, tblOfficers.PersEmail FROM tblLodges LEFT JOIN tblOfficers ON tblLodges.lngLodgeID = tblOfficers.lngLodgeID WHERE tblLodges.intLodgeNumber=$id GROUP BY tblOfficers.lngOfficerTitleID LIMIT 0, 50")or die(mysql_error()); echo "<center>\n"; echo "<H2>Roster of Lodge Officers</H2>\n"; echo "<table border='1'> <tr> <th>Lodge Number</th> <th>Officer Title</th> <th>Officer First</th> <th>Officer Last</th> <th>Officer Email</th> <th>Officer Phone</th> </tr>"; if (mysql_num_rows($query)) { while ($row = mysql_fetch_array($query)) { $variable1=$row["intLodgeNumber"]; $variable2=$row["strOfficerTitle"]; $variable3=$row["strFirstName"]; $variable4=$row["strLastName"]; $variable5=$row["PersEmail"]; $variable6=$row["BusinessPhone"]; //table layout for results print("<tr>"); echo "<tr align=\"center\" bgcolor=\"#EFEFEF\">\n"; echo "<td class=\"td_id\">$variable1</td>\n"; echo "<td class=\"td_id\">$variable2</td>\n"; echo "<td class=\"td_id\">$variable3</td>\n"; echo "<td class=\"td_id\">$variable4</td>\n"; echo "<td class='td_id'><a href='mailto:". $variable5. "'>". $variable5. "</a></td>\n"; echo "<td class=\"td_id\">$variable6</td>\n"; print("</tr>"); } } ?> <p> </p> Quote Link to comment https://forums.phpfreaks.com/topic/202877--/#findComment-1063231 Share on other sites More sharing options...
kenrbnsn Posted May 25, 2010 Share Posted May 25, 2010 The code you posted doesn't seem to be the code that processes the form. Please post the code for 3results.php. Ken Quote Link to comment https://forums.phpfreaks.com/topic/202877--/#findComment-1063235 Share on other sites More sharing options...
JTapp Posted May 25, 2010 Author Share Posted May 25, 2010 Thanks <table border="1" align="center" cellpadding="4" cellspacing="0"> <tr> <td colspan="5" bgcolor="#CD7427" height="18"><center spry:hover="headerintable"> <strong> Search Results</strong> </center></td> </tr> <tr> <td width="13%" height="18" align="center" bgcolor="#ffffff"><center> Lodge ID Number </center></td> <td width="19%" height="18" align="center" bgcolor="#ffffff"><center> Lodge Name </center></td> <td width="20%" align="center" bgcolor="#ffffff"> Click Button To View <strong>Lodge Details </strong></td> <td width="18%" height="18" align="center" bgcolor="#ffffff"><center> City </center></td> <td width="10%" height="18" align="center" bgcolor="#ffffff"><center> District Number </center></td> </tr> <?php $username = "*******"; $password = "******"; $hostname = "**********"; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("********",$dbhandle) or die("Could not select **********"); $metode = mysql_real_escape_string($_POST['metode']); $search = mysql_real_escape_string($_POST['search']); $sql = "SELECT strLodgeName, intLodgeNumber, intDistrictID, strLodgeLocationCity FROM tblLodges WHERE TRIM(LEADING '0' FROM $metode) = '$search' GROUP BY strLodgeName LIMIT 50"; if ($results = mysql_query($sql)) { if (mysql_num_rows($results)) { while ($row = mysql_fetch_assoc($results)) { echo "<tr bgcolor=\"#dddddd\"><td><center>"; echo $row["intLodgeNumber"]; echo "</center></td><td><center>"; echo $row["strLodgeName"]; echo "</center></td><td><center><span class=\"style2\">"; echo "<input name=\"submit\" type=\"button\" value=\"Lodge Details\" onclick=\"javascript:window.location='http://www.gloklahoma.com/lodgelocator/3view.php?id="; echo $row["intLodgeNumber"]; echo "'\" /></center></td>"; echo "</center></td><td><center>"; echo $row["strLodgeLocationCity"]; echo "</center></td><td><center>"; echo ltrim($row["intDistrictID"], '0'); } } else { echo "No records found"; } } else { echo "Query failed<br >" . mysql_error() . "<br>$sql"; }?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/202877--/#findComment-1063236 Share on other sites More sharing options...
kenrbnsn Posted May 25, 2010 Share Posted May 25, 2010 Exposing MySQL table structure in HTML is really not a good idea. I would change the select box in the form to something like this: <select name="metode" size="6"> <option value="0" selected>Name of Lodge</option> <option value="1">Lodge Number</option> <option value="2">District Lodge Is In</option> <option value="3">City Lodge Is Located In</option> <option value="4">Zip Code of Lodge Location</option> <option value="5">Lodge County</option> </select> And then do this in the php script: <?php $search_fields = array('strLodgeName','intLodgeNumber','intDistrictID','strLodgeLocationCity','strLodgeLocationZIP','strLodgeCounty'); $metode = (isset($_POST['metode']) && $_POST['metode'] > -1 && $_POST['medode']) < count($search_fields))?$search_fields[$_POST['metode']]:$search_fields[0]; $sql = "SELECT strLodgeName, intLodgeNumber, intDistrictID, strLodgeLocationCity FROM tblLodges WHERE $metode like '%$search%' GROUP BY strLodgeName LIMIT 50"; ?> BTW, the "like" clause is what you were missing. Also, since you're only searching one table, you don't need the tablename in the where clause. Ken Quote Link to comment https://forums.phpfreaks.com/topic/202877--/#findComment-1063246 Share on other sites More sharing options...
jcbones Posted May 25, 2010 Share Posted May 25, 2010 De-bugged for Ken's big fingers //removed a nasty parentheses that would cause a syntax error. $metode = (isset($_POST['metode']) && $_POST['metode'] > -1 && $_POST['medode'] < count($search_fields))?$search_fields[$_POST['metode']]:$search_fields[0]; Quote Link to comment https://forums.phpfreaks.com/topic/202877--/#findComment-1063307 Share on other sites More sharing options...
kenrbnsn Posted May 26, 2010 Share Posted May 26, 2010 Sorry ... that's what I get for re-thinking my answer as I'm typing it... :-) Thanks, Ken Quote Link to comment https://forums.phpfreaks.com/topic/202877--/#findComment-1063353 Share on other sites More sharing options...
JTapp Posted May 26, 2010 Author Share Posted May 26, 2010 Thanks guys.. all fixed. Appreciate your time! Quote Link to comment https://forums.phpfreaks.com/topic/202877--/#findComment-1063372 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.