Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an array from DB results

Status
Not open for further replies.

camcim

Programmer
Jan 25, 2003
20
0
0
US
Hi all,
If i have the following:
Code:
$sql = "SELECT * FROM company_categories WHERE company_id='$id'";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
    $comp_cat_id = $row["comp_cat_id"];
    $company_id = $row["company_id"];
    $category_id = $row["category_id"];

echo "$category_id";
how can i get the $category_id into an array?

Cheers,
camcim
 
$cat_array = array();

$cat_array[] = $category_id;

or if you want to know the specific index...

$cat_array['apples'] = $category_id;
$cat_array[1] = $category_id;

The initial call to $cat_array = array(); may be optional (I can't remember off hand), but it certainlly won't hurt things.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top