justlukeyou Posted May 31, 2012 Share Posted May 31, 2012 Hi, Im a echo out insider {} however when I try and add CSS it just creates an error as it dislikes the HTML. I have tried this but it doesn't like it. Is there a certain formar to using html inside PHP? echo '<div class="productimageborder"><a href="product.php?price=' . $query_row['name'] . '</div>'; $pages_query = mysql_query("SELECT COUNT(`name`) FROM `productdbase`"); $pages = mysql_result($pages_query, 0); $pages = ceil(mysql_result($pages_query, 0) / $per_page); $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1; $start = ($page - 1) * $per_page; $query_string = "SELECT `name`, `rrp`, `image_link`, `image_link`, `discount` FROM `productdbase` LIMIT $start, $per_page"; $query = mysql_query($query_string); while ($query_row = mysql_fetch_assoc($query)) { echo '<p>', $query_row['name'] ,'</p>'; echo '<p>', $query_row['rrp'] ,'</p>'; echo '<p>', $query_row['image_link'] ,'</p>'; echo '<p>', $query_row['name'] ,'</p>'; } if ($pages >= 1 && $page <= $pages) { for ($x=1; $x<=$pages; $x++) { echo ($x == $page) ? '<strong><a href="?page='.$x.'">'.$x.'</a></strong> ' : '<a href="?page='.$x.'">'.$x.'</a> '; } } Quote Link to comment Share on other sites More sharing options...
scootstah Posted May 31, 2012 Share Posted May 31, 2012 What is the error? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted May 31, 2012 Share Posted May 31, 2012 Instead of just saying "there's an error", how about posting the actual error message? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted May 31, 2012 Author Share Posted May 31, 2012 Thanks, Im been playing with a bit more and now when I ech the follow it just echoes the first items once but not the echo inside the DIV. It should echo echo line for 15 different results. echo '<p>', $query_row['name'] ,'</p>'; echo '<p>', $query_row['rrp'] ,'</p>'; echo '<p>', $query_row['image_link'] ,'</p>'; echo '<p>', $query_row['discount'] ,'</p>'; echo '<div class="productimageborder"><a href="product.php?price=' . $query_row['name'] . '</div>'; Quote Link to comment Share on other sites More sharing options...
Drummin Posted May 31, 2012 Share Posted May 31, 2012 echo '<div class="productimageborder"><a href="product.php?price=' . $query_row['name'] . '</div>'; Ahh.. maybe missing a little something here? echo '<div class="productimageborder"><a href="product.php?price=' . $query_row['price'] . '">' . $query_row['name'] . '</a></div>'; Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted May 31, 2012 Author Share Posted May 31, 2012 Weldone matey, It now echoes it inside the DIV but it doesn't echo the price, only the name. But its a step forwards. Quote Link to comment Share on other sites More sharing options...
Drummin Posted May 31, 2012 Share Posted May 31, 2012 Well just add price to your query assuming you have a field name price. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted May 31, 2012 Author Share Posted May 31, 2012 Yes that would help! Now I just need to the productrangeborder DIV, I have tried this as below but it kicks back an unexpected T_ECHO So I take Im putting it in way. '<div class="productrangeborder">' echo '<div class="productdetailsborder"><a href="product.php?product_id=' . $query_row['product_id'] . '">' . $query_row['name'] . '</a></div>'; echo '<div class="productimageborder"><a href="product.php?product_id=' . $query_row['product_id'] . '"><img src="' . $query_row['image_link'] . '"/></a></div>'; echo '<div class="priceborder">' . $query_row['rrp'] . '</div>'; echo '<div class="discountborder">' . $query_row['discount'] . '</div>'; '</div>' Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted May 31, 2012 Author Share Posted May 31, 2012 Or I could just do this. echo '<div class="productrangeborder"><div class="productdetailsborder" Getting there with it. This PHP is knackering stuff. Quote Link to comment Share on other sites More sharing options...
Drummin Posted May 31, 2012 Share Posted May 31, 2012 Just got to watch those semi-colons at the end of lines and echo where you mean to. echo '<div class="productrangeborder">'; echo '<div class="productdetailsborder"><a href="product.php?product_id=' . $query_row['product_id'] . '">' . $query_row['name'] . '</a></div>'; echo '<div class="productimageborder"><a href="product.php?product_id=' . $query_row['product_id'] . '"><img src="' . $query_row['image_link'] . '"/></a></div>'; echo '<div class="priceborder">' . $query_row['rrp'] . '</div>'; echo '<div class="discountborder">' . $query_row['discount'] . '</div>'; echo '</div>'; Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted May 31, 2012 Author Share Posted May 31, 2012 Oh I see, I didn't know it could be dont like that. Thanks. Does the pagination have to be insider the PHP for the echo then. Echoing column by column is so much easier. <?php echo $row['product_id']; ?> Quote Link to comment Share on other sites More sharing options...
Drummin Posted May 31, 2012 Share Posted May 31, 2012 Oh I see, I didn't know it could be dont like that. Thanks. Does the pagination have to be insider the PHP for the echo then. Echoing column by column is so much easier. <?php echo $row['product_id']; ?> Yes, any php coding or echo's need to be inside <?php ?> tags. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted May 31, 2012 Author Share Posted May 31, 2012 Thanks, but do they need to be inside these {} This is what Im having real problem with. All the code is set insider these tags. Can I use these, what is the simplest way to echo this inside of PHP surrounded by HTML. <php } ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted May 31, 2012 Share Posted May 31, 2012 THIS explains proper use of curly braces in a string. Quote Link to comment Share on other sites More sharing options...
silkfire Posted June 1, 2012 Share Posted June 1, 2012 Sigh Gareth...echoing HTML with PHP is a nasty habit. And people think you're trolling, too. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted June 1, 2012 Author Share Posted June 1, 2012 Thanks, I'm just looking for the simplest way to do this. I did read through the guide but I can't see where I can seperate the curly tags from HTML. Do you how I can do this please. I have the product display and the pagination code so I just to fit it together. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.