Move to next record in array.

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
docwisdom
Forum Newbie
Posts: 6
Joined: Mon Jun 19, 2006 7:23 pm

Move to next record in array.

Post by docwisdom »

I have an SQL query with 3 records.
In this code, there are three rows to be displayed
echo $row['550img'];
echo $row['272img'];
echo $row['272img'];
What I need to happen is have it move to the next record for each of these.
So the 550img would be from record 1, the 272img from record 2, and the second 272img from record 3.

In asp I would use soemthing like recordset.movenext



Code: Select all

<? 
					$row = mysql_fetch_array($result);
					echo "<table width='100%'  border='0' cellspacing='5' cellpadding='0'>
                      <tr align='center'>
                        <td colspan='2'><a href='bigjohn.html'><img src='";
					echo $row['550img'];
					echo "' width='550' height='200' border='0'></a> </td>
                        </tr>
                      <tr>
                        <td width='50%' align='right'>
						  <a href='naturerangers.html'><img src='";
					echo $row['272img'];
					echo "' width='272' height='99' border='0'></a></td>
                        <td width='50%' align='left'><a href='tvproduct.php?prodid=1'><img src='";
					echo $row['272img'];
					echo "' width='272' height='99' border='0'></a></td>
                      </tr>
                    </table>";
					
					?>
                    <br>
Last edited by docwisdom on Fri Aug 04, 2006 6:15 pm, edited 1 time in total.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Code: Select all

mysql_data_seek()
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

docwisdom
Forum Newbie
Posts: 6
Joined: Mon Jun 19, 2006 7:23 pm

Post by docwisdom »

still no luck,

this:

Code: Select all

<?					
$query="SELECT * FROM `products` WHERE `type` = 'television' ORDER BY id DESC LIMIT 3";
$result=mysql_query($query);
?>

<? 
					$row = mysql_fetch_array($result);
					echo "<table width='100%'  border='0' cellspacing='5' cellpadding='0'>
                      <tr align='center'>
                        <td colspan='2'><a href='bigjohn.html'><img src='";
						mysql_data_seek($result, 0);
					echo $row['550img'];
					echo "' width='550' height='200' border='0'></a> </td>
                        </tr>
                      <tr>
                        <td width='50%' align='right'>
						  <a href='naturerangers.html'><img src='";
						  mysql_data_seek($result, 1);
					echo $row['272img'];
					echo "' width='272' height='99' border='0'></a></td>
                        <td width='50%' align='left'><a href='tvproduct.php?prodid=1'><img src='";
						mysql_data_seek($result, 2);
					echo $row['272img'];
					echo "' width='272' height='99' border='0'></a></td>
                      </tr>
                    </table>";
					
					?>
gives me this:
http://www.digitalmediafactory.net/television/index.php


the arrayiterator code makes absolutely no sense to me (kind of a noob)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Why are you not throwing those to the browser inside of a while loop?
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

You can try something like this to iterate over the result array:

Code: Select all

$query="SELECT * FROM `products` WHERE `type` = 'television' ORDER BY id DESC LIMIT 3";
$result=mysql_query($query); 

while ($row = mysql_fetch_array($result)) {

echo $row['column1'];
echo $row['column2'];

// Any other code you need

}
docwisdom
Forum Newbie
Posts: 6
Joined: Mon Jun 19, 2006 7:23 pm

Post by docwisdom »

I was using a while loop in the beginning but what it gave me was 3 groupings of 3 images.

Basically each product has two image sizes a 550 and a 272. I want the script to pull the most recent 3 entries in the table and for the first entry, display its 550 image, the second will show its 272 image and the third will show its 272 image as well.

So I need:
write 550 image path
go to next record
write 272 image path
go to next record
write 272 image path


thanks for your responses so far.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

So in the loop count what iteration you're on. When it's the first, output the 550.
Post Reply