Jump to content

Return MySQL query results into indexed array?


grippat

Recommended Posts

I'm trying to get the results of mysql_query() into an indexed array so i can access specific locations later on. I want to have a for loop later that goes through and does something a set number of times (22 to be exact). Here's the code I'm trying to get to work.

$company_ids = mysql_query('SELECT id FROM _companies WHERE cust_sales_rep = '.$sales_rep_id);$num_companies = 0;$num_companies = mysql_num_rows($company_ids);		$companies_per_day = $num_companies/22;		$stop_point = 0;		// After determining the number of companies for each day, go thru and assign each day's call datefor ($i = $stop_point; $i < $companies_per_day; $i++) {		    $one_id[$i] = mysql_fetch_array($company_ids, MYSQL_NUM);	    // Creates the call     db_query("INSERT INTO _calls_test (`desc`, sch_call, company_id, type, user_id) VALUES ('Auto generated frequency call','".$$todays_date."','".$one_id."','Frequency','".$sales_rep_id."')");				}	

Link to comment
Share on other sites

All arrays are indexed, some are indexed with numbers only and others are associative. In PHP, all arrays are technically associative. Also, this query has problems:db_query("INSERT INTO _calls_test (`desc`, sch_call, company_id, type, user_id) VALUES ('Auto generated frequency call','".$$todays_date."','".$one_id."','Frequency','".$sales_rep_id."')");There is no variable called $todays_date, so $$todays_date is going to fail, $one_id is just going to print the word "Array" (because $one_id is an array), and there is no $sales_rep_id variable defined.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...