Page 1 of 1

Move to next record in array.

Posted: Fri Aug 04, 2006 3:07 pm
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>

Posted: Fri Aug 04, 2006 6:11 pm
by Luke

Code: Select all

mysql_data_seek()

Posted: Fri Aug 04, 2006 6:52 pm
by wtf

Posted: Fri Aug 04, 2006 6:52 pm
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)

Posted: Fri Aug 04, 2006 10:06 pm
by RobertGonzalez
Why are you not throwing those to the browser inside of a while loop?

Posted: Sat Aug 05, 2006 7:28 am
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

}

Posted: Tue Aug 08, 2006 5:02 pm
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.

Posted: Tue Aug 08, 2006 5:04 pm
by feyd
So in the loop count what iteration you're on. When it's the first, output the 550.