jesushax Posted June 5, 2008 Share Posted June 5, 2008 hi im after creating an if statment that will look up a field value and if a certain selection of words = something then execute code for example FieldAnimal: 'dog''cat''mouse''bird' if ($rs["FieldAnimal"] = dog) {code} but obviously the field doesnt = dog i need a way to find out if the field has dog init any ideas? thanks Link to comment https://forums.phpfreaks.com/topic/108808-solved-if-any-word-in-a-field-something/ Share on other sites More sharing options...
BillyBoB Posted June 5, 2008 Share Posted June 5, 2008 Something like this might work. $fieldanimal = array('dog', 'cat', 'mouse', 'bird'); if(in_array('dog', $fieldanimal)) { // Profit??? } Link to comment https://forums.phpfreaks.com/topic/108808-solved-if-any-word-in-a-field-something/#findComment-558149 Share on other sites More sharing options...
jesushax Posted June 5, 2008 Author Share Posted June 5, 2008 ok heres what i have, it doesnt work though <?php $services = array($rsEdit["ClientServices"]); ?> <table width="50%%" border="0"> <tr> <td>XHTML/CSS Standards Compliant</td> <td><input type="checkbox" name="chkXHTML" value="XHTML/CSS Standards Compliant" class="blank" <?php if(in_array('XHTML/CSS Standards Compliant', $services)) { echo 'checked="checked"'; } ?> /></td> Link to comment https://forums.phpfreaks.com/topic/108808-solved-if-any-word-in-a-field-something/#findComment-558161 Share on other sites More sharing options...
jesushax Posted June 5, 2008 Author Share Posted June 5, 2008 ok soo heres where im at, using your code above as guidelines this should work yes? but it doesnt $str = $rsEdit["ClientServices"]; $str = str_replace(":", "'", "$str"); $str = str_replace("''", "', '", "$str"); $services = array($str); ?> <table width="50%%" border="0"> <tr> <td>XHTML/CSS Standards Compliant</td> <td><input type="checkbox" name="chkXHTML" value="XHTML/CSS Standards Compliant" class="blank" <?php if(in_array('XHTML/CSS Standards Compliant', $services)) {echo 'checked="checked"';} ?> /></td> echoing $str gives 'XHTML/CSS Standards Compliant', 'Webpage Design', 'Form to PDF/Email', 'Corporate Branding' so why it no work? cheers Link to comment https://forums.phpfreaks.com/topic/108808-solved-if-any-word-in-a-field-something/#findComment-558212 Share on other sites More sharing options...
jesushax Posted June 5, 2008 Author Share Posted June 5, 2008 anyone got any ideas why my code isnt working? kinda waiting until this is sorted to move on Cheers Link to comment https://forums.phpfreaks.com/topic/108808-solved-if-any-word-in-a-field-something/#findComment-558270 Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 Ok, I decided to go back to the original question, ignoring all the other posts (so I won't try to use someone else's code), and this is what I came up with to handle the problem stated: <?php function searchForThis($data, $search){ if (strstr($data, $search)){ print "I found $search!"; } else{ print "$search was not found."; } } /* Ok, lets take this function for a test spin: */ $data = "FieldAnimal: 'dog''cat''mouse''bird'"; $search = "mouse"; searchForThis($data, $search); /* Ok, now that we have that result, lets try another */ /* First, lets give us some room.... */ print "<br />\n<br />\n<br />\n"; /* Ok, that's enough room */ $data = "This is a test (this one should fail)"; $search = "cheese"; searchForThis($data, $search); ?> Link to comment https://forums.phpfreaks.com/topic/108808-solved-if-any-word-in-a-field-something/#findComment-558280 Share on other sites More sharing options...
jesushax Posted June 5, 2008 Author Share Posted June 5, 2008 absolute superstar! works a treat thankyou very much Link to comment https://forums.phpfreaks.com/topic/108808-solved-if-any-word-in-a-field-something/#findComment-558303 Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 Glad to be of assistance. Could you mark this thread solved, please? Link to comment https://forums.phpfreaks.com/topic/108808-solved-if-any-word-in-a-field-something/#findComment-558307 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.