CodeMama Posted January 5, 2009 Share Posted January 5, 2009 First, is there a GREAT online directory of exact syntax that is searchable Here is what I am trying to do: I have a menu that if the adminID is 3, 20 or 24 it needs to load an admin only menu option, trying to use this code but it isn' t working: <?php if ($row->AdminID == '3, 24, 20') { ?> <tr> <td><div class="admin_link"><a href="AddAdmin.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Add Admin</a></div></td> </tr> <tr> <td><div class="admin_link"><a href="ViewAdmin.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View Admin</a></div></td> </tr> <?php } ?> and I have also tried this: <?php if ($row->AddEditAdmin == "YES") { ?> Should I just put a new query in? Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/ Share on other sites More sharing options...
GingerRobot Posted January 5, 2009 Share Posted January 5, 2009 Yeah, you can't do that. You must test each value explicitly: if($var == 4 || $var == 20 || $var == 24){ //do something } Alternatively, you can place the possible values in an array and use the in_array() function: $values = array(4,20,24); if(in_array($var,$values)){ //do something } At present, your code tests to see whether or not the value of $row->AdminID is the string "3, 24, 20". As for an online directory, there's always the manual. Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729882 Share on other sites More sharing options...
rhodesa Posted January 5, 2009 Share Posted January 5, 2009 if (in_array($row->AdminID,array(3,24,20)) { for beginners, check out: http://devzone.zend.com/node/view/id/627 for general php syntax, the PHP doc is pretty good: http://www.php.net/manual/en/ Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729883 Share on other sites More sharing options...
Mark Baker Posted January 5, 2009 Share Posted January 5, 2009 First, is there a GREAT online directory of exact syntax that is searchable There's an excellent online directory of exact syntax that is searchable and that you can access if you follow this link Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729886 Share on other sites More sharing options...
kenrbnsn Posted January 5, 2009 Share Posted January 5, 2009 Yes, it's the PHP Manual. If you're interested in a particular function, just put the name of the function at the end of the url, for example: http://www.php.net/substr As to your question, the best way of doing this (IMHO) is to use the in_array function: <?php if (in_array($row->AdminID,array(3,24,20)) { ?> Ken (beaten...) Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729887 Share on other sites More sharing options...
CodeMama Posted January 5, 2009 Author Share Posted January 5, 2009 Well interestingly and oddly enough, those suggestions broke my code and now nothing shows up, and yes I have error_reporting turned on and no errors are being printed to the browser (or anywhere) I get a blank page. ..any other clues I can use to get this figured out? Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729904 Share on other sites More sharing options...
GingerRobot Posted January 5, 2009 Share Posted January 5, 2009 Can you show us your new code? Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729916 Share on other sites More sharing options...
nadeemshafi9 Posted January 5, 2009 Share Posted January 5, 2009 cute, why dont you echo $row->AdminID before the if to see if it actualy has what u are looking for, there will be no error if there is no error lol Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729918 Share on other sites More sharing options...
revraz Posted January 5, 2009 Share Posted January 5, 2009 Your code was already broken with this if ($row->AdminID == '3, 24, 20') { Well interestingly and oddly enough, those suggestions broke my code and now nothing shows up, and yes I have error_reporting turned on and no errors are being printed to the browser (or anywhere) I get a blank page. ..any other clues I can use to get this figured out? Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729921 Share on other sites More sharing options...
nadeemshafi9 Posted January 5, 2009 Share Posted January 5, 2009 you could use ereg() somhow to check the string comparison in the if but for now as matey upstairs said if ($row->AdminID == '3' || $row->AdminID == '24' || $row->AdminID == '20') { Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729934 Share on other sites More sharing options...
nadeemshafi9 Posted January 5, 2009 Share Posted January 5, 2009 u could do this <?php $nums = array("3", "24", "20"); foreach($nums as $num) { if(ereg($num, $row->AdminID )) $isitin = 1; else $isitin = 0; } if ($isitin) { ?> <tr> <td><div class="admin_link"><a href="AddAdmin.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Add Admin</a></div></td> </tr> <tr> <td><div class="admin_link"><a href="ViewAdmin.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View Admin</a></div></td> </tr> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729940 Share on other sites More sharing options...
GingerRobot Posted January 5, 2009 Share Posted January 5, 2009 Yes, you could do that. But why on earth would you? That's one of the most convoluted pieces of code i've seen in my life Edit: Actually i lied. You couldn't do that. That would only check to see if $row->AdminID was 20, since your variable $isitin is overwritten every time. Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729941 Share on other sites More sharing options...
nadeemshafi9 Posted January 5, 2009 Share Posted January 5, 2009 convoluted ?, yes maybe but it works watchu sayin ? Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729945 Share on other sites More sharing options...
rhodesa Posted January 5, 2009 Share Posted January 5, 2009 convoluted ?, yes maybe but it works watchu sayin ? because it's a MUCH less efficient way of doing in_array() Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729946 Share on other sites More sharing options...
nadeemshafi9 Posted January 5, 2009 Share Posted January 5, 2009 Yes, you could do that. But why on earth would you? That's one of the most convoluted pieces of code i've seen in my life Edit: Actually i lied. You couldn't do that. That would only check to see if $row->AdminID was 20, since your variable $isitin is overwritten every time. quote true but its nearly there here u go <?php $nums = array("3", "24", "20"); $isitin = 0; foreach($nums as $num) if(ereg($num, $row->AdminID )) $isitin = 1; if ($isitin) { ?> <tr> <td><div class="admin_link"><a href="AddAdmin.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Add Admin</a></div></td> </tr> <tr> <td><div class="admin_link"><a href="ViewAdmin.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View Admin</a></div></td> </tr> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729947 Share on other sites More sharing options...
nadeemshafi9 Posted January 5, 2009 Share Posted January 5, 2009 convoluted ?, yes maybe but it works watchu sayin ? because it's a MUCH less efficient way of doing in_array() its much more extendibale, u can connect and stuff to db or somthing interesting if not stick with the simple if or || hein lol i thoght u were gona show me a one liner to make my code look crap i was worried there lol Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729950 Share on other sites More sharing options...
rhodesa Posted January 5, 2009 Share Posted January 5, 2009 ok...let me shorten your ereg code for you: <?php if(in_array($row->AdminID,array("3", "24", "20"))) { ?> <tr> <td><div class="admin_link"><a href="AddAdmin.php?AdminID=<?php echo $row->AdminID; ?>" target="mainFrame">Add Admin</a></div></td> </tr> <tr> <td><div class="admin_link"><a href="ViewAdmin.php?AdminID=<?php echo $row->AdminID; ?>" target="mainFrame">View Admin</a></div></td> </tr> <?php } ?> p.s. - to the OP - you were missing "row->" before AdminID in your HTML block (see above) Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729953 Share on other sites More sharing options...
nadeemshafi9 Posted January 5, 2009 Share Posted January 5, 2009 nice Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729956 Share on other sites More sharing options...
CodeMama Posted January 5, 2009 Author Share Posted January 5, 2009 Thanks everyone, I figured it out, my original try of using this: <?php if ($row->AddEditAdmin == "YES") { ?> Did end up working, the problem was that my query had ended on the page (does that make sense) because when I moved that chunk of menu options up on the page, it worked, but at the bottom of the menu (after a chunk of code that uses a different query) this chunk didn't work, so I just went with the rearrange and now I can try and figure out why the one query didn't continue to work, can queries not be nested on a page? Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729957 Share on other sites More sharing options...
nadeemshafi9 Posted January 5, 2009 Share Posted January 5, 2009 nice Thanks everyone, I figured it out, my original try of using this: <?php if ($row->AddEditAdmin == "YES") { ?> Did end up working, the problem was that my query had ended on the page (does that make sense) because when I moved that chunk of menu options up on the page, it worked, but at the bottom of the menu (after a chunk of code that uses a different query) this chunk didn't work, so I just went with the rearrange and now I can try and figure out why the one query didn't continue to work, can queries not be nested on a page? is this a third part software that u are modifying ? Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729958 Share on other sites More sharing options...
CodeMama Posted January 5, 2009 Author Share Posted January 5, 2009 No but the original application was written by the programmer that was here before I started, so I'm not the original coder, and I'm not sure if he modeled it after a 3rd party app or wrote it from scratch. Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729963 Share on other sites More sharing options...
nadeemshafi9 Posted January 5, 2009 Share Posted January 5, 2009 just look at the methods of the $row-> class and break it down ur gona have to get intimate with it, how long have u been working with php professionaly ? Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-729969 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 just look at the methods of the $row-> class and break it down ur gona have to get intimate with it, how long have u been working with php professionaly ? If $row is coming from the database it was probably retrieved with mysql_fetch_object not third party at all just a different way of pulling data out of the database. Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-730061 Share on other sites More sharing options...
nadeemshafi9 Posted January 6, 2009 Share Posted January 6, 2009 just look at the methods of the $row-> class and break it down ur gona have to get intimate with it, how long have u been working with php professionaly ? If $row is coming from the database it was probably retrieved with mysql_fetch_object not third party at all just a different way of pulling data out of the database. im just sugesting this may be the freamwork Model component of the MVC in place so it would be good to know it and use it in ur own code like it was made to do rather than revert to basic php which would be a waste of the nice work done by the previouse programmer. Quote Link to comment https://forums.phpfreaks.com/topic/139535-solved-help-with-syntax/#findComment-730697 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.