Jump to content

Archived

This topic is now archived and is closed to further replies.

Moron

AAAARRRGGHHH!!!!!!!!!!!!!!!

Recommended Posts

I'm as sick of posting this as you folks are of reading it. Trust me on this! But will someone PLEASE PLEASE PLEASE tell me what is happening here??????? A week of my life on this is ENOUGH!!!!!!

My code:

[quote]
while ($RESULT = mssql_fetch_assoc($RESULTDS))   {

$lastjuly = strtotime("July 1 $last");
$todaysdate = date(Ymd);
$todaystring = strtotime($todaysdate);
[b]$recdate = "$RESULT[Lmo]$RESULT[Lda]$RESULT[LYR]";[/b]
[b]$recdatestring = strtotime($recdate);[/b]

if ($recdatestring >= $lastjuly)  {


echo "<tr align=center>";
echo "<td>";


echo $RESULT['Lmo'];
echo "/";
echo $RESULT['Lda'];
echo "/";
echo $RESULT['LYR'];
echo "</td>";

echo "<td>";
echo $RESULT['Leave Code'];
echo "</td>";

echo "<td>";
$TotalGenHours = $TotalGenHours + $RESULT['Hours'];
echo $RESULT['Hours'];
echo "</td>";

echo "</tr>";
}
}[/quote]

Note the lines I put in bold. If I echo $recdate, it gives me 03282001 and pulls ZERO records.
?????????????????????????????????????????????????????????????????

Anybody?

Share this post


Link to post
Share on other sites
that line is saying recdate = monthdayyear as pulled from the database (so it will look like 082106 or similar).

If it is not working try.

$recdate = $RESULT[Lmo] . $RESULT[Lda] . $RESULT[LYR];

Share this post


Link to post
Share on other sites
[quote author=ToonMariner link=topic=105053.msg419399#msg419399 date=1156166278]
that line is saying recdate = monthdayyear as pulled from the database (so it will look like 082106 or similar).

If it is not working try.

$recdate = $RESULT[Lmo] . $RESULT[Lda] . $RESULT[LYR];
[/quote]

Thanks, but the formatting isn't the problem. The problem seems to be that it's seeing the date of a [b]specific[/b] record on March 28, 2001. Therefore, since that specific record is [b]not[/b] after July 1, 2006, then no records are pulled. What I'm trying to tell it (with GREAT DIFFICULTY) is....

Go through ALL the records. *IF* a record is *ON OR AFTER* July 1, 2006, then display it.

Share this post


Link to post
Share on other sites
As Ive said many times before you should be trying to do this in your query.

Share this post


Link to post
Share on other sites
[quote author=thorpe link=topic=105053.msg419412#msg419412 date=1156167392]
As Ive said many times before you should be trying to do this in your query.
[/quote]

Here's the part I don't understand, though; The query is pulling exactly what I want it to pull, which is all records. In other words, I don't want to miss anything. I can make it pull by calendar year, as in all records for that employee number for a specific year and so on, but I want to pull records after July 1.

Share this post


Link to post
Share on other sites
the state that in the query under the where clause.

Which ever field holds the date use 'WHERE `date` > 'july 1st' (obviously change that so the formats match otherwise it'll fail)

Share this post


Link to post
Share on other sites
[quote author=ToonMariner link=topic=105053.msg419438#msg419438 date=1156168997]
the state that in the query under the where clause.

Which ever field holds the date use 'WHERE `date` > 'july 1st' (obviously change that so the formats match otherwise it'll fail)
[/quote]

But this isn't a one-time deal. July 1 is the start of our fiscal year. Therefore, I have to use variables that define the previous July 1. Is there a way to plug a variable into a query?

Share this post


Link to post
Share on other sites
Some test code - and the results it produces showing that the strtotime argument you're using isn't working:

[code]$recdate = "03282001";
echo strtotime($recdate); // outputs -1
echo "<br>";

$recdate = "03-28-2001"; // test date
echo strtotime($recdate); // outputs 1285128000
echo "<br>";

$last = "2001";
$recdate = "07-01-". $last;
$lastjuly = strtotime($recdate);
echo $lastjuly; // outputs 1340424000[/code]

That should point the way to success ... which is to generate the record date from the database using:

[code]$recdate2 = $RESULT['Lmo']. "-". $RESULT['Lda']. "-". $RESULT['LYR']; // what is this record's date?[/code]


I do realise that you're working with a legacy database where the 'date' is stored in that funny manner, but (and I think I've said it before) fixing the database to use a single real date field would have avoided all the aggravation you're having trying to work around the fundamentally flawed date storage structure.  And I can't believe it woud take very long to fix the database - add new field named 'real_date', date format, then loop thru' your database generating dates in yyyy-mm-dd format by concatenating three field values and update each row with a real date.

Share this post


Link to post
Share on other sites
Thanks a lot, Andy. Based on what you posted, I tried this:

$recdate2 = $RESULT['Lmo']. "-". $RESULT['Lda']. "-". $RESULT['LYR'];
$recdate2string = strtotime($recdate2);

if ($recdate2string >= $lastjuly)  {

...etc....

It still pulls all records going back to 2001.

I think you're right, though; I'm going to look at simply adding a consolidated date field in the database. I guess nobody considered this back in 2001.

Share this post


Link to post
Share on other sites
[quote author=Moron link=topic=105053.msg419446#msg419446 date=1156170043]

It still pulls all records going back to 2001.[/quote]

I'd echo the value of $lastjuly in your code to make sure it really is the same as 07-01-2001 would be.

Share this post


Link to post
Share on other sites
[quote author=AndyB link=topic=105053.msg419447#msg419447 date=1156170199]
[quote author=Moron link=topic=105053.msg419446#msg419446 date=1156170043]

It still pulls all records going back to 2001.[/quote]

I'd echo the value of $lastjuly in your code to make sure it really is the same as 07-01-2001 would be.
[/quote]

You were right, Andy. Adding this to the query in the WHERE statement did the trick:

[quote]and LH.[LYR] >= '$last'  and LH.[Lda] >= '01' and LH.[Lmo] >= '07' [/quote]

Thanks again!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.