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);
}
}
?>