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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.