Jump to content

How to store row/column of mysql data in array


gaya

Recommended Posts

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

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 by gaya
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...