Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As per new modification in the question try the following code.</p> <p> <p>First get the name you want to fetch records for in a variable, like user01-Diana</p> <pre><code>$name = "user01-Diana"; </code></pre> <p>now extract the text against which you want to search the record, like user01</p> <pre><code>$name = substr($name, 0, strpos($name, '-')); </code></pre> <p>now we will create a pattern against which we will have to match the images name in folder, in this case our patter is, '/user01/'</p> <pre><code>$pattern = "/$name/"; </code></pre> <p>now specify the path to your directly form the currnt file in <code>opendir</code> function</p> <pre><code>if ($handle = opendir('./userimg')) { //here we are matching user01 against the files in the directory while (false !== ($entry = readdir($handle))) { //those that get matched will be echoed below if(preg_match($pattern, $entry)) echo "&lt;br /&gt;".$entry; } closedir($handle); } </code></pre> <hr> <hr> <p>OLD code to match previous requirement </p> <p>First you will have to extract <code>user1</code> from <code>user01-Diana</code></p> <p>you can do this by,</p> <pre><code>$name = "user01-Diana"; $name = substr($name, 0, strpos($name, '-')); </code></pre> <p>Now you will get <code>user01</code> in <code>$name</code> variable.</p> <p>After that you can use the following query.</p> <pre><code>$sel = "SELECT * FROM tablename where imagename like '".$name."%'"; </code></pre> <p>also if you have data in same table somewhat like as below,</p> <p><img src="https://i.stack.imgur.com/X6bSV.png" alt="enter image description here"></p> <p>use the following query</p> <pre><code>Select t1.imagename from Table1 as t1 LEFT JOIN Table1 as t2 ON t1.imagename LIKE concat("'", substr(t2.username, 1,(LOCATE("-",t2.username)-1)) , "%'") WHERE t1.imagename IS NOT NULL ORDER BY t1.imagename </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.
    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