Jump to content

[SOLVED] if description does not contain the following words


Recommended Posts

Hello everyone,

 

I am parsing a MS Excel (.xls) file and adding it's content to a mySQL database, so far to good, but what I want to do is if the column titled description does not contain these words "seedlings" or "discount" then add it to the database but if it does skip it and keep looping.

 

Here is my code that I am trying to get working:

if((!empty($description))or($available >0)and(!preg_match("/seedlings/i", $description))):
  mysql_query("INSERT INTO `availability` VALUES ('','$description','$available','$price')");
endif;

 

I may not be using the right function for this "preg_match"?

preg_match is a little over kill for this,

i would use stripos

for example (untested)

// if description is not empty and available is greater than 0 and description does not contain seedlings or discount
if(!empty($description) && $available >0 && stripos($description, 'seedlings') === false && stripos($description, 'discount') === false){
  mysql_query("INSERT INTO `availability` VALUES ('','$description','$available','$price')");
}

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.