How can i select multiple values from DB..?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dilruk83
Forum Newbie
Posts: 13
Joined: Thu Oct 30, 2008 6:44 am

How can i select multiple values from DB..?

Post by dilruk83 »

This is my table which contain two column named router and routet_Desc.
-----------------------
router routet_Desc
r1 a
r1 b
r1 c
r1 d

Then i wanna select that all routet_Desc according to router name.How can i do that..?
If i select r1 result should be a,b,c,d.I wanna put those result to array.How can i do that..?
if $router=array();

i wanna get $router[0]=a ,$router[1]=b.......etc


Please help me to do this..

Thanking you alll
robnet
Forum Commoner
Posts: 85
Joined: Mon Aug 10, 2009 8:32 am
Location: South East, UK

Re: How can i select multiple values from DB..?

Post by robnet »

What have you got so far?

What database are you using?
dilruk83
Forum Newbie
Posts: 13
Joined: Thu Oct 30, 2008 6:44 am

Re: How can i select multiple values from DB..?

Post by dilruk83 »

This is my query for mysql Database
$Select_VirtualRouters=mysql_query("SELECT routet_Desc FROM table_name WHERE router='r1' ");

while (list($vrouter)=mysql_fetch_array($Select_VirtualRouters))
{
echo $vrouter;
}


I got the out put : abcd , that is mean all router_Desc as list/string.

but i wanna get out put as array. That is mean Myarray[0]=a , Myarray[1]=b ,Myarray[2]=c ,Myarray[3]=d

because i'm going to assign those router_Desc to four string variables.

Thank you
robnet
Forum Commoner
Posts: 85
Joined: Mon Aug 10, 2009 8:32 am
Location: South East, UK

Re: How can i select multiple values from DB..?

Post by robnet »

Try changing your while loop to this:

Code: Select all

while ($result=mysql_fetch_array($Select_VirtualRouters)) {
 Myarray[]=$result['routet_Desc'];
}
dilruk83
Forum Newbie
Posts: 13
Joined: Thu Oct 30, 2008 6:44 am

Re: How can i select multiple values from DB..?

Post by dilruk83 »

Thank you very much friend......it was grt......really thanking you again..



Wishing you all the best in future...


TC..
Post Reply