For Programmers: Free Programming Magazines  


Home > Archive > PHP on Windows > November 2004 > Re[2]: [PHP-WIN] While loops to build an array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re[2]: [PHP-WIN] While loops to build an array
Re_action

2004-11-30, 4:00 pm

Hello S.D.Price,

Sorry, but i can't clearly understand, what do you mean by this:
SDP> $days = array([date]=>array(id),)
if every $days[date] should contains array of id's you should use
this:
$days[date(j,$row3['entry_date'])][] = $row3['newsid'];

SDP> Hi thanks but this gives:

SDP> $days[date] = id;

SDP> What I need is a multidimensional array in the form

SDP> $days = array([date]=>array(id),)

SDP> Do you know how to do this?

SDP> thanks
SDP> Steve


SDP> -----Original Message-----
SDP> From: re_action [mailto:re_action@fromru.com]
SDP> Sent: 30 November 2004 17:10
SDP> To: php-windows@lists.php.net
SDP> Subject: Re: [PHP-WIN] While loops to build an array


SDP> Hello S.D.Price,

SDP> Your syntax is not correct, try this, instead:
SDP> if (mysql_num_rows($result3) > 0){
SDP> while ($row = mysql_fetch_array($result3)) {
SDP> $days[date(j,$row3['entry_date'])] = $row3['newsid'];
SDP> };
SDP> }
SDP> else {
SDP> echo "<p>The array has not been built.</p>";
SDP> };



SDP>> Hi, I wonder if you could help. I am trying to build a php based
SDP>> calendar for a news blog. The calendar should create hyperlinks
SDP>> directly to a news story. However in order to do this I need to
SDP>> create a $days array which takes the date value of the story
SDP>> submitted and the id of the story and creates a dynamic link.

SDP>> Howver I am finding it difficult to generate the array using a
SDP>> while loop - do you know a better way?.


SDP>> if (mysql_num_rows($result3) > 0) {

SDP>> $days = array(
SDP>> while ($row = mysql_fetch_array($result3)) {
SDP>> date(j,
SDP>> $row3['entry_date'])=>array($row3['newsid']),;
SDP>> }
SDP>> );


SDP>> }

SDP>> else {
SDP>> echo "<p>The array has not been built.</p>";

SDP>> }

SDP>> echo generate_calendar($year, $month, $days);

SDP>> Thanks

SDP>> Steven





SDP> --
SDP> Best regards,
SDP> re_action mailto:re_action@fromru.com




--
Best regards,
re_action mailto:re_action@fromru.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com