PDA

View Full Version : display results correctly


mat
09-08-2002, 03:35 AM
hello,

http://www.theory1.orcon.net.nz/gallery.gif

http://www.theory1.orcon.net.nz/result.gif

So after getting any records matching the productCollectionID in the database php is supposed to spit them back out in a gallery format similar to above.

when you output a result you basically echo/print that result plus what ever html formatting you want and then php will just output as many times as there are results. fine , but what if i wanted to do something like the gallery above? it would either just keep going off the side of the page or of the bottom of the page instead of going across 3 and then starting a new row,

do you see what i mean? can this be done somehow? of one of those squares is a result(recordset) is it possible to make it so that they output like above?


mat,

mordred
09-08-2002, 12:44 PM
I don't know what you are referring to - there seems to be an image or URL missing in your post.

freakysid
09-08-2002, 03:20 PM
something like:


$sql = "SELECT * FROM Foo";
$result = mysql_query($sql);
$i = 0;

while( $row = mysql_fetch_array($result) ) {
if ( $i == 0) {
// start the first row of output
// record 1 row 1 goes here
}
elseif ($i % 3 != 0) {
// start the next row of output
// record 1 of the next row goes here
}
else {
// start the next record on the same row
}
$i++;
}

// now that you have finished outputing the records
// if you are using a table structure to format the rows
// you might need to know how many records there were
// on the last row printed out.

$numRecordsLastRow = $i % 3;

:)

(untested code)

Ökii
09-08-2002, 07:02 PM
A tabular structure might look like

echo '<table border="blah" etc>';
$counta = 0; // set a counter to count each row returned
$maxperRow = 3; // number of records per tr row
while($row=mysql_fetch_array($result)){
if($counta==0) {echo '<tr>';}// start a row if counter at zero
echo '<td>'.$row["fieldname"].'<td>'; // echo all the info
if(++$counta==$maxperRow) {echo '</tr>';$counta=0;} // do a /tr and reset counter to zero when 3 rows have been echoed
}
if($counta!=0) {
echo '<td colspan="'.($maxperRow-$counta).'"> amp;nbsp; </td></tr>';
}
echo '</table>';

Just as freakysid stated, count each return and echo out a newline / </tr> whatever when the counter reaches your limit.

mat
09-08-2002, 11:48 PM
nice, i see :thumbsup:

mat,