Note that there are some explanatory texts on larger screens.

plurals
  1. POShow three images from each user
    text
    copied!<p>I have a pictures table where users pictures are saving with their ID and pic physical link.</p> <pre><code>userID | picture 1 | picnameLink 1 | picnameLink 2 | picnameLink 1 | picnameLink 2 | picnameLink 3 | picnameLink </code></pre> <p>Now, I want to show maximum 3 pictures in a jquery picture gallery block where one block should show all 3 pictures from one same user and if a user have less than 3 pictures, it should show no image text.</p> <p>I have tried to do with group by mysql query but I am not getting desired result. Do I have to use two loops?</p> <p>--Edit for fthiella-- Here is code</p> <pre><code>$query = "SELECT * FROM pictures GROUP BY userID"; $result = mysql_query($query); while($row = mysql_fetch_array($result)){ $image_array[] = $row['picLink']; $id_array[] = $row['pic_id']; } $num_images_to_display = 3; /* MODIFY TO REFLECT NUMBER OF IMAGES TO SHOW PER SCREEN */ $num_images = count($image_array); $image_path = "../images/"; /* MODIFY TO REFLECT THE PATH TO YOUR IMAGES */ $y = $num_images_to_display; if(!isset($_GET['first'])){ $first = 0; }else{ $first = (int) $_GET['first']; } $x = $num_images - 1; $z = $x - $y; if($first&gt;$z) { $first = $z; } $last = $first + $num_images_to_display; </code></pre> <p>And here is HTML area:</p> <pre><code>&lt;div style="position:absolute; top:50px; left:100px; width:800px; text-align: center;"&gt; &lt;?PHP $i = $first; while($i&lt;$last) { $showme = $image_path . $image_array[$i]; ?&gt; &lt;?php if($image_array[$i]!="") { ?&gt;&lt;img src="&lt;?PHP echo $showme; ?&gt;" width="176px" height="197px"&gt;&lt;?php } else { ?&gt;&lt;img src="../image/no_image.jpg" width="176px" height="197px"&gt;&lt;?PHP } ?&gt; $prev = $first-1; $next = $first +1; if($prev&lt;0){ $prev = 0; } ?&gt; &lt;/div&gt; </code></pre> <p>Result of this query shows pictures in groups but I want maximum three pictures of each user where no image shows if a user has less than three images.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload