Help with a loop...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Help with a loop...

Post 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>
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

The simple thing you're missing is the loop itself. ;)
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Post 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;
                                }

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that doesn't loop anything. it's a single pass.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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]().

:)
Post Reply