How to generate an array

Source: Internet
Author: User
How to build an array
In the MySQL library, there are two fields in a table, $cont _type, $cont _id, and the number of individual records is more than one, how to generate such a 2-dimensional array $tartree[$cont _type][]= $cont _id; mysql_ Fetch_row ()? Array

Share to:


------Solution--------------------

After reading it, it will be created as a two-dimensional array, directly paste the sample code
$conn = mysql_connect ("localhost", ' root ', '); If you have a password, you can add
$tarTree = Array ();
if ($conn)
{
if (mysql_select_db (' sql_primary ', $conn))//sql_primary is your database name
{
$sql = "SELECT * from Customers";//customers Replace with your table
$result = mysql_query ($sql);
while ($row = Mysql_fetch_array ($result))
{
Echo $row [' Company ']. \ r \ n ";
$tarTree [$row [' Cont_type ']][]= $row [' cont_id '];
}
Mysql_close ($conn);
}
}
?>
  • 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.