drummer101 Posted March 9, 2008 Share Posted March 9, 2008 <?php while($row = mysql_fetch_array($user_id)) if(in_array(19, $row)){ echo "ADMIN<br>"; } else { echo "NOT<br>"; } } else { echo "You have entered an invalid username/password combination"; } ?> $row is a sql select statement that will return a quantity of results > 2 right now the php codeblock returns, "ADMIN NOT NOT". I can't figure out how to get the loop to stop when it returns true. and continue looping until END or TRUE. Quote Link to comment https://forums.phpfreaks.com/topic/95173-in_array-help/ Share on other sites More sharing options...
laffin Posted March 9, 2008 Share Posted March 9, 2008 look at this line mysql_fetch_array($user_id) mysql_fetch_array requires a mysql resource, not a string/value u obtain a mysql resource with mysql_query Quote Link to comment https://forums.phpfreaks.com/topic/95173-in_array-help/#findComment-487470 Share on other sites More sharing options...
drummer101 Posted March 9, 2008 Author Share Posted March 9, 2008 okay I've changed fetch_array to query, however, the code snippet now returns blank, instead of any results =\ Quote Link to comment https://forums.phpfreaks.com/topic/95173-in_array-help/#findComment-487474 Share on other sites More sharing options...
laffin Posted March 9, 2008 Share Posted March 9, 2008 <?php $res=mysql_query("SELECT * FROM users where username='$user' AND pass='$pass'"); if($row = mysql_fetch_array($user_id)) if(in_array(19, $row)){ echo "ADMIN<br>"; } else { echo "NOT<br>"; } } else { echo "You have entered an invalid username/password combination"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/95173-in_array-help/#findComment-487478 Share on other sites More sharing options...
drummer101 Posted March 9, 2008 Author Share Posted March 9, 2008 One more question. Ran into a problem case checking. It appears that all of the results from $user_id aren't being returned, only the last one is. user_id's are matched to group ID's, so you might have User Group ID 5 6 5 8 5 10 6 6 7 8 7 10 How would I go about assigning all the group ID's of user 5 to an array? something like $this->sql->group_ids or am I way off base on that? Quote Link to comment https://forums.phpfreaks.com/topic/95173-in_array-help/#findComment-487493 Share on other sites More sharing options...
sasa Posted March 9, 2008 Share Posted March 9, 2008 try ... $admin = 'NOT<br>'; while ($row = mysql_fetch_array($user_id)) if(in_array(19, $row)) $admin = "ADMIN<br>"; echo $admin; } else { echo "You have entered an invalid username/password combination"; } Quote Link to comment https://forums.phpfreaks.com/topic/95173-in_array-help/#findComment-487498 Share on other sites More sharing options...
drummer101 Posted March 9, 2008 Author Share Posted March 9, 2008 Thanks so much sasa, I only have problem left to solve now, and thats how to get the loop to stop when it returns TRUE and execute until the entire array has been read if in_array returns false. Any tips? Quote Link to comment https://forums.phpfreaks.com/topic/95173-in_array-help/#findComment-487501 Share on other sites More sharing options...
drummer101 Posted March 9, 2008 Author Share Posted March 9, 2008 would <?php while($row = mysql_fetch_array($user_id)) if(in_array(19, $row)){ echo "ADMIN<br>"; break; } else { echo "NOT<br>"; } } else { echo "You have entered an invalid username/password combination"; } ?> Work? Quote Link to comment https://forums.phpfreaks.com/topic/95173-in_array-help/#findComment-487506 Share on other sites More sharing options...
drummer101 Posted March 9, 2008 Author Share Posted March 9, 2008 No edit button, arghhh But yes it does work. ninja edit: no mark topic as solved? Quote Link to comment https://forums.phpfreaks.com/topic/95173-in_array-help/#findComment-487526 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.