Jump to content

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

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.