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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.