inserting into rows and columns

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
naz
Forum Newbie
Posts: 11
Joined: Fri Feb 18, 2005 11:16 am

inserting into rows and columns

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have a read through the Useful Posts thread (linked to in my signature). Your answer, with code, lies within.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

You could use a div tag and set float: left and let the images tile themselves.
naz
Forum Newbie
Posts: 11
Joined: Fri Feb 18, 2005 11:16 am

still stuck!!! please help

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
naz
Forum Newbie
Posts: 11
Joined: Fri Feb 18, 2005 11:16 am

Post by naz »

still stuck plase help
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what have you done since? I told you what needed to be changed.
naz
Forum Newbie
Posts: 11
Joined: Fri Feb 18, 2005 11:16 am

Post 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
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post 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>";
Post Reply