PHP + MySQL implementation drop-down box displays database information

Source: Internet
Author: User
Tags php foreach
PHP + MySQL implementation drop-down box displays database information

Classroom research



CRMS-Classroom research





1. I want to enter the classroom number in the first box, and the second box displays the CID content of course2 table in the database in the drop-down box.
This should be wrong. I have no clue and don't know how to implement it. Code details!
2. how can I query data by entering one of the data (that is, no need to fill in two?


Reply to discussion (solution)

What does it mean. What is the value of the input box selected in the drop-down box?

The CID content of course2 table in database crms is displayed in the drop-down box.

While ($ row = mysql_fetch_array ($ result ))
{
Echo"$ Row [CID]";
}

No. I don't know if I can insert a PHP code in the middle of the select statement. I just want to give it a try.

As long as it is a PHP file. Html and php nesting are allowed.

You have to use AJAX to link menus.

I have learned this before. could you just give the code to me?

What should I do for friends on the fifth floor?

Add the #3 modified part of your code. I don't know what problems you have encountered.

While ($ row = mysql_fetch_array ($ result ))
{
$ Row
}

Change this paragraph

While ($ row = mysql_fetch_array ($ result ))
{
Echo"$ Row [CID]";
}
So, right?
I changed it, but the CID content still does not appear in my drop-down box. select only!

Check that the table contains data.
$ Result = mysql_query ($ search_course, $ con) or die (mysql_error ());
Is there any error?

Data is available.
No error is reported. Are you sure you want to use echo? isn't it just echo on the screen?

For reference only:

 Error :". mysql_error (); if (mysql_affected_rows ()> 0) {$ titles = array (); while ($ rows = mysql_fetch_array (MYSQL_ASSOC) {array_push ($ titles, $ rows) ;}}?>
 
 
) ">

Script // Ajaxvar xmlHttp; function createXMLHttpRequest () {if (window. XMLHttpRequest) {xmlHttp = new XMLHttpRequest ();} else if (window. activeXObject) {xmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ") ;}} function record (id) {createXMLHttpRequest (); url =" action. php? Id = "+ id +" & ran = "+ Math. random (); method = "GET"; xmlHttp. open (method, url, true); xmlHttp. onreadystatechange = show; xmlHttp. send (null);} function show () {if (xmlHttp. readyState = 4) {if (xmlHttp. status = 200) {var text = xmlHttp. responseText; document. getElementById ("s2 "). innerHTML = text;} else {alert ("response error code:" + xmlHttp. status) ;}} script Error :". mysql_error (); if (mysql_affected_rows ()> 0) {$ arrMenu = array (); while ($ rows = mysql_fetch_array (MYSQL_ASSOC) {array_push ($ arrMenu, $ rows) ;}} mysql_close (); if (! Empty ($ arrMenu) {echo""; Foreach ($ arrMenu as $ item2) {echo"{$ Item2 ['name']}";} Echo"";}}?>

It's so simple, it's not as complicated as above !!? You can directly copy it and use it ....

// Require_once ('Conn. php ');//? It is best to write a file to connect to the database every time it is included! And write it at the top.

$ Con = mysql_connect ("localhost", "root ","***");
?>




Untitled Document



-Select- $ SQL = "select CID from course2 ";$ Result = mysql_query ($ SQL );While ($ row = mysql_fetch_assoc ($ result )){?> // Obtain the value using the php method. } ?>


It's so simple, it's not as complicated as above !!? You can directly copy it and use it ....

// Require_once ('Conn. php ');//? It is best to write a file to connect to the database every time it is included! And write it at the top.

$ Con = mysql_connect ("localhost", "root ","***");
?>

Set Change

   

So? The value can also be passed after submission !! Remember Add name

It's so simple, it's not as complicated as above !!? You can directly copy it and use it ....

// Require_once ('Conn. php ');//? It is best to write a file to connect to the database every time it is included! And write it at the top.

// It is best to write the following three lines in the conn. php file. it will be OK if it is included in the above line every time !!
$ Con = mysql_connect ("localhost", "root", "***") or die ("error message:". mysql_error (); // connection
$ Db = mysql_select_db ("name of the database where the table course2 is located"); // If you do not want to write this, you will not be able to retrieve the data, but no error will be reported.
Mysql_query ("set names gb2312 ");

?>




Untitled Document



-Select- $ SQL = "select CID from course2 ";$ Result = mysql_query ($ SQL );While ($ row = mysql_fetch_assoc ($ result )){?> // Obtain the value using the php method. } ?>

Hello, because I just started learning, and I don't know much about conversion between HTML and PHP. I have already written the head in an HTML file, and I have already written the body (there is also a box above to fill in the classroom number, which has been implemented ), I started to write the course number (using your method), and now I want to write the time (implemented). how can I insert your code in the middle? Because you have started writing head again.

So complicated? The script tag can also be added at the bottom of the code, as long as there are:

Script // Ajaxvar xmlHttp; function createXMLHttpRequest () {if (window. XMLHttpRequest) {xmlHttp = new XMLHttpRequest ();} else if (window. activeXObject) {xmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ") ;}} function record (id) {createXMLHttpRequest (); // specify the target address and parameter url =" action. php? Id = "+ id +" & ran = "+ Math. random (); method = "GET"; xmlHttp. open (method, url, true); xmlHttp. onreadystatechange = show; xmlHttp. send (null);} function show () {if (xmlHttp. readyState = 4) {if (xmlHttp. status = 200) {// callback function, return the backend result var text = xmlHttp. responseText; document. getElementById ("s2 "). innerHTML = text;} else {alert ("response error code:" + xmlHttp. status) ;}} script

Just run

$ SQL = "select CID from course2 ";
$ Result = mysql_query ($ SQL );
While ($ row = mysql_fetch_assoc ($ result )){
?>

// Obtain the value using the php method.
}

I want to write it like this, but it cannot be displayed!

You have not connected the table .....

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.