Jump to content

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);

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.