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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Creation Question

Status
Not open for further replies.

lprono77

Programmer
Sep 25, 2005
2
US
I think this is a simple question. I need to create an array using a mysql query for a calendar program I am using. The problem is I'm not certain how to create this array using the query.

Here's what I need to produce:

$days = array(
2=>array('/weblog/archive/2004/Jan/02','linked-day'),
3=>array('/weblog/archive/2004/Jan/03','linked-day'),
8=>array('/weblog/archive/2004/Jan/08','linked-day'),
22=>array('/weblog/archive/2004/Jan/22','linked-day'),

);

This array basically tells the calendar program which days have events connected to them and then creates a link. The first number (2,3,8,22) is the day of the month. My query searches the db for all events within the current month. I need to figure out how to add these into the days array and create their own sub array.

If someone can help point me in the right direction I'd appreciate it. Thanks!
 
why create an array and not retrieve the info from youre database ?? select distinct(day) from table where month(dateevent)=month(currentdate) or something like that


and what is linked-day doing since it looks like a constant you don't have to put it in an arra

but if you insist

$days = array()
$days[2]= '/weblog/archive/2004/Jan/02';
$days[3]= '/weblog/archive/2004/Jan/02';
$days[8]= '/weblog/archive/2004/Jan/02';
$days[22]= '/weblog/archive/2004/Jan/02';

 
Thanks for the response. I actually am trying to retrieve it from the bd, I was just using that array as an example of an array that will work. I basically need to rund a query whicih looks like this:

SELECT * FROM calendar where event_month= '$this_month' and event_year='$this_year'


Then create an array that functions as the one I mentioned above, but from the query. I'm thinking something like this in the query:
$d=$row["event_day"];
$days[$d]= "'/weblog/archive/2004/Jan/02'";

My problem is it needs to create an array like this one:

$days = array(
2=>array('/weblog/archive/2004/Jan/02','linked-day'),
3=>array('/weblog/archive/2004/Jan/03','linked-day'),
8=>array('/weblog/archive/2004/Jan/08','linked-day'),
22=>array('/weblog/archive/2004/Jan/22','linked-day'),

);

With the days (which are $row["event_day"] and then within that the /weblog... will ultimatly be filled with another varible for a link. Thanks again for your help.
 
but still I don't see the need of forming an array , is that forced upon you from some higher power ??

you can also loop through you're database results and fill you're whole link

$url="/weblog/archive/" . $row[event_year]. "/". $row[event_month]. "/" . $row[day];

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top