Php+mysql Implementing a drop-down box to display database information

Source: Internet
Author: User
Tags php foreach


<title>Classroom</title>



Crms-classroom







1. I want to enter the classroom number in the first box, and the second box displays the contents of the CID of the Course2 table in the database by the drop-down box.
This should be wrong, there is no clue, do not know how to achieve. For detailed code!
2, how to achieve the completion of one of the data (that is, do not fill two) you can query data?


Reply to discussion (solution)

What do you mean. Drop-down box to check the value of the input box?

The contents of the CID in the Course2 table in the database CRMs appear in the drop-down box

while ($row = Mysql_fetch_array ($result))
{
echo "$row [CID] ";
}

No way. I don't know if I'm inserting a PHP code in the middle of a select. Can I just try it on my own, please?

As long as the PHP file is OK. Allow HTML to be nested with PHP.

This has to be Ajax, the menu linkage is.

Wood has learned, can not directly to the code I ... It's not going to be complicated.

5 floor of the friend, that should be how to write ah?

Your code will be the same as the part that you changed. I don't know what's wrong with you.

while ($row = Mysql_fetch_array ($result))
{
$row
}

To change this paragraph into

while ($row = Mysql_fetch_array ($result))
{
echo "$row [CID] ";
}
Is that right?
I changed, but my dropdown box still does not appear CID content, only please select!

Confirm that there is data in the table.
$result = mysql_query ($search _course, $con) or Die (Mysql_error ());
So there's no error?

There is data.
No error, confirm is with Echo, this is not 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);}}? >
 
 
) ">
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 $item 2) {echo"{$item 2[' name '} ";} echo "";}}? >

It's so simple, it doesn't need to be that complicated!

Require_once (' conn.php '); ? It's best to write a file that connects to the database every time it's included! And it's written on top.

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




Untitled Document



-Please select- $sql = "Select CID from Course2"; $result =mysql_query ($sql); while ($row =mysql_fetch_assoc ($result)) {?> This value is to be taken out of Php method }?>


It's so simple, it doesn't need to be that complicated!

Require_once (' conn.php '); ? It's best to write a file that connects to the database every time it's included! And it's written on top.

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

Put Into

  
   

After submission, you can pass the value to the past!! Remember to Add a Name

It's so simple, it doesn't need to be that complicated!

!--? php
//require_once (' conn.php '); it's best to write a file that connects to the database every time it's included! and write at the top

//best to write the following three lines in the conn.php file after each time to the above to include a bit on the OK!!
$con = mysql_connect ("localhost", "root", "* *") or Die ("error message:". Mysql_error ());//connection
$db = mysql_select_db (" The name of the database where the table course2 resides "); This can not write the data but will not error
mysql_query ("Set names gb2312");

?>




Untitled document



-Please select-!--? php $sql = "Select CID from Course2" ; $result =mysql_query ($sql); while ($row =mysql_fetch_assoc ($result)) {?> !--? php echo $row [' CID ']? --> //This value is to be removed by PHP method!--? php }?>

Hello, because I just started to learn, for the conversion between HTML and PHP is very understanding. I have written a head in an HTML, already in the body (there is a box to fill the classroom number, has been implemented), only to start to write the course number (in your way), the following I have to write the time (implemented), then how to insert your code in the middle? Because you started writing head again.

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


You can run it.

$sql = "Select CID from Course2";
$result =mysql_query ($sql);
while ($row =mysql_fetch_assoc ($result)) {
?>

This value is to be taken out of the PHP method.
}

I also feel like this to write, but it is not show Ah!

You are not connected to 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.