Caffeine Posted September 2, 2007 Share Posted September 2, 2007 Hello everyone. I am trying to create a small control panel, for a customer to add products to his site using Paypal's auto generated HTML. Everything has gone well, I have an image uploader etc. but the formatting on output keeps breaking after a certain number of entries. I took some screenshots to help, not exactly eye-candy... but I've yet to implement it into the design I've created. Here is the output working: Here is the output when I have as many as 6 entries being echoed: My code looks like this: <table width="700" border="0" cellspacing="0" cellpadding="0"> <tr> <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("username_product", $con); $result = mysql_query("SELECT * FROM details ORDER BY id DESC"); while($row = mysql_fetch_array($result)) { /*echo nl2br("Item no: " . $row ['id']) . "<br>"; */ echo "<th scope='col'>"; echo nl2br($row ['name']); echo "<br>"; echo " <img src='"; echo nl2br(" " . $row ['image']); echo "' width='100' height='100'>"; echo "<br>"; echo nl2br("Description: " . $row ['description']); echo "<br>"; echo nl2br("Price: " . $row ['price']); echo "<br>"; echo nl2br($row ['paypal']); echo nl2br(" " . $row ['date']); echo "</th>"; } mysql_close($con); ?> </tr> </table> I know my PHP is dirty, but I wish I knew how to make it go onto a new line within my table or something. If someone could help, I would be gratefeul. Thank you in advance and thanks to those who took the time to read ??? Quote Link to comment https://forums.phpfreaks.com/topic/67654-php-formatting-within-tables/ Share on other sites More sharing options...
trq Posted September 2, 2007 Share Posted September 2, 2007 Check out this thread in the FAQ/Code snippet repository. get back to us if you have any problems. Quote Link to comment https://forums.phpfreaks.com/topic/67654-php-formatting-within-tables/#findComment-339834 Share on other sites More sharing options...
Caffeine Posted September 2, 2007 Author Share Posted September 2, 2007 Woops, I guess I should've done some more digging around. Thanks for the reply so quickly thorpe :] Quote Link to comment https://forums.phpfreaks.com/topic/67654-php-formatting-within-tables/#findComment-339837 Share on other sites More sharing options...
Timma Posted September 2, 2007 Share Posted September 2, 2007 Don't forget to press Topic Solved Quote Link to comment https://forums.phpfreaks.com/topic/67654-php-formatting-within-tables/#findComment-339847 Share on other sites More sharing options...
Caffeine Posted September 2, 2007 Author Share Posted September 2, 2007 If I ever get this damn thing to work Quote Link to comment https://forums.phpfreaks.com/topic/67654-php-formatting-within-tables/#findComment-339857 Share on other sites More sharing options...
Caffeine Posted September 2, 2007 Author Share Posted September 2, 2007 As you can see, I'm not much of a programmer and I'm very, very sorry about this double post. My code seems to now spit out the text I want, but it's not actually outputting anything from the database. I think I've done something wrong ??? I also have read the rules and know that massive scripts are not allowed to be posted, I hope this one is small enough for me not to get into any trouble I'm grateful for you guys helping me and stuff <table cellspacing="3" cellpadding="3"> <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("caffein_product", $con); $query = "SELECT * FROM details ORDER BY id"; $result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($product != "" && $product != null) echo "<td>$product</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; echo nl2br($row ['name']); echo "<br>"; echo " <img src='"; echo nl2br(" " . $row ['image']); echo "' width='100' height='100'>"; echo "<br>"; echo nl2br("Description: " . $row ['description']); echo "<br>"; echo nl2br("Price: " . $row ['price']); echo "<br>"; echo nl2br($row ['paypal']); } mysql_close($con); ?> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/67654-php-formatting-within-tables/#findComment-339871 Share on other sites More sharing options...
wildteen88 Posted September 2, 2007 Share Posted September 2, 2007 You have to modify the code in the FAQ to your code. You cannot use the code unmodified. EDIT try the following: <table cellspacing="3" cellpadding="3"> <?php $con = mysql_connect("localhost","username","password") or die('Could not connect: ' . mysql_error()); mysql_select_db("caffein_product", $con); $query = "SELECT * FROM details ORDER BY id"; $result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 6; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; echo '<td>' . $row['name'] . '<br />'; echo '<img src="' . $row['image'] . '" width="100" height="100"><br />'; echo "Description: " . nl2br($row['description']) . '<br />'; echo 'Price: ' . $row['price'] . '<br />'; echo $row['paypal']. '</td>'; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } mysql_close($con); ?> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/67654-php-formatting-within-tables/#findComment-339900 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.