blsn
blsn

Reputation: 1093

my PHP MySQL syntax is too long

Thank you, very nice solution, that was answered my question. How can I use your solution if my $sql is as follows:

$sql = "SELECT * FROM $tbl_main, $tbl_country, $tbl_members
WHERE ($tbl_main.country_id = $tbl_country.country_id) AND ($tbl_main.member_id = $theselect) ORDER BY $chosenTable.$orderby LIMIT $startpoint, $limit";

i.e. how can I use your solution somewhere in the middle of a code.

Upvotes: 0

Views: 81

Answers (1)

Mark Byers
Mark Byers

Reputation: 838276

You can conditionally concatenate the extra condition:

$sql = "SELECT * FROM $tbl_main, $tbl_country, $tbl_members
WHERE ($tbl_main.country_id = $tbl_country.country_id)";

if(isset($theselect)) {
    $sql .= " AND ($tbl_main.member_id = $theselect)"; 
}

$sql .= " ORDER BY $chosenTable.$orderby LIMIT $startpoint, $limit";

Upvotes: 4

Related Questions