Loop in array

I have these arrays. i want the array values to be stored from database… but fetching data from database inside array with while loop isnt possible or may i am doing something wrong.

for example :

in this code :

echo json_encode(array(

	array(
		'id' => 111,
		'title' => "Event1",
		'start' => "$year-$month-10",
		'url' => "http://yahoo.com/"
		),
	
		
));

i want this part to be looped:

array(
‘id’ => 111,
‘title’ => “Event1”,
‘start’ => “$year-$month-10”,
‘url’ => “http://yahoo.com/
),

… so i get somwthing like this :

echo json_encode(array(

	array(
		'id' => 111,
		'title' => "Event1",
		'start' => "$year-$month-10",
		'url' => "http://yahoo.com/"
		),


	array(
		'id' => 111,
		'title' => "Event1",
		'start' => "$year-$month-10",
		'url' => "http://yahoo.com/"
		),


	array(
		'id' => 111,
		'title' => "Event1",
		'start' => "$year-$month-10",
		'url' => "http://yahoo.com/"
		)
	
		
));

Are you asking how to do this in PHP? Or Javascript?

Also, the loop you displayed as an example just showed the same array over and over…
Did you mean that it would loop thru all the entries and show Event1, Event2, Event3…
Or, did you mean you wanted to duplicate the arrays for some reason?

Lastly, you can use PHP to loop thru entries in a database with very little code.
You can use SQL or MySQL queries to do this also and the loop thru the results.
Lots of ways to handle routines to loop thru data.

We would need a little further details on exactly what you are trying to do in your project.
Since the example you showed just has Event1,Event1,Event1 , Not sure what you want.

Let us know and we can help you…

Sponsor our Newsletter | Privacy Policy | Terms of Service