Link to home
Start Free TrialLog in
Avatar of abolinhas
abolinhasFlag for Portugal

asked on

Customize mysql values in select box

Dear Experts,

I want to customize the mysql values of my select box for this:
"drc='row'" - (include "" and ')

Open in new window


I already have this query
 
<option value='<?php echo '"drc='.$row['drc'].'"'?>'><?php echo '$row['dico']' ?></option>

Open in new window


And the result are
 
"drc=row" - (missing the ' in row)

Open in new window


Can you help me ?

Best regards

André Bolinhas
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norie
Norie

André

Escape the single quote you want to add with /.

Not 100% sure of the syntax you'll need but it would be something like this.

<option value='<?php echo '"drc=/''.$row['drc'].'/'"'?>'><?php echo '$row['dico']' ?></option>

I've tried to highlight what i added  in bold but not sure if it's clear.

You could also try using chr(39).

Finally you could use CHAR and CONCAT in the MySQl query to return the value plus quotes instead of just the value:

CONCAT(CHAR(39), drc, CHAR(39))

If any of those work I'd probably go for the last one.
do not understand why you have drc= in value varible


<option value=drc="'<?php echo $row['drc']; ?>"><?php echo $row['dico']; ?></option>

or

echo "<option value=drc=\"{$row['drc']}\">{$row['dico']}</option>";

Open in new window

Assuming this is part of a <select><option> HTML string, can you please show us a representation of what you want for the end product?  The more I look at this, the less it makes sense to me.  Thanks, ~Ray
Avatar of abolinhas

ASKER

Thanks, this tip solve my problem.
The accepted solution cannot possibly solve the problem because it creates a PHP parse error.  I will ask a moderator to reopen the question.  A tested and working answer was posted at ID:37023971.
Copied and pasted from the accepted "solution"...
http://www.laprbass.com/RAY_temp_abolinhas.php
 Outputs:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/websitet/public_html/RAY_temp_abolinhas.php on line 5

It is always a good idea to test the solutions posted by the experts here at EE.  I test my code before I post it, but as you can see here not everyone takes the time and effort to prepare a test.  And unfortunately you do not have any way of knowing whether the proposed solutions are any good unless you test them yourself.  Caveat Emptor.

Best of luck with your project, ~Ray
<?php // RAY_temp_abolinhas.php

// DROP INTO HTML AND TEST THE ACCEPTED SOLUTION
?>
<option value='<?php echo '"drc=/''.$row['drc'].'/'"'?>'><?php echo '$row['dico']' ?></option>

Open in new window

Correct answers are posted at http:#37023957 and http:#37023971