Reads the contents of the database into a two-dimensional array and outputs it in the specified column

Source: Internet
Author: User
Tags array mysql query table name mysql database
Data | database | array?
$host = "localhost"; Host Name
$user = "root"; MySQL User name
$password = ""; MySQL Password
$database = "Doc"; MySQL database name
$tables = "MClass"; Table name

$conn =mysql_connect ("$host", "$user", "$password") or Die ("Database open error");
mysql_select_db ("$database");

$query = "SELECT * from $tables";
$result =mysql_query ($query, $conn);
$i = 0;
$j = 0;
while ($row =mysql_fetch_row ($result)) {
$array [$i] [$j] = $row [0]. $row [1];
$array 2[$i] [$j] = $row [0];
$j + +; echo $i. ",". $j. $row [1]. " <br> ";
if ($j ==3) {
$i + +;
$j = 0;
}//else {$j + +;}

$amax =count ($array);//is the number of data in the array.

$rows = 2; Set the number of columns

Start displaying data
For ($x =0 $x <= $amax-1; $x + +) {
for ($y =0; $y <= $rows; $y + +) {
echo "<a Href=". $array 2[$x] [$y]. " ". $array [$x] [$y]." </a> | ";
echo "<p>";

Display results as

? >

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: 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.