Echo div

hey…

im doing a bit of pagination (which i havent done before).

I want to echo out the results in a div, however i keep getting a error…

Whats seems to be drastically wrong with this?

$sql = "SELECT prodid, code FROM items2 WHERE cat1='Altri' ORDER BY prodid ASC LIMIT $offset, $rowsperpage ";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

while ($list = mysql_fetch_assoc($result)) {
   // echo data
   echo '<div class=\\"colbox\\">
      <div class=\\"colboxinner\\">
        <a href=\\"http://www.website.com\\" ><img src=\\"imagethumbs/XXXXXXX.jpg\\" alt=\\"alt\\" width= \\"102\\" height=\\"104\\" /></a>
   <div class=\\"proddetails\\"> codice: <strong>$list['prodid']</strong><br />
     prezzi: <strong></strong></div>
     </div>
   
      </div>';
 
   
} 

Thanks in advance

oh, ps, do i ‘need’ to escape all double quotes?

You can’t put an ‘if’ in an echo statement.
Why don’t you take another look at ahundiak’s reply and try to add the if in that code. It’ll be a lot easier, I think :slight_smile:

thanks chaps…ive got it working…

i was looking too mauch at the div structure for errors rather than the data…

changed $list[‘prodid’] to ‘. $list[‘prodid’] .’

duh

Mixing a bunch of html and php inside an echo can be difficult to trouble shoot. You don’t actually need to escape double quotes when they are inside of a single quote string. But in any event, consider this approach:


<?php
$sql = "SELECT prodid, code FROM items2 WHERE cat1='Altri' ORDER BY prodid ASC LIMIT $offset, $rowsperpage ";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

while ($list = mysql_fetch_assoc($result)) {
?>
<div class="colbox">
  <div class="colboxinner">
    <a href="http://www.website.com" >
      <img src="imagethumbs/XXXXXXX.jpg" alt="alt\\" width= "102" height="104"/>
    </a>
   <div class="proddetails"> codice: <strong><?php echo $list['prodid']; ?></strong>
<br />
     prezzi: <strong></strong>
   </div>
  </div>
</div>
<?php } ?>

Bit easier to read perhaps? And I think you were missing a " mark.

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/funarise/public_html/fdgg.php on line 61

.line 61 begins with

<div class="proddetails">

sorry for the revisit…

I got it working the other day, now im trying to add a conditional display, however im not sure how to do it…what ive got a moment is the following (which is completly wrong!):

   echo '<div class="colbox">
      <div class="colboxinner">
        <a href="http://www.website.com" ><img src="http://www.funarisedie.com/'.$number1.'" alt="alt" width= "102" height="104" /></a>
   <div class="proddetails"> codice: <strong>'. $list['code'] .'</strong><br />
  '.if ($sale == si){.' prezzo: <strong>'. $list['price'] .'</strong>'.};.' 
 '. if ($sale == no){.' <span class="sale">  prezzo: <strong>'. $list['sprice'] .'</strong></span>'.};.'</div>
     </div>
   
      </div>';
 
   
}

How to i ‘introduce’ the IF around the record?

Thanks in advance

What error?

do i ‘need’ to escape all double quotes?

You need to escape all double quotes in a string if you put the entire string between double quotes.
You need to escape all single quotes in a string if you put the entire string between single quotes.