Jump to content

php select statement


project3

Recommended Posts

ok I have a select statement that works just fine. I want to alter it a little to add some to the where clause.

 

in the db it selects by day of the week restaurants that match hours opened to the current time.

but what i want to do is add more hours opened. as some restaurants will have three periods during the day when they are open like

restaurant

open      close

9          11

1          3

5          10

 

 

now i have that set up in db. and can select the first result but i need a or statement and am unsure how to do a or in the following sql statemnt (at bottom of post).

 

 

$thiscat in the following statement is the day of the week like

 

$thiscat = catMonFrom

$thiscat2 = catMonTo

 

the other cats are catMonFrom2, catMonTo2, catMonFrom3, catMonTo3

 

catMon

 

$Q = "select "

      . "  c.catID, "

      . "  catName, "

      . "  catDesc, "

      . "  catPhoto, "

      . "  catPhotoWidth, "

      . "  catPhotoHeight "

      . "from "

      . "  ds_categories c "

      . "left join ds_language_categories l on "

      . "  l.catID = c.catID "

      . "where "

      . "  $thiscat <= '$tnow' and "

      . "  $thiscat2 >= '$tnow' and "

      . "  parentID = '$parentID' and "

      . "  catHide != 'Y' and "

      . "  l.langID = '$langID' "

      . "  $ex "

      . "order by "

      . "  catSort,catName "

      . "limit "

      . " $skip, " . $config->getValue('limit')

      . "";

 

Any help would be great.

Link to comment
https://forums.phpfreaks.com/topic/93045-php-select-statement/
Share on other sites

Try this:

$Q = "select "
      . "  c.catID, "
      . "  catName, "
      . "  catDesc, "
      . "  catPhoto, "
      . "  catPhotoWidth, "
      . "  catPhotoHeight "
      . "from "
      . "  ds_categories c "
      . "left join ds_language_categories l on "
      . "  l.catID = c.catID "
      . "where "
      . "  ('$tnow' BETWEEN catMonFrom AND catMonTo or "
      . "   '$tnow' BETWEEN catMonFrom2 AND catMonTo2 or "
      . "   '$tnow' BETWEEN catMonFrom3 AND catMonTo3) and "
      . "  parentID = '$parentID' and "
      . "  catHide != 'Y' and "
      . "  l.langID = '$langID' "
      . "  $ex "
      . "order by "
      . "   catSort,catName "
      . "limit "
      . " $skip, " . $config->getValue('limit')
      . "";

Link to comment
https://forums.phpfreaks.com/topic/93045-php-select-statement/#findComment-476681
Share on other sites

Try this:

$Q = "select "
      . "  c.catID, "
      . "  catName, "
      . "  catDesc, "
      . "  catPhoto, "
      . "  catPhotoWidth, "
      . "  catPhotoHeight "
      . "from "
      . "  ds_categories c "
      . "left join ds_language_categories l on "
      . "  l.catID = c.catID "
      . "where "
      . "  ('$tnow' BETWEEN catMonFrom AND catMonTo or "
      . "   '$tnow' BETWEEN catMonFrom2 AND catMonTo2 or "
      . "   '$tnow' BETWEEN catMonFrom3 AND catMonTo3) and "
      . "  parentID = '$parentID' and "
      . "  catHide != 'Y' and "
      . "  l.langID = '$langID' "
      . "  $ex "
      . "order by "
      . "   catSort,catName "
      . "limit "
      . " $skip, " . $config->getValue('limit')
      . "";

 

 

That worked great. I forgot about between that really helps out alot.

Thank you again and do you know what happend to the topic solved button I don't see it anymore.

Link to comment
https://forums.phpfreaks.com/topic/93045-php-select-statement/#findComment-476704
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.