?
Solved

Customize mysql values in select box

Posted on 2011-10-25
11
Medium Priority
?
283 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:abolinhas
9 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 37023957
When you create strings in PHP that contain the quote delimiter, you must escape the quote delimiter with a backslash.
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 2000 total points
ID: 37023971
This is kind of a guess since I do not have your test data, but maybe...
INSTEAD OF THIS:
<option value='<?php echo '"drc='.$row['drc'].'"'?>'><?php echo '$row['dico']' ?></option>

TRY THIS:
<option value="<?php echo "drc={$row["drc"]}"; ?>"> <?php echo $row['dico']; ?></option>

Open in new window

0
 
LVL 36

Expert Comment

by:Norie
ID: 37023997
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:amigura
ID: 37024024
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

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37024101
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
0
 
LVL 9

Author Comment

by:abolinhas
ID: 37049969
Thanks, this tip solve my problem.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37050000
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.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37050014
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

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37050373
Correct answers are posted at http:#37023957 and http:#37023971
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question