Moron
-
Posts
369 -
Joined
-
Last visited
Posts posted by Moron
-
-
There is still a problem.... removing DISTINCT from the query makes it list all records, but both links for the 29th bring up the same record.
How can I make this:
while ($RESULT = mssql_fetch_assoc($RESULTDS)) { $endingdate = $RESULT['PSTUB5']; $month = substr("$endingdate", -8, 2); $day = substr("$endingdate", -6, 2); $year = substr("$endingdate", -4, 4); $Date = $month."/".$day."/".$year; echo "<a href=\"paystubpopup.php?Date=".$endingdate."\" target=\"_blank\">"; echo $Date; echo "</a>"; echo "<BR>";
.... distinguish between the two?
-
DISTINCT removes duplicate rows from the result set.
Thank you! That did the trick! I was using code from a previous query and I had used DISTINCT for whatever reason at the time.
-
Show your code for the query...
is $RESULTDS the correct variable? something about the D after the T looks odd
Yes, $RESULTDS is correct. The "DS" part is an acronym for my department. Everything works except when there is more than one record for a given date. That's why I suspect that the first code I posted might be the problem instead of the query.
-
Help with what query? My guess is that your actual query is only retrieving one of each date.
Here's the actual query:
$RESULTDS=mssql_query("SELECT DISTINCT LH.[EMPNO], M2.[hrYRAT], M2.[EMPNO], M2.[MANLAP], M2.[PAYCTR], M2.[MANLAC], M2.[MANLTC], M2.[MSKLAB], M2.[MSKLTC], M2.[NAMEMI], M2.[NAMEL], M2.[NAMEF], EH.[DATE], EH.[ENETPA], EH.[EGRSER], EH.[EREGHR], EH.[EDEDUC], EH.[EROTHR], EH.[EFWHD], EH.[EPEDAT], EH.[ESSDED], EH.[EHOSPD], EH.[ELIFED], EH.[ECRUD], M2.[POSITN], M2.[MCTDWH], M2.[MHDATE], M2.[MCTDCS], M2.[MO3TOT], M2.[MCTDLD], M2.[MCTDGE], M2.[MALPPP], M2.[MSLPPP], M2.[MWHSTA], M2.[MWHALL], M2.[MWHADD], EH.[EGARND], EP.[EMPNO], DP.[EMPNO], EI.[DDEPTN], EI.[NEWOCC], EI.[hrYRAT], EI.[MEMPAD], EI.[MEMPCS], EI.[MEMPZI], PA.[PSTUB1], PA.[PSTUB5], PA.[PSTUB6], PA.[PSTUB2], PA.[PSTUB3], PA.[PSTUB4], PA.[PSTUB7], PA.[PSTUB8], PA.[PSTUB9], PA.[PSTU10], PA.[PSTU11], PA.[PSTU12], PA.[PSTU13], PA.[PSTU14], PA.[PSTU15], PA.[PSTU16], PA.[PSTU17], PA.[PSTU18], PA.[PSTU19], PA.[PSTU28], PA.[PSTU29], PA.[PSTU30], PA.[PSTU20], PA.[PSTU21], PA.[PSTU30], PA.[PSTU26], PA.[PSTU31], PA.[PSTU36], PA.[PSTU37], PA.[PSTU42], PA.[PSTU43], PA.[PSTU44], PA.[PSTU45], PA.[PSTU46], PA.[PSTU47], PA.[PSTU48], PA.[PSTU22], PA.[PSTU23], PA.[PSTU24], PA.[PSTU25], PA.[PSTU27], PA.[PSTU32], PA.[PSTU33], PA.[PSTU34], PA.[PSTU35], PA.[PSTU49], PA.[PSTU50], PA.[PSTU51], PA.[PSTU52], PA.[PSTU53], PA.[PSTU38], PA.[PSTU39], PA.[PSTU54], PA.[PSTU55], PA.[PSTU57] FROM MASTERL2 M2 LEFT JOIN LeaveHistory LH ON LH.[EMPNO]=M2.EMPNO LEFT JOIN EARNHIST EH ON EH.[EEMPNO]=M2.EMPNO LEFT JOIN EMPPICTURE EP ON EP.[EMPNO]=EH.EEMPNO LEFT JOIN Departments DP ON DP.[EMPNO]=EP.EMPNO LEFT JOIN View_EmployeeInfo EI ON EI.[EMPNO]=M2.EMPNO LEFT JOIN PAYSTUBS_Archive PA ON PA.[PSTUB2]=M2.EMPNO WHERE PA.[PSTUB2] = '".$_SESSION['empcode']."' ORDER BY PA.[PSTU57] desc"); $RESULT=mssql_fetch_assoc($RESULTDS);
Is there some reason it wouldn't be pulling all of the records?
On mine, I have two records for Nov 29 and one for November 15. It pulls the November 15 record and ONE for the 29th.
-
while ($RESULT = mssql_fetch_assoc($RESULTDS)) { $endingdate = $RESULT['PSTUB5']; $month = substr("$endingdate", -8, 2); $day = substr("$endingdate", -6, 2); $year = substr("$endingdate", -4, 4); $Date = $month."/".$day."/".$year; echo "<a href=\"paystubpopup.php?Date=".$endingdate."\" target=\"_blank\">"; echo $Date; echo "</a>"; echo "<BR>";
It works perfectly, EXCEPT..... if there is more than one database entry for a certain date, it only displays one of them.
Ideas?
-
A side note even a whitespace is considered not empty.
<?php if(isset($_RESULT['PSTU62']) && !empty(trim($RESULT['PSTU62']))) { echo $RESULT['PSTU62']."<br />"; } ?>
The trim function will remove any whitespaces.
Here is another variation, that may be better suited that way you the variable exist if not it is null you then use the is_null function to check. And it is trimmed in the definition.
<?php $pst = isset($_RESULT['PSTU62'])?trim($_RESULT['PSTU62']):null; if(!is_null($pst) && $pst != "") { echo $RESULT['PSTU62']."<br />"; } ?>
Your second example seems to be working for me. Adapting it to my code I'm using:
<?php $message62 = isset($RESULT['PSTU62'])?trim($RESULT['PSTU62']):null; if(!is_null($message62) && $message62 != "") { echo $RESULT['PSTU62']."<br />"; } $message63 = isset($RESULT['PSTU63'])?trim($RESULT['PSTU63']):null; if(!is_null(message63) && message63 != "") { echo $RESULT['PSTU63']."<br />"; } $message64 = isset($RESULT['PSTU64'])?trim($RESULT['PSTU64']):null; if(!is_null(message64) && $message64 != "") { echo $RESULT['PSTU64']."<br />"; } ?>
...etc.....
Thanks!
-
You dont need an else statement on that loop.
All you want to do is echo out what youve done so you just need
<?php if(!empty($RESULT['PSTU62'])) { echo $RESULT['PSTU62']."<br />"; } ?>
Thanks, but I'm getting the same result, a "<BR>" inserted even when the field is empty.
Using your example, my code now reads:
<?php if(!empty($RESULT['PSTU62'])) { echo $RESULT['PSTU62']."<br />"; } ?>
-
<?php if(!empty($RESULT['PSTU62'])) { echo $RESULT['PSTU62']; echo "<BR>"; } else { } ?>
If there is data in the field it echoes it and inserts a break (HTML <BR> tag).
But..... if there's nothing in a field, it still inserts a break tag anyway, resulting in too many spaces between entries.
Ideas?
???
-
yeah, that would be a sure sign that someone needs to be fired. lol
Hope it does the job for ya. I'll tag this thread to notify, so let me know if it works else I'll help you.
It works!
Thanks again. Currently, there is only one Pay Period Ending date in the table, but I see no reason it won't work fine once there are more.
-
THANK YOU FOR CLARIFYING!!! lol jk, but that does help.
on this line i gave you:
echo "<a href=\"paystubs.php?Date=".$Date."\">";
instead say
echo "<a href=\"paystubs.php?Date=".$endingdate."\">";
Then, in your query, say
...WHERE `date_column`=".$_GET['Date']."...
that should pass your block date (12152008) to the next page specified by the link above and make it usable for the query.
Additional comment: use
if(!is_numeric($_GET['Date'])){ die('Bad Date Input'); }
That will prevent SQL injection (type of hacking if you didn't know)...
Thanks, Brian. I'll try it in a bit.
This is on our internal Intranet, so if we have a hacker I think we'll catch him pretty quickly!
-
oh yes, and to make it into a $_SESSION var, add this to the top of your pages that will use the $_SESSION var.
session_start();
and add this to that page
$_SESSION['the_name_of_the_session_you_want'] = $_GET['Date'];
Its hard for me to know what you want at this point because you'r a little all over the place. LOL
Thanks for your help, Brian. Yes, this has been confusing.
Let me try to express myself a bit better. I understand that the above code isn't a proper HTML "form." What I want is the following:
1. Get the available pay period ending dates through a query (already working).
2. List them and make them links (working).
NOTE: The reason I'm breaking up the date is for display purposes only ("12/15/2008" looks a bit more human-readable than "12152008"). But it's the actual date value ($RESULT['PSTUB5']) that I'm trying to pass to the next page.
3. Pass the selected variable ($RESULT['PSTUB5']) into the query on the next page by using sessions or whatever technique I can (WHERE $RESULT['PSTUB5'] = $_SESSION['enddate']) .
That's what I'm really getting at; when a user clicks a Pay Period Ending Date, I want to pass that selected Pay Period Ending Date into the query on the next page, thereby pulling the record for that date.
As for forms, I don't really want an HTML "select" with a dropdown; I want a list to appear instead, which is what I have now.
Sorry for the confusion. Does this make a bit more sense?
Thanks again.
-
You have to have the variable picked out before you could make it a session value which if you are using a form to pick it out, you'll need to post it first. :-\
Can I see your code for the form and also where you are trying to use the POST variable?
Here it is:
<?php $RESULTDS=mssql_query("SELECT DISTINCT M2.[EMPNO], PS.[PSTUB5] FROM MASTERL2 M2 LEFT JOIN PAYSTUBS PS ON PS.[PSTUB2]=M2.EMPNO WHERE M2.[EMPNO] = '".$_SESSION['empcode']."' ORDER BY PS.[PSTUB5]"); $RESULT=mssql_fetch_assoc($RESULTDS); mssql_data_seek($RESULTDS,0); echo "<CENTER>"; echo "<font size=2 color=#000000 face=arial>"; echo "Please select a stub to view:"; echo "</font>"; echo "</CENTER>"; echo "<BR>"; echo "<form action=\"paystubs.php\" name=\"paystubs\" value=\"ppeenddate\" method=\"post\">"; while ($RESULT = mssql_fetch_assoc($RESULTDS)) { $endingdate = $RESULT['PSTUB5']; $month = substr("$endingdate", -8, 2); $day = substr("$endingdate", -6, 2); $year = substr("$endingdate", -4, 4); echo "<CENTER>"; echo "<font size=2 color=#0000ff face=arial>"; echo "<a href=\"paystubs.php\">"; echo $month; echo "/"; echo $day; echo "/"; echo $year; echo "</a>"; echo "</form>"; echo "</font>"; echo "</CENTER>"; echo "<BR>"; } ?>
The above does what I want; it lists the available Pay Period Ending dates ($RESULT['PSTUB5']) from the database table and also makes them clickable. I just can't seem to pass $RESULT['PSTUB5'] as a variable to the next page. This variable will tell it what date to pull the record for.
-
I think this may be what you are asking about:
<?php $RESULT = mssql_fetch_array($RESULTDS); ?> <select name="endingdate" id="endingdate"> <?php do { ?> <option value="<?php echo $RESULT['PSTUB5']; ?>"><?php echo $RESULT['PSTUB5']; ?></option> <?php } while ($RESULT = mssql_fetch_assoc($RESULTDS)); ?> </select>
(as long as mssql_fetch_assoc does the same as the mysql version. I've never used it.)
that should do the trick to make it a POST value. Note that the menu I made above is named "endingdate", so the POST value it will make will be $_POST['endingdate'].
For some reason, that isn't making it a $_POST value. I can echo other post or session values on the page, but this gives me nothing.
Isn't there a way to make ANY value a $_SESSION variable?
-
value=""[/b] part is what is passed as a post value. The name of the post value is the menu's name (in example: my_menu). So you'd use $_POST['my_menu'].
So using this code:
while ($RESULT = mssql_fetch_assoc($RESULTDS)) { $endingdate = $RESULT['PSTUB5']; $month = substr("$endingdate", -8, 2); $day = substr("$endingdate", -6, 2); $year = substr("$endingdate", -4, 4); echo "<CENTER>"; echo "<font size=2 color=#0000ff face=arial>"; echo $month; echo "/"; echo $day; echo "/"; echo $year; echo "</font>"; echo "</CENTER>";
...how do I make "$RESULT['PSTUB5']" a "post" value and also make it linkable?
-
You can use javascript to submit the form once a drop down value is chosen, taht will then take you to your script
Can I not just make the selected item a "post" value in php and pass it that way?
-
Okay, I now have it pulling the records of available paystubs for each employee and populating a list. So if you all don't mind, help me with my thinking here....
Next I need to make each item in the list linkable (duh). Then I need to pass the date they're clicking as a variable into the query on the results page right? Or am I missing something?
-
build a query to select everything you want from the database. output it into a select field in an html form
when that form is submitted build another query using the chosen value from the drop down list.
Sounds good to me. I just plugged in a dynamic javascript dropdown to list the entries when they click the button. I can write the query in question. Any good starting point on plugging into the select fields?
-
Okay, I'm working on a project for employee paystubs. It's working great, but...... when they click the "Paystubs" button, I want it to drop down a list of entries for their name in the database so they can pick and click one. The table I'm using is brand new and only contains the latest and greatest data (thus, one record per person), but soon there will be an archive. I want to display a list and let them pick.
Any guidance is appreciated as always.
-
printf() did the trick.
Thanks, everyone!
-
This is probably dirt simple, but I'm having a problem finding it in the manual.
In the database, if a number is five digits, my code echoes the entire five digits (12345), of course. If it's a single digit, I want to append four zeros to the beginning of it (00004, etc...).
How is this done?
Thanks!
-
I'll keep this long and painful story as short as possible. We have an Access 2000 database that is used for making identification cards. It pulls the data from an MS SQL database through an ODBC connection.
Well, it suddenly got VERY slow to pull any records. I can run an older backup copy of the Access database and anything that was already in there runs fine. BUT... if I refresh the connection to the SQL tables (in Linked Table Manager), it suddenly takes 10-15 minutes to pull a single record and then I can't edit it once it does.
All of the SQL tables run fine within Enterprise Manager. The Access database itself runs fine until I try to refresh the connections in Linked Table Manager.
Any ideas? I'm stumped and so are a few other people.
-
do you have any records in it?
I tried some other databases and it worked. Who knows? Maybe my migration from CSV didn't work properly.
Thanks.
-
When I click Browse here, all I get is a history of database activity (tables created, etc....). I want to browse the actual records.
-
click on the table you want then hit browes at the top...
I don't have any such button or link. I'm using the version of PHPMyAdmin that loaded with Wampserver 5.
[SOLVED] Help with this query, please?
in MySQL Help
Posted
The check number and date cannot be the same, so the check number can be the distinguishing field. How do I express that here?
i.e. How do I add the check number field to the URL variable?