Page 1 of 1

Multiple Highlighted List

Posted: Thu Sep 11, 2003 9:37 am
by theoph
I'm having problems getting php to highlight multiple items that have been inserted into a MySQL field. It highlights fine with one entry, but not with more than one. The multiple items are inserted into the field they are seperated by comas.

Any suggestions?

Code: Select all

<select name="s_cells&#1111;]" size="4" multiple id="select">
    <option value="" <?php if (!(strcmp("", $row_rsLaos&#1111;'s_cell']))) &#123;echo "SELECTED";&#125; ?>>-None-</option>
    <?php
do &#123;  
?>
    <option value="<?php echo $row_rsCellmenu&#1111;'name']?>"<?php if (!(strcmp($row_rsCellmenu&#1111;'name'], $row_rsLaos&#1111;'s_cell']))) &#123;echo "SELECTED";&#125; ?>><?php echo $row_rsCellmenu&#1111;'name']?></option>
    <?php
&#125; while ($row_rsCellmenu = mysql_fetch_assoc($rsCellmenu));
  $rows = mysql_num_rows($rsCellmenu);
  if($rows > 0) &#123;
      mysql_data_seek($rsCellmenu, 0);
	  $row_rsCellmenu = mysql_fetch_assoc($rsCellmenu);
  &#125;
?>
        </select>

Posted: Thu Sep 11, 2003 10:33 am
by JAM
Hope you'll understand my point of idea.
When I did this, I used the similarity of the code below:

Code: Select all

while ($row_rsCellmenu = mysql_fetch_assoc($query_result)) {
    $check = (strcmp($row_rsCellmenu['name'], $row_rsLaos['s_cell']) > 0 ' selected' : '');
    echo '<option '.$check.'name="something" value="'.$row_rsCellmenu['name'].'">'.$row_rsCellmenu['name'].'</option>';
}
Tried to rewrite it some to fit your variables. Rewriting it needed.

Here I use the shorter version of if-then-else, assigning $check with either ' SELECTED' or ''.
As I'm using this loop to print the options with the $check embedded, it will automaticly get selected.

Just If it's an option to rewrite it (or someone else doesn't give another answer/example).

Posted: Thu Sep 11, 2003 11:48 am
by theoph
Thanks

I give it a try.

-Dave

Posted: Thu Sep 11, 2003 12:47 pm
by theoph
JAM wrote:

Code: Select all

while ($row_rsCellmenu = mysql_fetch_assoc($query_result)) {
Got a parse error on the above line. Did we need a ";" after the last ")" and before "{"?

When I inserted the ";", I got a parse error on the second line of code.

Code: Select all

<?php
$check = (strcmp($row_rsCellmenu['name'], $row_rsLaos['s_cell']) > 0 'selected':''); 

?>
-Dave

Posted: Thu Sep 11, 2003 1:09 pm
by JAM
No, the usage in the example is correct...

But I meant that you would need to rewrite the code snippet i provided to fit your own. It will not work 'as-is'.

I rewrote it to more look like you own. Some modifications might still be needed.

Code: Select all

<select name="s_cells[]" size="4" multiple id="select"> 
    <option value="" <?php if (!(strcmp("", $row_rsLaos['s_cell']))) {echo "SELECTED";} ?>>-None-</option> 
    <?php 
do {  
    $check = (strcmp($row_rsCellmenu['name'], $row_rsLaos['s_cell']) > 0 ? ' SELECTED' : '');
    echo '<option '.$check.'value="'.$row_rsCellmenu['name'].'">'.$row_rsCellmenu['name'].'</option>';
    <?php 
} while ($row_rsCellmenu = mysql_fetch_assoc($rsCellmenu)); 
?> 
        </select>

Posted: Thu Sep 11, 2003 5:16 pm
by theoph
Still getting a parse error on the row that has the following script:

Code: Select all

$check = (strcmp($row_rsCellmenu['name'], $row_rsLaos['s_cell']) > 0 ? ' SELECTED' : ''); ?>
BTW - Used the whole script you recommended to me.

-Dave

Posted: Fri Sep 12, 2003 2:33 am
by twigletmac
There's a parenthsis missing:

Code: Select all

(strcmp($row_rsCellmenu['name'], $row_rsLaos['s_cell'])
should be

Code: Select all

(strcmp($row_rsCellmenu['name'], $row_rsLaos['s_cell']))
Mac

Posted: Fri Sep 12, 2003 8:36 am
by theoph
Still getting a parse error on the following line of code:

Code: Select all

$check = (strcmp ($row_rsCellmenu['name'], $row_rsLaos['s_cell']))> 0 ?'SELECTED':'';
Any suggestions?

Posted: Sat Sep 13, 2003 7:44 am
by twigletmac
Oops, my bad, I didn't copy all the code - it should be:

Code: Select all

$check = (strcmp ($row_rsCellmenu['name'], $row_rsLaos['s_cell']) > 0) ? 'SELECTED' : '';
Mac

Posted: Sat Sep 13, 2003 1:13 pm
by m3rajk
twigletmac wrote:There's a parenthsis missing:

Code: Select all

(strcmp($row_rsCellmenu['name'], $row_rsLaos['s_cell'])
should be

Code: Select all

(strcmp($row_rsCellmenu['name'], $row_rsLaos['s_cell']))
Mac
that's what i LOVE about (x)emacs. the parenthesis matching is a lifesaver at times... specially when using scheme or lisp

Posted: Sun Sep 14, 2003 3:33 pm
by theoph
All parse errors have been fixed and the page now displays with no problems. However, no items are being highted in the Multiple List Box. Even when there is only one item to be hightlighted. The following is the code Dreamweaver MX 2004 generates. It highlights find with one item but not with there is multiple items in a field seperated with comas.

<?php
do {
?>
<option value="<?php echo $row_rsCellmenu['name']?>"<?php if (!(strcmp($row_rsCellmenu['name'], $row_rsLaos['s_cell']))) {echo "SELECTED";} ?>><?php echo $row_rsCellmenu['name']?></option>

<?php
} while ($row_rsCellmenu = mysql_fetch_assoc($rsCellmenu));
$rows = mysql_num_rows($rsCellmenu);
if($rows > 0) {
mysql_data_seek($rsCellmenu, 0);
$row_rsCellmenu = mysql_fetch_assoc($rsCellmenu);
}
?>

Any thing here that would help us getting multiple items in a List Box to highlight?

-Dave

Workable Code

Posted: Fri Oct 03, 2003 9:29 am
by theoph
This is the code that finially worked for me. Thanks to all that helped and pointed me into the right direction.

Code: Select all

<?php 
			do {
				if(strpos($row_rsLaos['s_cell'],$row_rsCellmenu['name'])!==FALSE)
				{
					$check = 'SELECTED';
				}
				else
				{
					$check = '';
				}
				echo '<option value="'.$row_rsCellmenu['name'].'" '.$check.'>'.$row_rsCellmenu['name'].'</option>';
			}
			while ($row_rsCellmenu = mysql_fetch_assoc($rsCellmenu));
?>