Jump to content

need help on mysql php array please


pixeltrace

Recommended Posts

hi,

 

i need help on my array code. what i want is to show 6 results into the the number i indicated but it doesn't seem to work.

the result i want is something like this:

 

result 1          result 2          result 3

 

result 4          result 5          result 6

 

 

below is my code:

<?php

	$query = mysql_query("SELECT filename, title FROM jos_phocagallery WHERE published=1 ORDER BY RAND() LIMIT 6") or die(mysql_error());;
	$row = mysql_fetch_array( $query );

	$filename[] = $row["filename"];
	$title[] = $row["title"];	

	?>

<p>
<img class="demo-fp-img demo-left" src="/images/phocagallery/thumbs/phoca_thumb_m_<?php echo $filename[0]; ?>" alt="<?php echo $title[0]; ?>"  title="<?php echo $title[0]; ?>" border="0" />
<span class="demo-sep"> </span> 
<img class="demo-fp-img demo-left" src="/images/phocagallery/thumbs/phoca_thumb_m_<?php echo $filename[1]; ?>" alt="<?php echo $title[1]; ?>"  title="<?php echo $title[1]; ?>" border="0" />
<span class="demo-sep"> </span> 
<img class="demo-fp-img demo-left" src="/images/phocagallery/thumbs/phoca_thumb_m_<?php echo $filename[2]; ?>" alt="<?php echo $title[2]; ?>"  title="<?php echo $title[2]; ?>" border="0" />
                                                            </p>
                                                            
<p>
<img class="demo-fp-img demo-left" src="/images/phocagallery/thumbs/phoca_thumb_m_<?php echo $filename[3]; ?>" alt="<?php echo $title[3]; ?>"  title="<?php echo $title[3]; ?>" border="0" /><span class="demo-sep"> </span> 
<img class="demo-fp-img demo-left" src="/images/phocagallery/thumbs/phoca_thumb_m_<?php echo $filename[4]; ?>" alt="<?php echo $title[4]; ?>"  title="<?php echo $title[4]; ?>" border="0" /><span class="demo-sep"> </span> 
<img class="demo-fp-img demo-left" src="/images/phocagallery/thumbs/phoca_thumb_m_<?php echo $filename[5]; ?>" alt="<?php echo $title[5]; ?>"  title="<?php echo $title[5]; ?>" border="0" />
</p>

 

hope you could help me with this.

 

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/203189-need-help-on-mysql-php-array-please/
Share on other sites

I don't think you've understood how mysql_fetch_array works. It only returns 1 record per-call; meaning you need to loop through, calling it each time, until their are no more records. This is easily done with a while() loop:

 

while ($record = mysql_fetch_array($query))
{
    // do something
}

 

I'd read the manual and take a look at the examples.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.