php - Duplicate Data how to remove -


hotels_data table hotel data table

hotel_rooms table

hotel_rooms table

mysql query

$pdo = $dbo->prepare('select distinct hotels_data.*, hotel_rooms.hid, hotel_rooms.room_name, hotel_rooms.price                      hotels_data                     left outer join hotel_rooms                     on hotels_data.hotel_id = hotel_rooms.hid                 '); 

outputing data

i loop hotel rooms

$row = $pdo->fetchall(pdo::fetch_obj);      foreach($row $rows){                 print '        <!-- listing -->              <div class="list_hotels_box">                 <ul class="list_hotels_ul">                     <li style="display:block;">                         <img src="../img/hotel_img.png" alt="" style="width: 180px; height:180px;"/>                     </li>                     <li style="width: 100%;">                         <a href="javascript:void()"><h3 class="clear-top">'.$rows->hotel_name.'<span><?php print $star; ?></span></h3></a>                         <p>'.$rows->hotel_address.', '.$rows->hotel_state.''.$rows->hotel_country.' </p>                         <div id="rooms">                        <p>                             <table class="table table-condensed table-striped table-hover table-bordered">                                         ';                                         foreach($row $td){                                             if($td->hotel_id == $rows->hid){                                                 print                                              '                                                 <tr>                                                         <td>'.$td->room_name.'</td>                                                         <td align="right" style="color: darkorange;"><strong><sup>rm</sup>'.$td->price.'</strong></td>                                                 </tr>                                                ';                                             };                                         } ;                             print '                                 <tr>                                     <td colspan="2"><a href="#" class="a" style="font-size: 11px;">see rooms</a></td>                                 </tr>                             </table>                          </p>                        </div>                     </li>                     <div align="right">                         <li>                             <h4><small>rating</small> <strong>8.5</strong></h4>                             <span class="help-block clear">"0" reviews</span>                             <button onclick="alert(\'not operational yet\')" class="btn btn-sm btn-info">book now</button>                         </li>                     </div>                 </ul>                 </div>                 <!-- listing -->                 '; 

here output have hotel sample & hotel sample 2 hotel sample has outputted 2 think bcoz of 2 rooms problem how remove duplicate data

please assist me. tq

sorry if didn't make myself clear output

one way split 2 queries, like:

select * hotels_data; 

and rooms query inside hotels loop:

select hid, room_name, price hotel_rooms hid = :hotel_id 

this assumes using binded parameters , bind $rows->hotel_id :hotel_id parameter.

you use group hotel_id, won't rooms hotels, unless use group_concat() , parse concatenated rooms values.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -