PHP implements universal database query

墨辰丷
Release: 2023-03-31 17:56:01
Original
1658 people have browsed it

This article mainly introduces the general function of reading data from the database table to the array in PHP. The example analyzes the general database query skills in PHP. It is of great practical value. Friends who need it can refer to it

The example of this article describes how PHP implements a general function of reading data from a database table into an array. The specific analysis is as follows:

This function does not care about the table structure. It only needs to specify the table name, structure and query conditions to perform general query operations on the table, which is very practical.

function listmytablerows($table, $name, $field, $where, $textID)
{
/ / Connect to the database and query execution
connect ();
$Sql = "select * from". $table. "". $where. "ORDER BY". $field;
$Req = mysql_query($sql);
$Res = mysql_num_rows($req);
?>
<Select name = "<?php echo $name; ?>" id="<?php echo $textID; ?>">
<option value=""> ____</ option>
<? Php
/ / We do a loop that will read the information for each record
while ($data = mysql_fetch_array($res))
{
  / / We display the information from the current record
?>
   <Option value = "<?php echo $data[&#39;id&#39;]; ?>">
   <?php echo $data[$field]; ?>
</ Option>
   <? Php
  }
?>
</ Select>
<? Php
}
?>
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

php method to hide the actual download address of a file

php method to get the date of this Monday

phpTwo commonly used methods to recursively delete folders

The above is the detailed content of PHP implements universal database query. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!