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"
Isbn |
Author |
Title |
Price | "; Echo"
\ N "; // Loop traversal while ($ myrow = mysql_fetch_row ($ result) {printf ("
% S |
% S |
% S |
% S | ", $ Myrow [0], $ myrow [1], $ myrow [2], $ myrow [3]);} echo"
\ 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"
Isbn |
Author |
Title |
Price | ";Echo"
\ N ";// Loop traversalWhile ($ myrow = mysql_fetch_row ($ result )){Printf ("
% S |
% S |
% S |
% S | ", $ Myrow [0], $ myrow [1], $ myrow [2], $ myrow [3]);}Echo"
\ 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"
Isbn |
Author |
Title |
Price | "; Echo"
\ N "; // Loop traversal while ($ myrow = mysql_fetch_row ($ result) {printf ("
% S |
% S |
% S |
% S | ", $ Myrow [0], $ myrow [1], $ myrow [2], $ myrow [3]);} echo"
\ 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"
Isbn |
Author |
Title |
Price | ";Echo"
\ N ";// Loop traversalWhile ($ myrow = mysql_fetch_row ($ result )){Printf ("
% S |
% S |
% S |
% S | ", $ Myrow [0], $ myrow [1], $ myrow [2], $ myrow [3]);}Echo"
\ 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!