Page 1 of 1

Help with a loop...

Posted: Fri Oct 08, 2004 10:49 am
by dardsemail
Okay - I'm having an absolute brain fart... I'm trying to do code for a loop and am stuck, stuck, stuck and I know I must be missing something SOOOOO simple.

I have started the code, but here's what I'd like to do, I'd like to have the page show one image at a time with a navigation bar below with links to click from image to image... Here's what I've got so far.

What I can't figure out is how to get it to show the image for the associated row number in the array. I know that this shouldn't be so difficult! I think once I get that, I can sort through creating the navigation bar.

Code: Select all

<?php
include ('connection/db.php');
$collection = $_GET['collection'];
$category = $_GET['category'];

$query = ("SELECT * FROM collection_tb WHERE collection = '$collection' AND piecetype = '$category'");
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);
$numRows = mysql_num_rows ($result);
?>
<table style="height:400px;" align="center" width="75%"  border="0" cellspacing="0" cellpadding="0">
	  	<tr>
	  		<td height="20px"></td>
		</tr>
		<tr>
	  		<td>
				<table align="center" border="0" cellpadding="0" cellspacing="0">
					<tr>
							<?php
							$rowNum = 0;
							if ($rowNum <= $numRows)
								{
							?>
						<td align="center"><img src="<?php echo $row['imageLinkMd'];?>" /></td>
						<td><?php echo $row['piecenum'];?></td>
							<?php
								$rowNum ++;
								echo $rowNum;
								}
							?>
					</tr>
				</table>
			</td>
		</tr>
      </table>

Posted: Fri Oct 08, 2004 10:51 am
by m3mn0n
The simple thing you're missing is the loop itself. ;)

Posted: Fri Oct 08, 2004 10:54 am
by dardsemail
wouldn't this be the loop?

Code: Select all

<?php
                            if ($rowNum <= $numRows)
                                {
                            ?>
                        <td align="center"><img src="<?php echo $row['imageLinkMd'];?>" /></td>
                        <td><?php echo $row['piecenum'];?></td>
                            <?php
                                $rowNum ++;
                                echo $rowNum;
                                }

?>

Posted: Fri Oct 08, 2004 10:56 am
by feyd
that doesn't loop anything. it's a single pass.

Posted: Fri Oct 08, 2004 11:06 am
by m3mn0n
See: [php_man]while[/php_man]()

There is examples of it in use with MySQL selecting at [php_man]mysql_fetch_array[/php_man]().

:)