Jump to content

Remove option if detect string match


Sigmahokies
 Share

Recommended Posts

Hello everyone

I'm trying to remove a html tag option when detect string to match. For example, if string show "Apple" in produce list that is not available, so, remove this option. I tried to grey it out, seem it doesn't work very good.

my code:

$disable = "<option disable>String</option>";

$picktable = $GaryDB->prepare("SHOW TABLES");

$picktable->execute();

while($row6 = $picktable->fetch()) {
if($row6[0] == "String") {
$row6[0] = str_replace("<option>String</option>",$disable,"<option>String</option>");
}
$pick .= "<option value='$row6[0]'>".$row6[0]."</option>";
}

unless you have better logic to remove or grey it out...

Thank you

Gary

Edited by Sigmahokies
Link to comment
Share on other sites

You can use 'continue' keyword within if condition to skip that row value completely removing need to replace. If you plan to replace apply row value to a new variable and manipulate that! Insread.

$pick .= "<option value='$row6[0]'>".$row6[0]."</option>";

Should be

$pick .= "<option value='"$row6[0]"'>".$row6[0]."</option>";

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...