PHP - Multiple MySQL result, in separate variables -
i need mysql query search inexact match / match containing submitted value.
the following example of in database:
id img 1 1001_abc_01.jpg 2 1001_abc_02.jpg 3 1002_abc_01.jpg 4 1002_abc_02.jpg 5 1002_abc_03.jpg 6 1002_abc_04.jpg 7 1002_abc_05.jpg 8 1003_abc_01.jpg 9 1003_abc_02.jpg 10 1003_abc_03.jpg
i need query search first part of filename (1002
) , and assign each returned result in img field different variable. maximum amount of variables 5.
for example, if search 1002
, should assign following variables:
<?php $img1 = '1002_abc_01.jpg'; $img2 = '1002_abc_02.jpg'; $img3 = '1002_abc_03.jpg'; $img4 = '1002_abc_04.jpg'; $img5 = '1002_abc_05.jpg'; ?>
so way can echo each filename result individually.
again, maximum amount of variables here 5, if more 5 results returned, first 5 assigned variables.
please let me know if possible , how write php script it.
select img <table_name> img '%search%' order id desc limit 5;
you substring
function, if first 4 integers fixed this:
select substring(img,1,4) <table_name> img = 'search' order id desc limit 5;
Comments
Post a Comment