Ah, my mistake. I was referring this piece of code:
$stmt->execute(["%$_POST[id2]%", $_POST['id']]);
^ here
I thought it would create an error because, while there are quotes around the entire first string, there are no quotes around the array index id2 within that string. Turns out that they are not required there, because it’s within a double-quoted string. I used to have a signature to show I’m learning PHP, but I don’t always remember to write it.
Ok back in work now as have been keen to get these updates sorted and see, and although dreamweaver now accepts those line changes the loop isnt working correctly, but I have managed to get it working on the live server so I can show you guys.
If you type Cancun into the text area the first 9 hotels will appear, and the second ‘Show More’ button, which all works fine.
But on pressing the ‘Show More’ button again, it correctly shows the remaining hotels, but it loops again and shows the same last batch of hotels again.
Am going to keep on working in my dev area to try and resolve it, but will leave the live one as it is.
What’s the code like at the moment? I can see that there are issues with how it populates on the second and subsequent runs, as you said.
ETA - That’s strange. It seems to vary randomly. Once I typed in Cancun and it displayed as you said - the first group correctly, the second group repeated. Another two times, I typed in Cancun and it displays the first group, then the second group twice and prompts for a third group, but seems to include places that don’t match the search word.
Yep its a strange one, and so far this morning ive been trying to counter the loop with count++ but thats not working, it hasnt changed much but the php related to this second display is -
<?php
if(!empty($_POST["id"]) && !empty($_POST["id2"])) {
$queryAll="select count(*) from tbl_hotels LEFT JOIN tbl_resorts ON (tbl_resorts.Id_Rsrt=tbl_hotels.IdRsrt_Hot) WHERE tbl_resorts.Nom_Rsrt like ? AND Act_Hot='1' AND (tbl_hotels.Id_Hot < ?) ORDER BY tbl_hotels.Id_Hot DESC";
$stmt=$dbo->prepare($queryAll);
$stmt->execute(array("%$_POST[id2]%", $_POST['id']));
$count = $stmt->fetchColumn();
$showLimit = 9;
$query="select Nom_Hot, IdType_Hot, Id_Hot, IdRsrt_Hot, Dir_Hot, IdCat_Hot, Act_Hot, Foto1_Hot from tbl_hotels LEFT JOIN tbl_resorts ON (tbl_resorts.Id_Rsrt=tbl_hotels.IdRsrt_Hot) WHERE tbl_resorts.Nom_Rsrt like ? AND Act_Hot=1 AND tbl_hotels.Id_Hot < ? ORDER BY tbl_hotels.Id_Hot DESC LIMIT $showLimit";
$resultb = $dbo->prepare($query);
$resultb->execute(array("%$_POST[id2]%", $_POST['id']));
$num_rowsb = $resultb->rowCount();
if($num_rowsb > 0){
foreach ($resultb as $nt) {
$tutorial_idb = $nt['Id_Hot']; ?>
<div class='obj'><a href='#'><p class='text'>REQUEST REPORT 2 <?php echo $tutorial_idb; ?></p><div class='item'><img src='http://www.checksafetyfirst.com<?php echo $nt['Foto1_Hot']?>' alt='' width='360' height='239'><div class='item-overlay top'></div></div></a><p class='nameHotel'><?php echo $nt['Nom_Hot'] ?></p><p class='addressHotel'><?php echo $nt['Dir_Hot'] ?></p></div>
<?php } ?>
<div class="obj push"></div>
<div class="obj push"></div>
<div class="pushend"></div>
<?php if($count > $showLimit){ ?>
<div class="show_more_main" id="show_more_main<?php echo $tutorial_idb; ?>">
<span data-id="<?php echo $tutorial_idb; ?>" data-id2="<?php echo $_POST['id2']; ?>" class="show_more" title="Load more posts">SHOW MORE SECOND <?php echo $tutorial_idb; ?></span>
<span class="loding" style="display: none;"><span class="loding_txt">Loading….</span></span><br/><br/>
</div>
<?php } } }?>
The AJAX hasnt changed, as I dont believe its that. But to test it was working I put the hotel id into the hotel div and it shows up on rollover and then the last id shows up next to the show more button, so its working fine, just for some reason it loops around again at the end
OK, the reason it sometimes displays things that don’t match my search input is down to how it goes off to search based on the search box changing, rather than waiting for a “submit” button - I just had a look at my test search, and it’s using “can” rather than the full word. So that probably isn’t relevant.
Out of interest, what’s the reason for having this line twice?
One thing puzzles me, that is the div called .tutorial_list doesn’t seem to just have the list of new hotels appended, it has another div with the same name appended within it. It’s a long time since I’ve looked at CSS in any detail, I wondered if that mattered. It seems that your second-search code is sending it as part of the response. At the start you have
Oh right, umm the displayDiv div is the area given to the page to allow the hotels to appear when you search by type, and then tutrial_list is whats allowing the hotels to appear inside of in an orderly way.
I shall have to keep looking at this to see if this is the problem maybe, as i havent quite worked it out yet, but wanted to reply to you straight away
It just seems that the second-and-subsequent search code shouldn’t be re-opening it every time, just sending the content. Might not make any difference, of course.
That does append it - the issue is that the response from the PHP code includes a div opener as well as all the hotel details, so that gets appended and opens another div.
Like I said, though, it might not make any difference to the problem itself.
Yep I think thats it mate, thank you very, very much. Seems like a bit of CSS tinkering now and I’m sorted, and relax, yes blood pressure reducing and heart rate returning to normal