HalfNote5 Posted March 6, 2013 Share Posted March 6, 2013 Okay, so I don't use PHP a lot, being a FoxPro programmer. That said, I've got a dbf file I need to access from a web page (done, actually, thanks to the magnificent Erwin Kooi and his PHP Dbase solution.) However, the question I have is purely PHP related. If I have a "Search" box on my website, and the user enters multiple keywords, how can I program it to where, as it trips through the array (resulting from the dbf file), it compares EACH INDIVIDUAL WORD in the string to the "KEYWORDS" element in the array so that it can decide whether or not to print that line. I wouldn't even mind feeding the results into their own temporary array so that arranging the results sould be done easier. I have no idea, however, where to begin as I'm pretty new to PHP. Knowing EXACTLY how to do this sort of thing in another programming language doesn't really help in a DIFFERENT language. ; ) I'd really appreciate a nudge in the right direction. Thanks! -DW Quote Link to comment https://forums.phpfreaks.com/topic/275310-separating-postget-input-of-multiple-keywords-in-single-inputbox/ Share on other sites More sharing options...
Jessica Posted March 6, 2013 Share Posted March 6, 2013 (edited) Explode the string by the spaces. Edit: Wait, you might just use strpos. Can you post some examples? Edited March 6, 2013 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/275310-separating-postget-input-of-multiple-keywords-in-single-inputbox/#findComment-1416907 Share on other sites More sharing options...
HalfNote5 Posted March 6, 2013 Author Share Posted March 6, 2013 (edited) Here's the basic code that shows EVERYTHING in the database (see below). I wouldn't mind using the keywords to dump each individual MATCHING record into its own separate array (which I would then feed to this thing instead of the current $v/$di array) )so that the whole $incrementpass bit where it creates a new table row after every three records still functions correctly. It occurs to me; could I take the 16th line down, which is: foreach ($r as $c=>$v)) and do something like (pardon my syntax, I dunno if this is right) foreach (($r as $c=>$v) where (strpos($string, $v) !== false)) but Instead of $string, I'm guessing I'd have to deal with MULTIPLE $strings in the form of an array? And that's where it gets confusing. In VFP I would dump the keywords to a temp table, trip through it each time it iterated, and dump the results to their own array or temp table, then use that to produce the end result. I wouldn't mind doing that here, I just don't quite know how. _______________________________________________________________ $di = dbase_open("php2/test/dwtest.dbf",0); echo "<table width=\"75%\" border=\"1\" align=\"center\">"; echo "<tr>"; $incrementpass = 9; for ($i=1;$i<dbase_numrecords($di);$i++) { $incrementpass = $i; if (fmod($incrementpass,3) == 1 and $incrementpass >=2) { echo "<tr>"; } ; $r = dbase_get_record_with_names($di,$i+1); echo "<td> <div align=\"center\">"; foreach ($r as $c=>$v) { if ($c == "ITEMNO") { echo "Item Number: $v : " ; } else if ($c == "NAME") { echo "$v : <br> " ; } else if ($c == "PICURL") { $v = rtrim($v) ; echo "<img SRC=\"/betapics/$v\" " ; } else if ($c == "LOCALBUY") { $v = rtrim($v) ; echo "<A HREF=\"$v\" target=\"_blank\">" ; } else if ($c == "ALTTEXT") { echo "alt=\"$v Keywords: " ; } else if ($c == "KEYWORDS") { echo "$v \" " ; } else if ($c == "TITLETEXT") { echo "title=\"$v \"> </A> " ; } else if ($c == "DESC") { echo "$v <br> " ; } else if ($c == "CPBUY") { $v = rtrim($v) ; echo "<A HREF=\"$v\" target=\"_blank\"><IMG SRC=\"/betapics/cpbutn.png\" alt=\"CafePressLink\"></A> : " ; } else if ($c == "RBBUY") { $v = rtrim($v) ; echo "<A HREF=\"$v\" target=\"_blank\"><IMG SRC=\"/betapics/rbbutn.png\" alt=\"RedBubbleLink\"></A> : " ; } else if ($c == "ZAZZBUY") { $v = rtrim($v) ; echo "<A HREF=\"$v\" target=\"_blank\"><IMG SRC=\"/betapics/zazzbutn.png\" alt=\"ZazzleLink\"></A>" ; } else if ($c == "BIGPICURL") { echo "<br> <A HREF=\"$v\">Click Here for Large Picture </A> " ; }; ##echo "<br><br><br>$incrementpass<br><br> $c NAME?=$v CONTENT? WHERE-EDNTD_WENT"; } echo "</div></td>"; if (fmod($i,3)==0 and $i!=0) { echo "</tr>"; } } echo "</table>"; echo "<br>lineitem<br>"; dbase_close($di); EDIT: Yes, I know it's a tad sloppy. ; ) Edited March 6, 2013 by HalfNote5 Quote Link to comment https://forums.phpfreaks.com/topic/275310-separating-postget-input-of-multiple-keywords-in-single-inputbox/#findComment-1416910 Share on other sites More sharing options...
HalfNote5 Posted March 6, 2013 Author Share Posted March 6, 2013 Wait! I've got it! Since $r is an array of its own, I could simply create an array of keywords (dunno how yet), do a nested foreach/as where it DELETES the row in the array (dunno how yet) if none of the keywords show up. Then $r would behave normally, if I did all this BEFORE running $r thrugh the above script. Quote Link to comment https://forums.phpfreaks.com/topic/275310-separating-postget-input-of-multiple-keywords-in-single-inputbox/#findComment-1416911 Share on other sites More sharing options...
Jessica Posted March 6, 2013 Share Posted March 6, 2013 omg no just stop. You don't want to get everything from the database, you just want to get the results which match at least ONE word in the search string right? Quote Link to comment https://forums.phpfreaks.com/topic/275310-separating-postget-input-of-multiple-keywords-in-single-inputbox/#findComment-1416913 Share on other sites More sharing options...
HalfNote5 Posted March 6, 2013 Author Share Posted March 6, 2013 (edited) Yes, precisely. But I should point out that "database" is a misleading term, if I'm strictly supposed to be using PHP parlance. Technically it's a DBF file which is converted into an array. It's NOT a SQL DB. EDIT: I figure since the array already exists, as it's read from the DBF file, then deleting NON-matches might be easier Edited March 6, 2013 by HalfNote5 Quote Link to comment https://forums.phpfreaks.com/topic/275310-separating-postget-input-of-multiple-keywords-in-single-inputbox/#findComment-1416914 Share on other sites More sharing options...
Jessica Posted March 6, 2013 Share Posted March 6, 2013 Okay, I missed that part. Sure, do it that way. Quote Link to comment https://forums.phpfreaks.com/topic/275310-separating-postget-input-of-multiple-keywords-in-single-inputbox/#findComment-1416915 Share on other sites More sharing options...
HalfNote5 Posted March 6, 2013 Author Share Posted March 6, 2013 Which still begs the question; which PHP function/command should I be using to separate my keywords from my search box into a small array (I'll go check out strpos so I'm not completely ignorant of it in the meantime), and also if a nested foreach/as loop is the correct/prefereable way to go about it. Quote Link to comment https://forums.phpfreaks.com/topic/275310-separating-postget-input-of-multiple-keywords-in-single-inputbox/#findComment-1416916 Share on other sites More sharing options...
HalfNote5 Posted March 6, 2013 Author Share Posted March 6, 2013 Actually, you were right the first time. Explode is precisely what I need. Quote Link to comment https://forums.phpfreaks.com/topic/275310-separating-postget-input-of-multiple-keywords-in-single-inputbox/#findComment-1416917 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.