Jump to content

[SOLVED] table to do new row after 3 results


didgydont

Recommended Posts

hi all

using some of the code in http://www.phpfreaks.com/forums/index.php/topic,87036.0.html i manged to get the row to count but it does

not drop down to the new line after three images i echoed the the row count to make sure it was working instead it displays one item then drops down.

basicly it does

1

2

3

1

2

3

instead of

123

123

any ideas?

 

<html>
<head>
<title>OLD WORLD</title>
<link rel="stylesheet" type="text/css" href="site.css" />

<body>

</head>

<body>
<?php

include("connect.php");
include("toolbar.php");
echo "<h1 ALIGN=\"center\">Old World Chandliers</h1>";

$result = mysql_query("SELECT * FROM stock");
// $result = mysql_query("SELECT * FROM stock WHERE itemnumber='$itemnumber'");

$i=1;
while($row = mysql_fetch_array($result))

  {
      $itemnumber = $row['itemnumber'];
  $name = $row['name'];
  $image = $row['image'];

echo "<table border='0' ALIGN='center' cellpadding='5' cellspacing='0'>";


if ($i==1){echo "<tr>";}
  echo "<td><a href='http://autolpg.com.au/oldworld/item.php?itemnumber=$itemnumber'><img src='$image' alt='$name' width='200' height='170'></a>
<form action='item.php' method='post' width='200'>
  <input type='hidden' name='itemnumber' value='$itemnumber'>
  <input type='submit' VALUE='click here for more details' class=namesbtn>
  </form> row count is $i</td>";
if ($i==3){echo "</tr>";
     $i=0;
     }
$i++;

echo "</table>";
  }


?>
</body>

</html>

worked it out

 

<html>

<head>

<title>OLD WORLD</title>

<link rel="stylesheet" type="text/css" href="site.css" />

 

<body>

 

</head>

 

<body>

<?php

 

include("connect.php");

include("toolbar.php");

echo "<h1 ALIGN=\"center\">Old World Chandliers</h1>";

 

$result = mysql_query("SELECT * FROM stock");

// $result = mysql_query("SELECT * FROM stock WHERE itemnumber='$itemnumber'");

 

$i=1;

echo "<table border='0' ALIGN='center' cellpadding='5' cellspacing='0'>";

while($row = mysql_fetch_array($result))

 

  {

      $itemnumber = $row['itemnumber'];

  $name = $row['name'];

  $image = $row['image'];

 

 

if ($i==1){echo "<tr>";}

  echo "<td><a href='http://autolpg.com.au/oldworld/item.php?itemnumber=$itemnumber'><img src='$image' alt='$name' width='200' height='170'></a>

<form action='item.php' method='post' width='200'>

  <input type='hidden' name='itemnumber' value='$itemnumber'>

  <input type='submit' VALUE='click here for more details' class=namesbtn>

  </form> row count is $i</td>";

if ($i==3){echo "</tr>";

    $i=0;

    }

$i++;

 

 

  }

  echo "</table>";

 

 

?>

</body>

 

</html>

 

try

<?php
...
$i=1;
echo "<table border='0' ALIGN='center' cellpadding='5' cellspacing='0'>";
while($row = mysql_fetch_array($result)){
$itemnumber = $row['itemnumber'];
$name = $row['name'];
$image = $row['image'];
echo "<tr>";
echo "<td><a href='http://autolpg.com.au/oldworld/item.php?itemnumber=$itemnumber'><img src='$image' alt='$name' width='200' height='170'></a>
<form action='item.php' method='post' width='200'>
  <input type='hidden' name='itemnumber' value='$itemnumber'>
  <input type='submit' VALUE='click here for more details' class=namesbtn>
  </form> row count is $i</td>";
for ($i = 1; $i < 3; $i++){
	$row = mysql_fetch_array($result);
	if ($row){
		$itemnumber = $row['itemnumber'];
		$name = $row['name'];
		$image = $row['image'];
		echo "<td><a href='http://autolpg.com.au/oldworld/item.php?itemnumber=$itemnumber'><img src='$image' alt='$name' width='200' height='170'></a>
<form action='item.php' method='post' width='200'>
  <input type='hidden' name='itemnumber' value='$itemnumber'>
  <input type='submit' VALUE='click here for more details' class=namesbtn>
  </form> row count is $i</td>";
	} else echo '<td> </td>';

}
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>

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.