Array problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lekan_dny
Forum Newbie
Posts: 1
Joined: Sun Jun 02, 2013 7:37 am

Array problem

Post by lekan_dny »

using this query:

Code: Select all

		$queryC = "SELECT * FROM  tbl_courses WHERE course_id='$course_id'";
			$resC = mysql_fetch_assoc(dbQuery($queryC));	
			$allUnits = $resC[course_unit];
print_r(array($allUnits));
returns:
Array ( [0] => 3 ) Array ( [0] => 3 ) Array ( [0] => 2 ) Array ( [0] => 2 )

but am expecting it to return

Array ( [0] => 3 ) Array ( [1] => 3 ) Array ( [2] => 2 ) Array ( [3] => 2 )


anybody whit usefull help please....


I need it as soon as possible

Thanks in advance
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Array problem

Post by social_experiment »

If you are looking for a single array that contains all the values modify your code slightly

Code: Select all

while ($resC = mysql_fetch_assoc(dbQuery($queryC))) {
      $allUnits[] = $resC[course_unit];
}
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply