Firstly, thanks so much for helping me solve this. I had been trawling for ages through manuals and tutorials but was unable to find the answer. Within hours of joining this forum and posting a message the problem has now been sorted.
I did say that I would report back - just in case anyone else can benefit from it.
To have full control over the display I particularly needed a html table. There was a very similar problem addressed in the useful posts link that Jcart suggested:
viewtopic.php?t=29816
I adapted this to use in my script which now displays the desired table containing photos 3 across and as many rows as it needs to display the number of photos recalled from the database search.
The complete script is as follows:
Code: Select all
<?php
// retrieve form data in a variable
$input = $_POST['number'];
// print it
echo "Race no: <i>$input</i>";
// open connection to MySQL server
$connection = mysql_connect('localhost', 'admin', 'W3BMSs28')
or die ('Unable to connect!');
// select database for use
mysql_select_db('races2') or die ('Unable to select database!');
$query = "SELECT photoID FROM pics WHERE comp1= {$_POST[number]} or comp2= {$_POST[number]} or comp3= {$_POST[number]} ";
$result = mysql_query($query)
or die ('Error in query: $query. ' . mysql_error());
// check if records were returned
if (mysql_num_rows($result) > 0)
{
// print HTML table
echo '<table width=200 cellpadding=10 cellspacing=0 border=1>';
$rowmax = 3;
for($x = 0; $row = mysql_fetch_row($result); $x++)
{
if($x % $rowmax == 0)
echo '<tr>';
echo '<td><IMG SRC="images/DSCN' .$row[0]. '.jpg" WIDTH=113 HEIGHT=150 VSPACE=0 ALT="yourraceday.co.uk"></td>';
if($x % $rowmax == $rowmax - 1)
echo '</tr>';
}
if($left = (($howmany + $rowmax - 1) % $rowmax))
echo '<td colspan="' . $left . '"> ' . ";</td>\n</tr>\n\n";
echo '</table>';
}
else
{
// print error message
echo 'No rows found!';
}
// once processing is complete
// free result set
mysql_free_result($result);
// close connection to MySQL server
mysql_close($connection);
?>
I hope this may be helpful and thanks again guys!