Jump to content

Comparing Strings


ihsreal

Recommended Posts

This code compares a drop down list with the users selections as stored in their property(house) data record. The problem I'm having is that when 2 or more descriptive fields begin with the same string, they are all selected even if only one of the selections are in the database (i.e. with the choices 'brick', 'brick and frame', 'brick siding' choosing just 'brick siding' also selects 'brick' when the page is loaded). How would I change this so that only 'brick siding' is selected in the example.

 

<select name="extConst[]" size="5" multiple="multiple" id="extConst[]">

<option value=""  >Make Selection(s)</option>

<?php do {  ?>

<option value="<?php echo $row_rsExtConst['extConstDesc']?>"<?php if ((strpos( $row_rsProperty['extConst_prp'],$row_rsExtConst['extConstDesc']))!==false) {echo "SELECTED";} ?>><?php echo $row_rsExtConst['extConstDesc']?></option>

<?php

} while ($row_rsExtConst = mysql_fetch_assoc($rsExtConst));

$rows = mysql_num_rows($rsExtConst);

if($rows > 0) {

mysql_data_seek($rsExtConst, 0);

$row_rsExtConst = mysql_fetch_assoc($rsExtConst);

  }

?>

</select>

 

Thanks for any help here.

 

Link to comment
https://forums.phpfreaks.com/topic/39428-comparing-strings/
Share on other sites

If you give each $row_rsExtConst['$k'], a separate id Key possibly in a 3D array, then you can post that id number with value="<?php echo $row_rsExtConst['extConstDesc'][0]?>" Which will return the unique id number so the script doesn't get confused.  Hope that makes sense ;)

Link to comment
https://forums.phpfreaks.com/topic/39428-comparing-strings/#findComment-190366
Share on other sites

Thanks, that does make sense, but I don't know how to do it.  :(

 

Here's what I did to solve the problem. I changed the name of the 'brick' to 'brick - all' and now it works correctly. I would have liked to find a solution that would compare the strings and selects only the selections where the entire string matched. Whatever works I guess.

Link to comment
https://forums.phpfreaks.com/topic/39428-comparing-strings/#findComment-190584
Share on other sites

  • 1 year later...

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.