Jump to content

[SOLVED] Layout Help


unitedintruth

Recommended Posts

I have a mysql table written for images. The fields are id, image, title, comment.

 

I am needing to write a table that will lay the images in a page 3 wide and I am having trouble getting them to layout. I can get the data to lay out one image wide but not 3.

 

I understand I do this with an "i" variable but have no idea how to lay this out and can't find a tutorial for this anywhere on the web.

 

Can someone please help me with this?

 

Thanks,

Donnie

Link to comment
https://forums.phpfreaks.com/topic/138330-solved-layout-help/
Share on other sites

Considering I am very new to PHP and just learning, this is what I have now.

 

<?php
        $con = mysql_connect("localhost","username","password");
        if (!$con)
        {
        die('Could not connect: ' . mysql_error());
        }
        mysql_select_db("my_db", $con);
        $result = mysql_query("SELECT * FROM puppies
        WHERE approved='yes'");

        echo "<table border='1'>";
        while($row = mysql_fetch_array($result))
        {
        echo "<tr>";
        echo "<td width=\"150\" align=\"center\"><img src=\"http://www.americanmi-kiregistryassociation.com/images/puppy_pics/" . $row['photo'] . "\"><br />";
        echo "Date of Birth: " . $row['dob'] . "<br />";
        echo "Date Available: " . $row['doa'] . "<br />";
        echo "Puppy Number: " . $row['nbr'] . "</td>";
        echo "</tr>";
        }
        echo "</table>";

        mysql_close($con);
      ?>

 

The table fields had to change some to fit my needs. I need to make this read 3 wide rather than 1.

 

Thanks,

Donnie

Link to comment
https://forums.phpfreaks.com/topic/138330-solved-layout-help/#findComment-723302
Share on other sites

echo '<table style="border:1px solid black;"><tr>'; // don't use "<table border="1"> use CSS for that.
$count = 1;
while($row = mysql_fetch_array($result)) {
        echo '<td style="width:150px; align:center;"><img src="http://www.americanmi-kiregistryassociation.com/images/puppy_pics/' . $row['photo'] . '"><br />'; // again swapped out width="150" align="center" for CSS
        echo "Date of Birth: " . $row['dob'] . "<br />";
        echo "Date Available: " . $row['doa'] . "<br />";
        echo "Puppy Number: " . $row['nbr'] . "</td>";
	/*
		Just a simple loop to count which column we're on, if we're on the third, we need to end the row and
		reset our count back to 1 for the next row.
	*/
        if($count==3) {
            echo "</tr><tr>";
            $count=1;
        } else {
            $count++; // does the same thing as $count = $count + 1;
        }
}
echo "</tr></table>";

 

Merry Christmas.

Link to comment
https://forums.phpfreaks.com/topic/138330-solved-layout-help/#findComment-723343
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.