Jump to content

count an inner join query


vexon

Recommended Posts

hello :)

I'm trying to count make a results page where you choose the amount of results shown per page. Also I want there to be a dropdown box to choose a page with results for example ranging from 100 tot 130 (Limit 100, 130) and a back and forward button.

To do this I'm making a query that counts all the rows without the limit so I can calculate the amount of page etc.
The query I'm using for this is:

$sql2 = "SELECT pricelist.description, pricelist.ref_trac, pricelist.old_ref, pricelist.PRICE_ID, pricelist.bruto_prices, OEM.OEM, COUNT(*) FROM pricelist INNER JOIN OEM ON pricelist.ref_trac = OEM.ref_trac,  WHERE pricelist.description LIKE '%".$description."%' AND pricelist.ref_trac LIKE '%".$ref_trac."%' AND pricelist.old_ref LIKE '%".$old_ref."%' AND OEM.OEM LIKE '%".$oem."%'";


The original query to option the display results is:

$sql = "SELECT pricelist.description, pricelist.ref_trac, pricelist.old_ref, pricelist.PRICE_ID, pricelist.bruto_prices, OEM.OEM FROM pricelist INNER JOIN OEM ON pricelist.ref_trac = OEM.ref_trac WHERE pricelist.description LIKE '%".$description."%' AND pricelist.ref_trac LIKE '%".$ref_trac."%' AND pricelist.old_ref LIKE '%".$old_ref."%' AND OEM.OEM LIKE '%".$oem."%' ORDER BY ".$sort." DESC LIMIT ".$limits[0].", ".$limits[1]."";

I can also tell that the query is very slow it takes 13 seconds to process :(
I think I'm going the wrong way with this and there might be an easier way (maybe even with tutorial) if so please let me know :)
I hope someone can help me out with this soon I'd be very thankfull for that.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.