jennatar Posted March 1, 2008 Share Posted March 1, 2008 Hiya. I'm new here, and new to php altogether. I'm just looking to make my pure HTML website more dynamic and easier to update, and picking up the basic php/mySQL to do that doesn't seem too bad. I'm here with my first (of undoubtedly many) hiccups: This is a search of sorts. I need to see if a string ($var) is contained within a field in my database, and return only those database entries where it is. Is there a way to include this in the WHERE portion of the mysql_query? ex: $var = 'string' $search = mysql_query("SELECT * FROM table1 WHERE stripos(field1, $var) != FALSE ORDER BY title"); ...I know that doesn't work, but that's what I'm going for: return a mysql query containing only those rows where field1 contains $var. If it can't be done, is there a way to incorporate it into a mysql_fetch_array? Like... while($row = mysql_fetch_array($search) && stripos(row['field1'], $var) != FALSE) ...again, I know that doesn't work. Or is there a better way to do it than stripos? Any help on this would be appreciated, and thanks for putting up with my lack of knowing anything. Link to comment https://forums.phpfreaks.com/topic/93799-newbie-string-question-phpmysql/ Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 $var = 'string' $sql ="SELECT * FROM table1 WHERE field1 LIKE '%$var%'"; Link to comment https://forums.phpfreaks.com/topic/93799-newbie-string-question-phpmysql/#findComment-480635 Share on other sites More sharing options...
jennatar Posted March 1, 2008 Author Share Posted March 1, 2008 ...man, I feel pathetic. Thanks. I think I need to find more lists of operators and things. Sorry about that. Link to comment https://forums.phpfreaks.com/topic/93799-newbie-string-question-phpmysql/#findComment-480642 Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 Remember that sql is not php. The mysql manual is a great resource. Link to comment https://forums.phpfreaks.com/topic/93799-newbie-string-question-phpmysql/#findComment-480654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.