Jump to content

select counting of two tables to paginate their query results


turpentyne

Recommended Posts

Hey there. Not sure how to word this. I've been flying blind as a newbie trying to figure out some pagination for a left joined query. I've got syntax errors trying to set up the SELECT COUNT function that adds up the results of the search on a previous page so it knows how many results matched both tables.

 

Right now, I've got this mess, and it's giving me a syntax error,

"You have an error in your SQL syntax; .... near 'LEFT JOIN plantae ON (descriptors.plant_id = plantae.pla' at line 12"

$data = "Select (SELECT COUNT(*)
                    FROM
                        descriptors
                    ) AS 
                        count1,
                (SELECT COUNT(*)
                    FROM
                         plantae
                    ) AS
                        count2

                    LEFT JOIN
                        plantae ON (descriptors.plant_id = plantae.plant_name)
                    WHERE
                        `leaf_shape` LIKE '%$select1%'
                        AND `leaf_venation` LIKE '%$select3%'
                        AND `leaf_margin` LIKE '%$select4%'";
                    
  
$result = mysql_query ($data);
if (!$result) {
    die("Oops, my query failed.  The query is: <br>$data<br>The error is:<br>".mysql_error());
} 



whoah! wait. got a little lucky. But still problems with the pagination.  I suppose I'll need to post a new topic for that.

 

I changed the code to:

$data = "SELECT COUNT(*)
                    FROM
                        descriptors
                    LEFT JOIN
                        plantae ON (descriptors.plant_id = plantae.plant_name)
                    WHERE
                        `leaf_shape` LIKE '%$select1%'
                        AND `leaf_venation` LIKE '%$select3%'
                        AND `leaf_margin` LIKE '%$select4%'";
                    
  
$result = mysql_query ($data);

Archived

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

×
×
  • 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.