Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8454311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:59:35+00:00 2026-06-10T11:59:35+00:00

I need a combine some php and html tricks to make a typical select

  • 0

I need a combine some php and html tricks to make a typical select option segment of a form hold multiple values for each form. An id for the product, the id for the markup, and the “name” of the markup. This allows administrative users to select prices for products based on profit margins. Submitting the form yields blank values for the three values inside the select.

<?php

    $factor_grab = "
    SELECT * FROM product_latest_price_factor AS t1
    WHERE product_id = '".$product_id."'";
    //echo $factor_grab.'<br>';
    $factor_result = mysql_query($factor_grab) or die (mysql_error());
    while($frow=mysql_fetch_array($factor_result))
    {
        $level = $frow['level'];
        $percentage = $frow['percentage'];
        $value = $frow['value'];
        $price_level_id = $frow['price_level_id'];

//This piece does not work
        echo '<option value="{level:\''.$level.'\', price_level_id:\''.$price_level_id.'\', percentage:\''.$percentage.'\'}">'.$level.' - %'.number_format($percentage,2).' - $'.$value.'</option>';

    }
      ?>

I thought I nailed it this time, as I can see the values in the form, and by inspecting the options with Google Chrome, but I think it’s because my quotes are getting out of hand. You can see each option value is supposed to store three variables. Level, Price_level and Price_level_id. (Value is just for users to explicitly see what the resulting price would be.) How do I echo out an option that can work for all three? That would be a very powerful solution for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:59:37+00:00Added an answer on June 10, 2026 at 11:59 am

    Properly escape things, and avoid issues:

    echo '<option value="', 
        htmlspecialchars(
            json_encode(
                array(
                    'level'=>$level,
                    'price_level_id'=>$price_level_id,
                    'percentage'=>$percentage
                )
            )
        ),
        '">',
        htmlspecialchars($level . ' - %' . number_format($percentage,2)),
        htmlspecialchars(' - $' . $value),
        '</option>';
    

    This is messy… only trying to show you the idea here. You should clean this stuff up a bit. It would be best if you only kept an ID in that option value, and pulled these other things out of a JavaScript array or object or wherever you keep them later.

    Also, be very sure that you are escaping data in your query. As it stands now, you are probably subject to SQL injection. Learn to use PDO with prepared queries to avoid this problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data from two different sources that I need to combine. Some data
I need to use Server.MapPath() to combine some files path that I store in
I need to combine fields and then trim out extra spaces the middle of
I need to combine to a string column and the result of a row_number()
I need to combine lines in two files, basing in the condition, that in
I need to combine my main query with a subquery: Current query (which works):
Using C++ I need to combine two distinct IDs into one 16bit integer. Then
I need to create and combine several expressions for child entity into one to
I need to create a table that will combine two database tables together. Both
I need to convert the function path::combine(path1, path2). Please help me if you have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.