gaya Posted February 13, 2013 Share Posted February 13, 2013 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. $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. Link to comment Share on other sites More sharing options...
gaya Posted February 13, 2013 Author Share Posted February 13, 2013 (edited) I found out the solution for this $sql="select type from qtype";$result=mysql_query($sql);$var = array();while ($rw = mysql_fetch_array($result)) { $var[] = $rw['type'];}print_r ($var); But now i have to compare the two fields. $quer="select type from qtype whereid='$qtype'";$res=mysql_query($quer);if(mysql_num_rows($res)){while($row=mysql_fetch_array($res)){$qtype1=$row[0];}} In the above code i take the type corresponding to its id.I have to compare if the type is in the array, and if it is some conditions should be done. please tell me how to do this. Edited February 13, 2013 by gaya Link to comment Share on other sites More sharing options...
justsomeguy Posted February 13, 2013 Share Posted February 13, 2013 You can use in_array to check if an item is in an array: http://www.php.net/manual/en/function.in-array.php 1 Link to comment Share on other sites More sharing options...
gaya Posted February 14, 2013 Author Share Posted February 14, 2013 Thanks justsomeguy. I used the following code and compared the two values. for($i=0; $i<6;$i++){if($var[$i]==$str){ echo "welcome----".$str; $a=a.php;[/font]} Now i have to include another php file inside the if condition,storing the php file name in a variable like $a=a.php,and when clicking it have to open the corresponding output in which a.php file is needed. Any ideas please tell me. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 14, 2013 Share Posted February 14, 2013 You need to make the filename a string. You can use the variable with include, there's no problem with that as long as the path to the file is correct. 1 Link to comment Share on other sites More sharing options...
gaya Posted February 15, 2013 Author Share Posted February 15, 2013 I did it.Thanks justsomeguy. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now