Note that there are some explanatory texts on larger screens.

plurals
  1. POmysqli fetch records
    primarykey
    data
    text
    <p>This is regarding a post <a href="https://stackoverflow.com/questions/13980078/show-three-images-from-each-user">Show three images from each user</a> where there is a great solution for a same issues which I was having.</p> <pre><code>if ($stmt = $mysqli-&gt;prepare("SELECT p1.userID, p1.picture as pic1, p2.picture as pic2, p3.picture as pic3 FROM pictures p1 left join pictures p2 on p1.userID=p2.userID and p1.picture&lt;&gt;p2.picture left join pictures p3 on p1.userID=p3.userID and p1.picture&lt;&gt;p3.picture and p2.picture&lt;&gt;p3.picture GROUP BY p1.userID LIMIT ?,1")) { $stmt-&gt;bind_param("i", $first); $stmt-&gt;execute(); $stmt-&gt;bind_result($user, $pic1, $pic2, $pic3); $stmt-&gt;fetch(); $stmt-&gt;close(); } $mysqli-&gt;close(); ?&gt; &lt;div style="position:absolute; top:50px; left:100px; width:800px; text-align: center;"&gt; &lt;img src="&lt;?PHP echo (isset($pic1) ? $image_path.$pic1 : $no_image); ?&gt;" width="176px" height="197px"&gt; &lt;img src="&lt;?PHP echo (isset($pic2) ? $image_path.$pic2 : $no_image); ?&gt;" width="176px" height="197px"&gt; &lt;img src="&lt;?PHP echo (isset($pic3) ? $image_path.$pic3 : $no_image); ?&gt;" width="176px" height="197px"&gt; &lt;/div&gt; </code></pre> <p>I was wondering how can I also get pictureID as well in this query? E.g if I use pictures for voting, I would then have to get pictureID as well.</p> <p><strong>Answer after Supericy help:</strong>(if someone looking for same)</p> <pre><code>if ($stmt = $mysqli-&gt;prepare("SELECT p1.userID, p1.picture as pic1, p1.pictureID as pic1id, p2.picture as pic2, p2.pictureID as pic2id, p3.picture as pic3, p3.pictureID as pic3id FROM pictures p1 left join pictures p2 on p1.userID=p2.userID and p1.picture&lt;&gt;p2.picture left join pictures p3 on p1.userID=p3.userID and p1.picture&lt;&gt;p3.picture and p2.picture&lt;&gt;p3.picture GROUP BY p1.userID LIMIT ?,1")) { </code></pre> <p>And then bind it</p> <pre><code>$stmt-&gt;bind_result($user, $pic1, $pic1id, $pic2, $pic2id, $pic3, $pic3id); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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