[thelist] php display 3x2

Andrew Maynes andrew at humanbehaviour.co.uk
Mon Dec 2 12:34:01 CST 2002


can someone point me in the right direction for displaying the results of this
table so that it is 3x2 only

I have changed everything and it just aint happening
http://www.hificollective.co.uk/books/books.php

code is: Courtesy of Jay :)

<?php
//connect to & select database
if(!($connect = mysql_pconnect("localhost", "root", "xxx"))){
	print("Failed to connect to database!\n");
	exit();
	}
if(!mysql_select_db("hifi", $connect)){
	print("Failed to select database!\n");
	exit();
	}
// do the query
$sql = "SELECT image, title FROM book_shop ";
$result = mysql_query($sql, $connect);

print("<table>");

//set a base number to keep track of the columns
$record_column == 3;
while($row = mysql_fetch_object($result)){
// how many columns do we want...3
   if($record_column <=3){
//if this is the first column we need to print the table row tag
      if($record_column == 0){
         print("<tr>");
      }
// print out 3 books for this column with proper tags
      print("<td>" . $row->image . $row->title . "</td>");
// increase the column number by one and get the next record
      $record_column++;
   } else {
// if there are 3 columns (like set above) then print the end tag
      print("</tr>\n");
// reset the column record to begin new row
	  $record_column = 1;
   }
}
print("</table>");
?>





More information about the thelist mailing list