Jump to content

[SOLVED] WHERE ?


Clinton

Recommended Posts

I did the code below because I'm going to replace dtype = * with dtype = $variable and I wanted to get it to work... which it's not. Basically, I want to be able to narrow down the search by dtype AND the dmajors but if there is no specific dtype selected I want to show all of the dtypes. Make sense?

 

 <?php $query = "SELECT COUNT(*) as num FROM $tbl_name WHERE dtype = * AND dmajorp = '$smajor' OR dmajorc1 = '$smajor' OR dmajorc2 = '$smajor' OR dmajorc3 = '$smajor' ORDER BY jpted"; ?>

Link to comment
https://forums.phpfreaks.com/topic/139606-solved-where/
Share on other sites

Just seen Brian's post, try that, if it doesn't work give below a bash!

 

-----

 

Perhaps you could do this PHP side? Something like...

 

$dtype = (some condition) ? "dtype = 'dtype' AND" : "";
$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE {$dtype} dmajorp = '$smajor' OR dmajorc1 = '$smajor' OR dmajorc2 = '$smajor' OR dmajorc3 = '$smajor' ORDER BY jpted";

 

A

Link to comment
https://forums.phpfreaks.com/topic/139606-solved-where/#findComment-730372
Share on other sites

<?php
if(!isset($dtype) || $dtype == ''){ $dtype = "-1"; }
  $query = "SELECT COUNT(*) as num FROM $tbl_name WHERE dtype = $dtype AND dmajorp = '$smajor' OR dmajorc1 = '$smajor' OR dmajorc2 = '$smajor' OR dmajorc3 = '$smajor' ORDER BY jpted";

?>
is that what you are looking for?

Link to comment
https://forums.phpfreaks.com/topic/139606-solved-where/#findComment-730380
Share on other sites

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.