mysql - PHP opening times & embassy holidays -


i've been using code:

 $rawsql = "select  *      _erc_foffices n  inner join      _erc_openings o on n.id = o.branch_id , o.dotw = dayofweek(current_date())  inner join      _erc_openings_times t on o.id = t.opening_id  (     unix_timestamp(current_timestamp()) between unix_timestamp(concat(current_date(), ' ', t.open)) , unix_timestamp(concat(current_date(), ' ', t.close))  )  ,  (     n.id = %d ) ;";  $sql = sprintf($rawsql, mysql_real_escape_string($id));  $result = mysql_query($sql);  /*these if & while statements decide whether or not information should displayed. if no results returned query above alternative message shown.*/  if(mysql_num_rows($result) > 0) {     while ($row = mysql_fetch_array($result, mysql_assoc)) {          echo "<div class='address'><p>" . $row["title"] . "<br/>";         echo $row["address_1"] . "<br/> " . $row["address_2"] . "<br/> " . $row["address_3"] . "<br/> " . $row["address_4"] . "<br/> " . $row["address_5"] . "</p>";         echo "<div class='buttons'><img src='http://localhost/erc/images/texttouser_button.png'/><br/><a href='" . $row["url"] . "' target='blank'><img src='http://localhost/erc/images/website_button.png'/></a></div></div>";         echo "<div class='email'>" . $row["email"] . "</div>";         $extra_notes = $row["extra"];      } } else {          $embassy_closed = mysql_query("select * _erc_foffices id = '$embassy_id'");          while($row = mysql_fetch_array($embassy_closed))                       {          echo "<div class='address'><p>" . $row["title"] . "<br/>";         echo $row["address_1"] . "<br/> " . $row["address_2"] . "<br/> " . $row["address_3"] . "<br/> " . $row["address_4"] . "<br/> " . $row["address_5"] . " <font color='red'>the embassy closed.</font></p>";         echo "<div class='buttons'><img src='http://localhost/erc/images/texttouser_button.png'/><br/><a href='" . $row["url"] . "' target='blank'><img src='http://localhost/erc/images/website_button.png'/></a></div></div>";         echo "<div class='email'>" . $row["email"] . "</div>";         $extra_notes = $row["extra"];                         }   } 

which takes opening times embassies database , decides whether or not embassy open. if it's not, message saying 'the embassy closed' shown. need add in public holidays, have altered query this:

    $rawsql = "select      *              _erc_foffices n      inner join          _erc_openings o on n.id = o.branch_id , o.dotw = dayofweek(current_date())      inner join          _erc_openings_times t on o.id = t.opening_id         left join      _erc_holidays h on h.branch_id = n.id          (         unix_timestamp(current_timestamp()) between unix_timestamp(concat(current_date(), ' ', t.open)) , unix_timestamp(concat(current_date(), ' ', t.close))      )      ,      (         n.id = %d     )         , (     unix_timestamp(current_timestamp())      not between unix_timestamp(h.begins_at) , unix_timestamp(h.ends_at) )         ;"; 

but outputs address/email etc twice.

could point out i'm doing wrong please?

thanks help

edit: have fixed now, used 2nd query , if/else loop.

i wouldn't profess expert , joins complicated, in experience if you're getting duplicates in query haven't grouped , can't see group @ in query.

hope helps.

by way... did source public holiday data? i'm looking exact same thing @ moment how came across post.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -