Jump to content
Dtrain

CMS Query Problem

Recommended Posts

Hi, I am making a CMS and I can't get the search page to work right. The CMS is for a new local DJI store and I can't get anything to show up when I search for those who have paid for insurance on their drones. And when I enter a first or last name that multiple people have in common, like Mike or Smith, the info doesn't display correctly, The first customer is displayed correctly, but no one else is.

searchcodefirst.php

searchcodeinsurance.php

searchcodelast.php

Share this post


Link to post
Share on other sites

Why don't you pick ONE problem and show us that code?  Perhaps if we solve that one, the others will fall into place for you.  Key thing is to Show the Code.

Share this post


Link to post
Share on other sites

searchcodefirst.php

searchcodelast.php

 

you should NEVER create different files of code that only differ in the table column being searched. to specifically search for just a first name or just a last name, all you should have is one file and a little program logic that dynamically picks the table column to be searched.

 

you should also NEVER run loop over the result from one query and run another query inside of the loop. you should run one JOINed query, then just loop over the result from that one query.

 

you should also separate the concerns in your code, which would make it easier to debug your code and to just post the portion of the code where the problem is at. at a minimum you should separate the database dependent code (that knows how to retrieve the data) from the presentation code (that knows how to produce the output from that data.) the result (output) from the database dependent code should just be an array of any rows that the query matched. the database dependent code should contain no html and the presentation code should contain no database statements, just php statements that test and operate on the array of data. for debugging, if the array of data contains the expected result, you know the database dependent code is working and that the problem is in the presentation code.

 

lastly, the code you have attached starts after some main query that's not part of the code. without knowing what those main queries are, we cannot possibly help you with anything your code is or is not doing.

Edited by mac_gyver

Share this post


Link to post
Share on other sites

here's another issue with the database design and this code. user/customer information, like first and last names, should be stored in a users/customers table. it should not be stored in tables holding purchase_orders and service_orders data. any rows in the purchase_orders and service_orders tables should be related back to the user/customer data using an id.

Edited by mac_gyver

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

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.