How do I control the selected values in select with PHP?

Source: Internet
Author: User
Like I have a select form.
Option_1Option_2 .....Option_n

The last n may be great, my design is that after the user form is submitted to MySQL, and then the user can edit it, then on the edit page, this single-selection form must appear as the value in MySQL is selected. I have read the values in MySQL is $value _select_1, how to control this select_1 form with PHP to the value of $value_select_1 to select it?

Shortly after learning PHP, I hope to advise.


Reply to discussion (solution)

Data in the database that is the data output that has been saved to take this value 1 and then the foreach output to determine whether the value is equal, equal is selected.

Data in the database that is the data output that has been saved to take this value 1 and then the foreach output to determine whether the value is equal, equal is selected.
Moderator give me remote chin
My environment is not good!!!!

Data in the database that is the data output that has been saved to take this value 1 and then the foreach output to determine whether the value is equal, equal is selected.
Girl

$value _select_1=1; $select _arr=array (' value_1 ', ' value_2 ', ' value_3 ', ' value_4 '); foreach ($select _arr as $value) {    if (Intval (substr ($value, -1,1)) = = = $value _select_1)        echo $value. ' Selected ';}

$value _select_1=1; $select _arr=array (' value_1 ', ' value_2 ', ' value_3 ', ' value_4 '); foreach ($select _arr as $value) {    if (Intval (substr ($value, -1,1)) = = = $value _select_1)        echo $value. ' Selected ';}

Thank you moderator, but why is 1 to 1?


$value _select_1=1; $select _arr=array (' value_1 ', ' value_2 ', ' value_3 ', ' value_4 '); foreach ($select _arr as $value) {    if (Intval (substr ($value, -1,1)) = = = $value _select_1)        echo $value. ' Selected ';}

Thank you moderator, but why is 1 to 1?
Understand, take the last one, thank you!

 
  '; Echo '' For ($i =1; $i <=10; $i + +) {    echo 'Option_ '. $i. ';} echo '; $cur = 10;echo ';? >

Better write functions to improve code reuse

 
  '; Echo '' For ($i =1; $i <=10; $i + +) {    echo 'Option_ '. $i. ';} echo '; $cur = 10;echo ';? >

This is good, but unfortunately I have already closed the post can not give you a cent, but still expressed great thanks
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.