Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2013
    Thanked 0 Times in 0 Posts

    date format not working with pagination

    I have the following query which works fine, but when I applied pagination to allow the user to see multiple result sets it gave me an undefined index error on my date fields but when I removed the date_format the query works fine. Am confused as to why it gave me an error just because I applied pagination.
    Anyways, here is the query and any suggestions would be greatly appreciated thanks:

    $sql="	SELECT DISTINCT Customers.CUST_ID, Jobs.J_RefNum, Customers.CUST_Forename,
    		Manufacturers.MANU_ID, Customers.CUST_Surname, Manufacturers.MANU_Name,  
    		Customers.CUST_Email, Jobs.J_Model, Customers.CUST_Mobile, OperatingSystems.OS_ID,
    		Customers.CUST_HomeNum, OperatingSystems.OS_Name, Customers.CUST_AddressL1,
    		Jobs.J_ReceivedBy, Customers.CUST_AddressL2, 
    		DATE_FORMAT(Jobs.J_DateRec, '%d/%m/%Y'), 
    		Jobs.J_FaultDesc, Customers.CUST_Postcode, Jobs.J_PassWinAdmin, 
    		Jobs.J_DataRecYN, Jobs.J_PowerSuppYN, Jobs.J_MediaYN, Jobs.J_BagYN, Jobs.J_Conditions,
    		Jobs.J_ServiceTag, JobStatus.JS_ID, JobStatus.JS_Status, Jobs.J_Engineer, Jobs.J_EngComments,
    		Jobs.J_AntivirusYN, Jobs.J_ServicePackYN, Jobs.J_PDFYN, Jobs.J_FlashYN, Jobs.J_VLCYN,
    		Jobs.J_ValidatedYN, Jobs.J_DataRestoredYN, Jobs.J_Quote, Jobs.J_Comms,
    		DATE_FORMAT(Jobs.J_DateWorkComm, '%d/%m/%Y'), 
    		DATE_FORMAT(Jobs.J_DateCollec, '%d/%m/%Y'), Jobs.J_ProductKey,
    		MediaSpec.MediaSpec_Spec, dataRecSpec.DRS_Name, Company.COMP_ID, Company.COMP_Name,
    		Company.COMP_Email, Company.COMP_PrimaryNum, Company.COMP_SecondaryNum, Company.COMP_AddressL1,
    		Company.COMP_AddressL2, Company.COMP_AddressL3, Company.COMP_Postcode
    		FROM Customers, Jobs, Manufacturers, OperatingSystems, JobStatus, MediaSpec, dataRecSpec, Company
    		WHERE (Jobs.J_RefNum = '$criteria' AND Jobs.J_RefNum = Customers.CUST_ID)
    		AND (JobStatus.JS_ID = Jobs.J_RefNum) AND (Manufacturers.MANU_ID = Jobs.J_RefNum)
    		AND (OperatingSystems.OS_ID = Jobs.J_RefNum) AND (MediaSpec.MediaSpec_ID = Jobs.J_RefNum)
    		AND (dataRecSpec.DRS_ID = Jobs.J_RefNum) AND (Company.COMP_ID = Jobs.J_RefNum)

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Thanked 76 Times in 76 Posts
    I assume, I forgot how that works (check on net), your syntax
    (OperatingSystems.OS_ID = Jobs.J_RefNum)
    is realy left join, so you could get null values on your fileds

    Jobs.J_DateWorkComm, Jobs.J_DateCollec

    or there are mybe null vallues in that fileld at start ?

    Mybe , since there is no order by, and I think it should be so pagination would make any sence,
    limit ... throws other records at top than no limit query. And then your poblem pops out since problematic recorsds/query results pops on top of resultset.
    Last edited by BubikolRamios; 10-13-2013 at 07:51 PM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #3
    New Coder
    Join Date
    Oct 2013
    Thanked 0 Times in 0 Posts
    is realy left join, so you could get null values on your fileds
    It's an implicite INNER join.

    But more importantly, why is there a DISTINCT in this query? There are no duplicates so there should not be a DISTINCT. There may be more results than anticipated, but if tht is the case then the query is wrong. DISTINCT is hardly ever the right thing to do.

    it gave me an undefined index error
    That's because you did not give the date_format() selections an alias that your script can recognise. if you select DATE_FORMAT(...) you get the value back at the index "DATE_FORMAT(...)" which is not very userfriendly, so use an alias:
    SELECT DATE_FORMAT(...) AS formatted_date; and use "formatted_date" as the indx of your array.

    Do *NOT* use the original fieldname, because the date you select is noloonger usable as the original field value and will get you into trouble.

  • #4
    Regular Coder
    Join Date
    Aug 2013
    Thanked 0 Times in 0 Posts
    got it thanks guys appreciate it


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts