How to write the simplest query result statement

Source: Internet
Author: User
I don't know how to write the simplest query result statement, but now I only have space for PHP,
To create a function, you can easily,

There are two columns in the data table (A & B)
Implementation: I enter A value in the text box to query the value of column B corresponding to this value in column A in the database and return it to the page.

Yes... can you help me write a relatively complete off-the-shelf statement? Which includes the database connection statement


Reply to discussion (solution)

Error_reporting (0 );
$ Conn = mysql_connect ("localhost", "root", "root"); // enter the database connection information.
Mysql_select_db ("test"); // enter the database name
$ ValA = $ _ POST ["valA"];
If ($ valA! = ""){
$ SQL = "select * from test where a =". $ valA;
$ Result = mysql_query ($ SQL );
While ($ arr = mysql_fetch_array ($ result ))
{
Echo $ arr ["B"]."
";
}
} Else {
?>

}
?>

? Yes? Outsourcing, right? Don't you want? ?

You ?? What is the function ??, Hundred or Eighty? ? Someone? You have done it.

Error_reporting (0 );
$ Conn = mysql_connect ("localhost", "root", "root"); // enter the database connection information.
Mysql_select_db ("test"); // enter the database name
$ ValA = $ _ POST ["valA"];
If ($ valA! = ""){
$ SQL = "select * from test where a =". $ valA;
$ Result = mysql_query ($ SQL );
While ($ arr = mysql_fetch_array ($ result ))
{
Echo $ arr ["B"]."
";
}
} Else {
?>

}
?>
Thank you ~ Thank you very much.

? Yes? Outsourcing, right? Don't you want? ?
GA, I will use. net myself, but I have no choice but to know that the logic cannot be changed to php. I am here to ask for advice on php...

Error_reporting (0 );
$ Conn = mysql_connect ("localhost", "root", "root"); // enter the database connection information.
Mysql_select_db ("test"); // enter the database name
$ ValA = $ _ POST ["valA"];
If ($ valA! = ""){
$ SQL = "select * from test where a =". $ valA;
$ Result = mysql_query ($ SQL );
While ($ arr = mysql_fetch_array ($ result ))
{
Echo $ arr ["B"]."
";
}
} Else {
?>

}
?>


Echo $ arr ["B"], should B be replaced by the column name in my column?

Well, yes. a is replaced with your condition field name, and B is replaced with the field name you want to get the result.

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.