/    Sign up×
Community /Pin to ProfileBookmark

Ok so I have a database table with dates in them….there are 3 fields in the table that I want to pull dates from…I want to display 3 rows of 3 dates for a total of 9 dates. I want to sort them by date.

Here’s the layout of the table…

autoid, procdate, paydate, deliverydate

Here’s my code so far:

[code=php]$eArray = array();

$dSQL = “SELECT * FROM procDates WHERE deliverydate > NOW() LIMIT 3”;
$dQRY = mysql_query($dSQL);
$dCnt = 1;
while ($dobj = mysql_fetch_object($dQRY)) {

//Org Orders Cutoff
$eArray[‘Org Orders Close’] = strtotime($dobj->procdate);

//Org Payments Due
$eArray[‘Org Payment Due’] = strtotime($dobj->paydate);
$dCnt++;

//DISTRIBUTION DAY!!
$eArray[‘Distribution Day’] = strtotime($dobj->deliverydate);
}

asort($eArray);

echo “<h2>Upcoming Events</h2>
<br />
<ul style=’list-style-type: none;’>”;
foreach($eArray as $key => $value) {
$date = date(“M j – g:ia”, $value);
echo “<li><font size=’2′><b>” . $date . “</b></font> &nbsp;&nbsp;&nbsp;” . $key . “</li>”;
}
echo “</ul>”;[/code]

Only problem is that as the WHILE loop goes through the 3 rows…it over-writes the array items. How do I prevent that?

I only get 3 items listed in my unordered list….

Example: [url]http://www.southatlantafoodsource.com[/url]
Click Calendar. You should see 9 items there…starting in September….

I guess I could do something like:

[code=php]
$eArray[] = array(‘Org Orders Close’ => strtotime($dobj->procdate);
[/code]

But how would I read that back in and sort through it?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tirnaAug 12.2010 — One way to do it is to have 3 different arrays for each date and then add the date from each column to its appropriate array.
Copy linkTweet thisAlerts:
@arrielmabaleAug 12.2010 — Ok so I have a database table with dates in them....there are 3 fields in the table that I want to pull dates from...I want to display 3 rows of 3 dates for a total of 9 dates. I want to sort them by date.

Here's the layout of the table...

autoid, procdate, paydate, deliverydate

Here's my code so far:

[code=php]$eArray = array();

$dSQL = "SELECT * FROM procDates WHERE deliverydate > NOW() LIMIT 3";
$dQRY = mysql_query($dSQL);
$dCnt = 1;
while ($dobj = mysql_fetch_object($dQRY)) {

//Org Orders Cutoff
$eArray['Org Orders Close'] = strtotime($dobj->procdate);

//Org Payments Due
$eArray['Org Payment Due'] = strtotime($dobj->paydate);
$dCnt++;

//DISTRIBUTION DAY!!
$eArray['Distribution Day'] = strtotime($dobj->deliverydate);
}

asort($eArray);

echo "<h2>Upcoming Events</h2>
<br />
<ul style='list-style-type: none;'>";
foreach($eArray as $key => $value) {
$date = date("M j - g:ia", $value);
echo "<li><font size='2'><b>" . $date . "</b></font> &nbsp;&nbsp;&nbsp;" . $key . "</li>";
}
echo "</ul>";[/code]


Only problem is that as the WHILE loop goes through the 3 rows...it over-writes the array items. How do I prevent that?

I only get 3 items listed in my unordered list....

Example: http://www.southatlantafoodsource.com

Click Calendar. You should see 9 items there...starting in September....

I guess I could do something like:

[code=php]
$eArray[] = array('Org Orders Close' => strtotime($dobj->procdate);
[/code]


Add some unique Id in the array,

And you also have to change the way you display it

[code=php]
//Org Orders Cutoff

$eArray['Org Orders Close'][$dobj->autoid]= strtotime($dobj->procdate);

//Org Payments Due

$eArray['Org Payment Due'][$dobj->autoid] = strtotime($dobj->paydate);
$dCnt++;

//DISTRIBUTION DAY!!
$eArray['Distribution Day'][$dobj->autoid] = strtotime($dobj->deliver[/code]
×

Success!

Help @swg1cor14 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...