Jump to content

Newbie string question (php/mysql)


jennatar

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.