Page 1 of 1

inserting into rows and columns

Posted: Sun Feb 20, 2005 4:26 pm
by naz
i am fairly new to php and i have a minor problem and was wondering if any1 can give me some advice or some code would go down nicely.
my problem is that i am inserting some images into my webpage, that is working fine but i want my images to be inserted along side each other but only three along side each other and then when a fourth image is inserted it is inserted below the first one but my code is inserting images directly under each other all the time i want something like this

Code: Select all

image      image     image   

image      image     image and etc

but at the moment it is doing this

image
image
image
image

etc


this is the code for my whole page



Code: Select all

<html>
<head>
<title>Hanover Furniture</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<STYLE type="text/css">
<!--
A {
	text-decoration:none;
	font-weight: bold;
}
A:hover { color:#FF8000 }
.style1 {font-weight: bold}
-->
</STYLE>
<link href="nav.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
a:link {
	color: #000000;
}
.style5 {color: #000000}
-->
</style>

</head>


<body bgcolor="#FEFCD3"  vlink="white" alink="blue">
<?php
require("dbcon.php");
?>
<div id="Layer1" style="position:absolute; left:10px; top:49px; width:171px; height:22px; z-index:1"><span class="style1"><font size="5" color="#0000FF">HANOVER</font><font size="5" color="#0099FF">FURNITURE</font><font size="4"></font></span></div>
<p> </p>

<div id="Layer2" style="position:absolute; width:200px; height:43px; z-index:8; left: 441px; top: 12px;">

  
  <table width="203" height="36" border="0">
    <tr>
      <td height="30"><div align="center" bgcolor="white">
          <p class="style5">Quick Find </p>
      </div></td>
    </tr>
  </table>
</div>
<div id="Layer36" style="position:absolute; width:23px; height:25px; z-index:28; left: 608px; top: 50px;"><img src="go.gif" width="21" height="21"></div>
<div id="Layer37" style="position:absolute; width:160px; height:25px; z-index:29; left: 463px; top: 50px;">
  <form name="form1" method="post" action="">
    <input type="text" name="textfield">
  </form>
</div>
<p><br>
</p>
<div id="Layer11" style="position:absolute; width:646px; height:52px; z-index:10; left: 17px; top: 122px;" class="nav">
  <div align="center">View our  exclusive range of designer fabric sofas available from our showroom. To find out more about each particular sofa click on the sofa or the link.</div>
</div>
<table width="644" height="29" border="0" cellpadding="0" cellspacing="0">
  <tr align="right">
    <td width="800" bgcolor="#606060">
      <div align="right" class="nav"><a href="main frame.php"> <strong></strong>Home |</a> <a href="furniturelink.php">Furniture |</a> <a href="feedback.php" >Feedback |</a> <a href="contactus.php">Contact Us </a> </a> </div></td>
  </tr>
</table>

<br>
<br><br>

<?php
// Request the text from database
$result = mysql_query(
"SELECT  sofa_image,sofa_name FROM sofas");
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}


print '<table width="694" height="187" border="0" cellpadding="0" cellspacing="0">';
while($row = @ mysql_fetch_row($result))
{
$imgdir = 'http://linux2.inf.brad.ac.uk:59285/Unnamed%20Site%201/images/' . $rowї0];
$imgdir2 = 'http://linux2.inf.brad.ac.uk:59285/Unnamed%20Site%201/moreinfologo.gif';
//$link = '<a href= "http://lamp.inf.brad.ac.uk:59285/Unnamed%20Site%201/sofa%20pages/1111.php=' . $more . '"></a>';
$more = "<img width='65' height='15' border='0' src=$imgdir2 >";
  print '<tr>';
  print "<td width='214' height='133'><img width='213' height='132' border='0' src=$imgdir ></td>";
  print '<td width="214"></td>';
  print '<td width="214"></td>';
  print '</tr>';
  print '<tr>';
  print '<td height="21"><div align="left" class="nav">' . $rowї1] . ' ' . $more . ' </td>';}
  print "<td></td>";
  print '<td></td>';
  print '</tr>';
  print '</table>';
  
  ?>
</html>


can some one please help????????????


thanks in advance

p.s some code would be really helpful :cry:


feyd | please use

Code: Select all

tags while the

Code: Select all

tags are offline[/color]

Posted: Sun Feb 20, 2005 4:31 pm
by feyd
have a read through the Useful Posts thread (linked to in my signature). Your answer, with code, lies within.

Posted: Sun Feb 20, 2005 4:31 pm
by smpdawg
You could use a div tag and set float: left and let the images tile themselves.

still stuck!!! please help

Posted: Sun Feb 20, 2005 5:16 pm
by naz
feyd wrote:have a read through the Useful Posts thread (linked to in my signature). Your answer, with code, lies within.
i have tried but still stuck please have a quick look at my code and if it isnt a problem tell me what parts need changin for my code to insert the images in the format i want please

thanks in advance

Posted: Sun Feb 20, 2005 8:45 pm
by feyd
your loop is changed such that it mostly just output's table cells. Once you have that, add a counting mechanism that on the first of a row will output a new table row container, same with the last of the row. After all images are output, you will need to make sure to output a cell span if needed to cover any remaining cells.

Posted: Mon Feb 21, 2005 5:23 am
by naz
still stuck plase help

Posted: Mon Feb 21, 2005 8:19 am
by feyd
what have you done since? I told you what needed to be changed.

Posted: Thu Feb 24, 2005 9:46 am
by naz
i cant understand what ur tryinfg to tell me but i have left it and inserted the images direclty under each other cheers anyway

Posted: Thu Feb 24, 2005 12:36 pm
by mcog_esteban
if you want 3 result in each row, you have to do something like this:

Code: Select all

$i = 1;
echo "<table><tr>";
while($row = mysql_fetch_array($result))
&#123;

if($i % 3 == 0) //Every time modulos is zero create a new row
&#123;
   echo "</tr><tr><td>$row&#1111;'...']</td>";
&#125;
else //Fill row with n columns
&#123;
  echo "<td>$row&#1111;'.....']</td>";
&#125;
$i ++;

&#125;
echo "</table>";