PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
theoph
Forum Commoner
Posts: 47 Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA
Post
by theoph » Thu Sep 11, 2003 9:37 am
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ї]" size="4" multiple id="select">
<option value="" <?php if (!(strcmp("", $row_rsLaosї's_cell']))) {echo "SELECTED";} ?>>-None-</option>
<?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);
}
?>
</select>
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Thu Sep 11, 2003 10:33 am
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).
theoph
Forum Commoner
Posts: 47 Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA
Post
by theoph » Thu Sep 11, 2003 11:48 am
Thanks
I give it a try.
-Dave
theoph
Forum Commoner
Posts: 47 Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA
Post
by theoph » Thu Sep 11, 2003 12:47 pm
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
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Thu Sep 11, 2003 1:09 pm
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>
theoph
Forum Commoner
Posts: 47 Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA
Post
by theoph » Thu Sep 11, 2003 5:16 pm
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
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Fri Sep 12, 2003 2:33 am
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
theoph
Forum Commoner
Posts: 47 Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA
Post
by theoph » Fri Sep 12, 2003 8:36 am
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?
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Sat Sep 13, 2003 7:44 am
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
m3rajk
DevNet Resident
Posts: 1191 Joined: Mon Jun 02, 2003 3:37 pm
Post
by m3rajk » Sat Sep 13, 2003 1:13 pm
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
theoph
Forum Commoner
Posts: 47 Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA
Post
by theoph » Sun Sep 14, 2003 3:33 pm
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
theoph
Forum Commoner
Posts: 47 Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA
Post
by theoph » Fri Oct 03, 2003 9:29 am
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));
?>