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
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
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
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.