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>

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.