Php query function (how to obtain the fields of the corresponding table through the query conditions)

Source: Internet
Author: User
Php query function (how to obtain the fields of the corresponding table through the query conditions)
 "; // Connect to the Database mysql_select_db (" test ") or die (mysql_error (); // echo" Connected to Database "; // query data, use the table to Display @ $ checked =$ _ POST ['checked']; @ $ result = mysql_query ("select * from books", $ db); echo"
 
 
  
  
\ N "; echo"
  
  "; Echo" 
   \ N "; // Loop traversal while ($ myrow = mysql_fetch_row ($ result) {printf (" 
   ", $ Myrow [0], $ myrow [1], $ myrow [2], $ myrow [3]);} echo" 
   
Isbn Author Title Price
% S % S % S % S
\ N ";?> Untitled Document


Reply to discussion (solution)

Please describe your problem

Result = mysql_query ("select * from books where checked = '$ checked '");

For example, enter the isbn number to be queried, and then confirm, and output the matching query results below.

Result = mysql_query ("select * from books where checked = '$ checked'"); I tried this and the following error occurred.
Another question is how to display the results of a table after the query.

... Where field = '$ checked' // replace the field with your actual field

If (isset ($ _ POST ['checked']) {
@ $ Result = mysql_query ("select * from books", $ db );
Echo"

















\ N ";Echo" ";Echo" \ N ";// Loop traversalWhile ($ myrow = mysql_fetch_row ($ result )){Printf (" ", $ Myrow [0], $ myrow [1], $ myrow [2], $ myrow [3]);}Echo"
Isbn Author Title Price
% S % S % S % S
\ N ";
}

Thank you, jordan102. how can I use the query conditions to output tables that meet the query conditions on the same page?
This is my table.

I tried jordan102 code and I do not know how to add if (isset ($ _ POST ['checked']) {......} the location of this code is incorrect.
I pressed the query button but did not respond. The code is as follows:

 "; // Connect to the Database mysql_select_db (" test ") or die (mysql_error (); // echo" Connected to Database "; // query data, use the table to Display @ $ checked =$ _ POST ['checked']; // @ $ result = mysql_query ("select * from books", $ db ); // @ $ result = mysql_query ("select * from books where isbn = '$ checked'"); if (isset ($ _ POST ['checked']) {@ $ result = mysql_query ("select * from books", $ db); echo"
 
 
  
  
\ N "; echo"
  
  "; Echo" 
   \ N "; // Loop traversal while ($ myrow = mysql_fetch_row ($ result) {printf (" 
   ", $ Myrow [0], $ myrow [1], $ myrow [2], $ myrow [3]);} echo" 
   
Isbn Author Title Price
% S % S % S % S
\ N ";}?> Untitled Document

@ $ Result = mysql_query ("select * from books where isbn = '$ checked'", $ db );

@ Jordan102 I tried @ $ result = mysql_query ("select * from books where isbn = '$ checked'", $ db). but I still cannot click the button.

This sentenceI tried it, but when I input the isbn of books to the input box, I click query. I still cannot find all the corresponding content of isbn = 1.

Only a portion of the data is available. check whether the data is different.

$ Result = mysql_query ("select * from books", $ db );
If none of the conditions are added, is it a condition query?

No data table is displayed after I run it. The result is as follows:
Will there be no matching for those fields?

Sorry! Forgot to add.

If no matching record exists, the natural list is empty.

@ $ Result = mysql_query ("select * from books where isbn = '$ checked'", $ db );
Where is the value assigned ???

Hey, I marked it red on #18 and you still copied the error.


// Obtain the connection
$ Db = mysql_connect ("localhost", "root", "root") or die (mysql_error ());
// Echo "Connected to MySQL
";
// Connect to the database
Mysql_select_db ("test") or die (mysql_error ());
// Echo "Connected to Database ";

// Query the data and display it in a table
// @ $ Checked = $ _ POST ['checked'];
// @ $ Result = mysql_query ("select * from books", $ db );
// @ $ Result = mysql_query ("select * from books where isbn = '$ checked '");
If (isset ($ _ POST ['checked']) {
$ Checked = $ _ POST ['checked'];
@ $ Result = mysql_query ("select * from books where isbn = '$ checked'", $ db );
Echo"

















\ N ";Echo" ";Echo" \ N ";// Loop traversalWhile ($ myrow = mysql_fetch_row ($ result )){Printf (" ", $ Myrow [0], $ myrow [1], $ myrow [2], $ myrow [3]);}Echo"
Isbn Author Title Price
% S % S % S % S
\ N ";
}
?>



Untitled Document




Reply to qxhaidao and jordan102: After one afternoon, the qxhaidao code runs successfully, and jordan only displays the header. I will add two points. thank you!

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.