content from DB into dropdown menu (content has quotes)

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

Post Reply
grudz
Forum Commoner
Posts: 68
Joined: Thu Dec 04, 2003 12:52 pm

content from DB into dropdown menu (content has quotes)

Post by grudz »

Hi,

Basically my subject askes the question...the problem isn't with how to do have content from a DB into a drop down menu, but it's when the content from the DB has quotes, that's when it value doesn't show everything.

here's my code

Code: Select all

PHP Code:
<select name="icons[]" size="10" multiple id="icons[]" 
        <option value=""></option> 
        <?php 
do {   
?> 
        <option value="<?php $value = stripslashes($value); echo $value?>"><?php echo $row_icons['icon']?></option> 
        <?php 
} while ($row_icons = mysql_fetch_assoc($icons)); 
  $rows = mysql_num_rows($icons); 
  if($rows > 0) { 
      mysql_data_seek($icons, 0); 
      $row_icons = mysql_fetch_assoc($icons); 
  } 
?> 

      </select>

Now i'm pretty sure i can change the stripslashes to something else, but i don't what will make it work...i've tried addslashes, and htmlentities....

Thank you
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

try str_replace ... find details on php.net
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It is hard to tell from your code because it does not show where $value is assigned. I would think you would use addslashes() to put it between quotes.
(#10850)
grudz
Forum Commoner
Posts: 68
Joined: Thu Dec 04, 2003 12:52 pm

Post by grudz »

ok....an example of the $value in my DB is this:

<a href="images/popup_5a7.png" onclick="popImg(this.href); return false;"><img src="images/legend_5a7.gif" border="0" alt="5 a 7"></a>

would that help?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

its not valid html to put html inside of a select or option element, just cant do that

you could do this though:

Code: Select all

$value = htmlspecialchars($value);
<option value="<?php echo $value; ?>"><?php echo $value; ?></option>
Post Reply