Jump to content

Recommended Posts

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:

6cowpdh.png

 

Here is the output when I have as many as 6 entries being echoed:

5y88mci.png

 

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  ???

Link to comment
https://forums.phpfreaks.com/topic/67654-php-formatting-within-tables/
Share on other sites

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 :P

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>

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.