简体   繁体   中英

PHP and MySQL - Printing rows matching a column value

I need to write a PHP script that will print out results from a MySQL database. For example, say I have 9 fields. Field 1 is an auto increasing number, field two is a three digit number.

I need to be able to have a script read, find the matching number (it'll be from a POST), and then display all matching three digit results, and the 7 other fields as well. I am already logged in to the database in this script.

I guess I'm really at a loss of where to begin. How would one start something like this?

Thank you.

Since you are already connected to the database, all you have to do is query the database the iterate through the results. Here is a quick example.

$sql = "SELECT * FROM table_name WHERE field_two = " . (int) $_POST['field_two_input'];
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
    echo $row['field_one'] . ':' . $row['field_two'] . '<br />';
}

Google around searching "php mysql".

For example: http://www.php.net/manual/en/function.mysql-query.php

You should start with some manual for beginners about SQL, PHP, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM