Html code repeats in parsing mysql results

Discuss coding issues, and scripts related to PHP and MySQL.
mluci12
Posts: 39

Html code repeats in parsing mysql results

I have this php code:

Code: Select all

if ($result->num_rows > 0) {
  if($row['stare'] =='sell') $html .='<h4 class="telefon2">'.$row['stare'].'</h4>';
  else if($row['stare'] =='rent ') $html .='<h4 class="telefon3">'.$row['stare'].'</h4>';
  // afisaza datele pentru fiecare rand din $result
  while($row = $result->fetch_assoc()) {
 if($row['stare'] =='sell') $html .='<h4 class="telefon2">'.$row['stare'].'</h4>';
  else if($row['stare'] =='rent ') $html .='<h4 class="telefon3">'.$row['stare'].'</h4>';
echo '<div class="box-body box box-solid fa fa-text-width box-header with-border">

          <div class="pull-left image">
              <img class="img-circle" src="avatar.png" alt="User Image" width="32" height="32"></img>
              <p style="text-align:center">'.$row['email'].'</p>
          </div>
         <h4 class="host_link">'.$row['importanta'].'</h4>
                            <h4 align=\"left\" class="host_link">'.$row['stare'].'</h4> 
                            <br></br> '. $html .'
                     <h4 align=\"left\"><strong>Title</strong>: '.$row['ids'].'</h4>
                     <h4 align=\"left\"><strong>Descriere</strong>: '.$row['descriere'].'</h4> 
                         <h4 align=\"left\"><strong>Email</strong>: '.$row['email'].'</h4>
                          <a href="send-message.php?user='.$row['memberid'].'&type=requiment" target="_blank"><img src="http://mluci.com/d/Message.png"></img></a>
                        <a href="tel:+40726106381"> <img src="http://mluci.com/d/call.png"></img></a>
                             <a href="ticket.php?idt='.$row['ID'].'&type=Available" target="_blank"><img src="http://mluci.com/d/details.png"></a>
                             <a href="copy.php?descriere='.$row['descriere'].'&title='.$row['ids'].'"><img src="http://mluci.com/d/copy.png"></img></a>
</div> ';
 }
}
else {
  echo '0 results';
} 
The problem is that html value repeats. See on: mluci.com/d/cont.php

Admin Posts: 805
Hi,
I suppose the cause is you concatenate the "stare" result with ".=", so, it is added to previous parsing. Try with simple "=", or replace your code it with this one:

Code: Select all

if($result->num_rows > 0){
  // afisaza datele pentru fiecare rand din $result
  while($row = $result->fetch_assoc()) {
   if($row['stare'] =='sell') $stare ='<h4 class="telefon2">'.$row['stare'].'</h4>';
    else if($row['stare'] =='rent ') $stare ='<h4 class="telefon3">'.$row['stare'].'</h4>';
    echo '<div class="box-body box box-solid fa fa-text-width box-header with-border">
    <div class="pull-left image">
      <img class="img-circle" src="avatar.png" alt="User Image" width="32" height="32"></img>
      <p style="text-align:center">'.$row['email'].'</p>
    </div>
    <h4 class="host_link">'.$row['importanta'].'</h4>
    <h4 align=\"left\" class="host_link">'.$row['stare'].'</h4> 
    <br></br> '. $stare .'
    <h4 align=\"left\"><strong>Title</strong>: '.$row['ids'].'</h4>
    <h4 align=\"left\"><strong>Descriere</strong>: '.$row['descriere'].'</h4> 
    <h4 align=\"left\"><strong>Email</strong>: '.$row['email'].'</h4>
    <a href="send-message.php?user='.$row['memberid'].'&type=requiment" target="_blank"><img src="http://mluci.com/d/Message.png"></img></a>
    <a href="tel:+40726106381"> <img src="http://mluci.com/d/call.png"></img></a>
    <a href="ticket.php?idt='.$row['ID'].'&type=Available" target="_blank"><img src="http://mluci.com/d/details.png"></a>
    <a href="copy.php?descriere='.$row['descriere'].'&title='.$row['ids'].'"><img src="http://mluci.com/d/copy.png"></img></a>
  </div>';
 }
}
else {
  echo '0 results';
} 

Similar Topics