imdead Posted January 14, 2012 Share Posted January 14, 2012 Hello, i created this script for a client and have ran into an annoying error with the results displaying on a new line for each result instead of side by side, any help is welcome Cheers <?php $subcat = mysql_real_escape_string(strip_tags(htmlspecialchars(protect($_GET['subcat'])))); $cat = mysql_real_escape_string(strip_tags(htmlspecialchars(protect($_GET['cat'])))); $sql = @mysql_query("SELECT * FROM cakes WHERE category =\"$cat\" AND sub_cat=\"$subcat\" ORDER BY id DESC"); while ($row = mysql_fetch_array($sql)) { $reference = $row['reference']; $image = $row['image']; echo ("<p><img src='./images/cakes/$image' height='289px' width='177px' alt='IMAGE OF CAKE'></img><br />"); echo ("<b>Reference:</b>$reference"."</p>"); } if (!$reference) { echo 'There are no cakes in this category yet.'; } ?> I know the errors only going to be something small i'm missing, but i've been coding all day Quote Link to comment https://forums.phpfreaks.com/topic/255032-phpmysql-result-on-same-line/ Share on other sites More sharing options...
blacknight Posted January 14, 2012 Share Posted January 14, 2012 <br /> = new line Quote Link to comment https://forums.phpfreaks.com/topic/255032-phpmysql-result-on-same-line/#findComment-1307681 Share on other sites More sharing options...
imdead Posted January 14, 2012 Author Share Posted January 14, 2012 That br is for the text, not for the next image Quote Link to comment https://forums.phpfreaks.com/topic/255032-phpmysql-result-on-same-line/#findComment-1307682 Share on other sites More sharing options...
blacknight Posted January 14, 2012 Share Posted January 14, 2012 try taking out your <p> tages same idea makes paragraphs under each other Quote Link to comment https://forums.phpfreaks.com/topic/255032-phpmysql-result-on-same-line/#findComment-1307685 Share on other sites More sharing options...
imdead Posted January 14, 2012 Author Share Posted January 14, 2012 I've tried taking the <P> tags out, and this was the result Quote Link to comment https://forums.phpfreaks.com/topic/255032-phpmysql-result-on-same-line/#findComment-1307686 Share on other sites More sharing options...
blacknight Posted January 14, 2012 Share Posted January 14, 2012 ever think of using a table? $html = '<table><tr>'; $cols = 3;// can be any size you want $x = 0; while ($row = mysql_fetch_array($sql)) { $x++; $reference = $row['reference']; $image = $row['image']; $html .= '<td>'; $html .= '<p><img src="./images/cakes/'.$image.'" height="289px" width="177px" alt="IMAGE OF CAKE"></img><br />'; $html .= '<b>Reference:</b>'.$reference.'.</p>'; $html .= '</td>'; if ($x == $cols) { $html .= '</tr><tr>'; $x=0; } } if (!$reference) { $html .= '<td>There are no cakes in this category yet.</td>'; } echo $html; Quote Link to comment https://forums.phpfreaks.com/topic/255032-phpmysql-result-on-same-line/#findComment-1307692 Share on other sites More sharing options...
imdead Posted January 14, 2012 Author Share Posted January 14, 2012 aha with some slight changes thats got it thankyou very much, with the cols though depending on how many it needs, should i use a count first and then use the result as the var? Quote Link to comment https://forums.phpfreaks.com/topic/255032-phpmysql-result-on-same-line/#findComment-1307696 Share on other sites More sharing options...
blacknight Posted January 14, 2012 Share Posted January 14, 2012 no i would set this for page width it sets how many colums you have going across the page 3-5 is usualy good depending on the size of the page Quote Link to comment https://forums.phpfreaks.com/topic/255032-phpmysql-result-on-same-line/#findComment-1307698 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.