Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2012
    Location
    chennai
    Posts
    55
    Thanks
    29
    Thanked 0 Times in 0 Posts

    How to store row/column of mysql data in array

    Hi,
    Please tell me how to store a column from db in array.
    My table name is qtype, and the fields in table are id & type.

    PHP Code:
    $sql="select type from qtype";
    $result=mysql_query($sql); 
    I had selected the type from table.
    There are some 6types in type field, and i have to store all the 6 in array.
    How shall i do this. Any ideas please tell me.
    Last edited by gayathri; 02-13-2013 at 11:55 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    PHP Code:
    $sql="select type from qtype";
    $result=mysql_query($sql) or die(mysql_error()); 
    while(
    $row=mysql_fetch_assoc($result)){
    $arrType=$row['type'];
    }

    print_r($arrType); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    gayathri (02-13-2013)

  • #3
    New Coder
    Join Date
    Nov 2012
    Location
    chennai
    Posts
    55
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Thanks for the reply Abduraooft.
    I got the result.
    Now I am having another column in same table. I need to compare both. I have to chech like if the type is in the array(), some conditions will have to do. How shall i do this. please tell me.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    I have to chech like if the type is in the array(), some conditions will have to do. How shall i do this. please tell me.
    Please explain your ultimate aim.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New Coder
    Join Date
    Nov 2012
    Location
    chennai
    Posts
    55
    Thanks
    29
    Thanked 0 Times in 0 Posts
    My ultimate aim is, I've already stored my type in another variable($var2). Just i need to check whether this $var2 is in the $arrType. I did it and the solution is
    PHP Code:
    for($i=0$i<6;$i++){
    if(
    $var[$i]==$str)
    {
        echo 
    "welcome----".$str;
            
    $a=a.php;

    Now i have to include another php file inside this if condition, storing the php file name in some variable like $a=a.php. and when clicking, it have to open the corresponding ouput in a.php file needed.
    Any ideas please tell me.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •