0

I have two tables , Names and Pics

Names table :

enter image description here

Pics table :

enter image description here

I would like to write a function in the php(by using sql) that it gets an id and return a result like this :

//suppose I sent 1 to this function...

result = array("name"=>"Name1","pics"=>"url6-url7");

There are hyphen in the URLS.

any helps?

3
  • 4
    what have u tried so far ? Commented Sep 19, 2014 at 10:15
  • I just know : $sql = "select * from Names,Pics where Names.ID = Pics.Name_ID"; Commented Sep 19, 2014 at 10:25
  • select * from Names,Pics where Names.ID = Pics.Name_ID AND Names.ID=$inputId Commented Sep 19, 2014 at 10:33

3 Answers 3

2
`Try this code its working 

SELECT GROUP_CONCAT(category.pics SEPARATOR '-') as newpics, company.id as searchid FROM `category` inner join  company on (company.id = category.cmp_id) where category.cmp_id = 2
Sign up to request clarification or add additional context in comments.

Comments

1
function whatIsThis($id){
   global $db;
   $sql = "select name, pics from names,pics where names.ID = pics.Name_ID AND names.ID = ".$id;
   $res = $db->query($sql);
   // Logic starts here...
   foreach($res as $rk=>$rv){ 
      $result['name'] = $rv['name'];
      $r[] = $rv['pics'];
   }
   $result['pics'] = implode('-',$r);
   return $result;
}
$iWant = whatIsThis('1');

I've used my own database class for query, you can use your own..
$iWant will return array as you need!

Comments

0

Considering your sql result in $sql, use var_dump to print the result and you will get the output result in the form of array that you want :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.