Page 1 of 1

php array help

Posted: Sat Dec 03, 2011 12:58 am
by kshitizgp
Array
(
[1] => Array
(
[id] => 2
[menu_name] => php
[type] => 2
[visible] => 1
)

guyz i have this array as output ...i want to change the code so that when i type id =2 the array should be

[2] =id
{
[menu_name] => php
[type] => 2
[visible] => 1
)

it should fetch from id =2 and give me the output ..please hlp sort of urgent


the code is <?php

$rs = mysql_query("select * from subject",$connection);

while( $ds = mysql_fetch_assoc($rs) )
{
$arrList[] = $ds;
}

echo '<pre>';
echo $arrList[2]['id'];///exit;
print_r($arrList);exit


/// help

Re: php array help

Posted: Sat Dec 03, 2011 5:37 am
by Celauran

Code: Select all

while ($ds = mysql_fetch_assoc($rs))
{
  $arrList[$ds['id']] = array('menu_name' => $ds['menu_name'], 'type' => $ds['type'], 'visible' => $ds['visible']);
}