iShaun Posted September 13, 2008 Share Posted September 13, 2008 Ok, i have a database setup like this: Name | Usergroup | Value ================================ can:view:cat:1 | 1 | 1 ----------------------------------- can:view:cat:2 | 1 | 1 what i want to do is be able to do: if($array['can:view:cat:1'] == '1') { return true; } can PHPFreaks help me? Link to comment https://forums.phpfreaks.com/topic/124010-array-help/ Share on other sites More sharing options...
LooieENG Posted September 13, 2008 Share Posted September 13, 2008 <?php $result = mysql_query("SELECT * FROM tablename WHERE Name = 'can:view:cat:1'"); $row = mysql_fetch_array($result); if ($row['Usergroup'] == 1) { // do stuff } ?> Is that what you mean? Link to comment https://forums.phpfreaks.com/topic/124010-array-help/#findComment-640203 Share on other sites More sharing options...
iShaun Posted September 13, 2008 Author Share Posted September 13, 2008 That won't loop, it will only do it once, im looking for like: foreach($permissions as $permission) { $this->permission[$permission['name']] = $permission['value'] } but that doesn't work Link to comment https://forums.phpfreaks.com/topic/124010-array-help/#findComment-640207 Share on other sites More sharing options...
iShaun Posted September 13, 2008 Author Share Posted September 13, 2008 Bump? Link to comment https://forums.phpfreaks.com/topic/124010-array-help/#findComment-640214 Share on other sites More sharing options...
LooieENG Posted September 13, 2008 Share Posted September 13, 2008 Ah <?php $result = mysql_query("SELECT * FROM tablename ORDER BY Name"); $row = mysql_fetch_array($result); for ($i = 1; $i < mysql_num_rows($result); $i++) { if ($row['Usergroup'] == 1) { // do stuff } } ?> Link to comment https://forums.phpfreaks.com/topic/124010-array-help/#findComment-640219 Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 Looie, that's the worst possible way to fetch results from a mysql database. First of all, you only call mysql_fetch_assoc() once, second of all, you call mysql_num_rows() EVERY SINGLE TIME you run the loop. Link to comment https://forums.phpfreaks.com/topic/124010-array-help/#findComment-640226 Share on other sites More sharing options...
LooieENG Posted September 13, 2008 Share Posted September 13, 2008 Woops, yeah. Always worked for me (when I do it right) What's the better way, I'd be happy to know. (once you solve this guy's problem) Thanks Link to comment https://forums.phpfreaks.com/topic/124010-array-help/#findComment-640241 Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 Woops, yeah. Always worked for me (when I do it right) What's the better way, I'd be happy to know. (once you solve this guy's problem) Thanks <?php //assume $result is a successful query resultset resource while ($row = mysql_fetch_assoc($result)) { //use $row in here } ?> Link to comment https://forums.phpfreaks.com/topic/124010-array-help/#findComment-640243 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.