0

Fetch all rows based on the query into an array and return single value

Query database for data

//----------------------------------------------------------------------
$result = mysql_query("SELECT * FROM $tableName");          query
$array = mysql_fetch_row($result);

fetch result In Array

$arr = array();
while ($row = mysql_fetch_assoc($result)) {
$arr2 = array();
foreach ($row as $val) $arr2[] = $val;
$arr[] = $arr2;
} 

Result Will Be

Array
(
[0] => Array
    (
        [0] => status_site
        [1] => 0
    )

[1] => Array
    (
        [0] => title_site
        [1] =>  Script
    )

[2] => Array
    (
        [0] => keys_site
        [1] => 
    )

  )

I need to make function that return element 0 to 1

 ex: function getsetting (title_site){
 return value script}
3
  • Try to replace $arr[] = $arr2; with $arr[$arr2[0]] = $arr2[1];. Is this the result you're looking for? Commented Feb 20, 2015 at 7:51
  • Tanks Amazing yes solved & changed then i'm use extract($arr) and get variable with easy $title_site Thanks Commented Feb 20, 2015 at 7:59
  • I've added it as an answer. Commented Feb 20, 2015 at 8:02

1 Answer 1

1

Replace the $arr[] = $arr2; with $arr[$arr2[0]] = $arr2[1];. That might solve your problem.

Sign up to request clarification or add additional context in comments.

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.