White_Lily Posted September 28, 2012 Share Posted September 28, 2012 (edited) Hi, I am currently developing a cms where people can edit their site however they please. I have just a small problem, within the database the table "pages" has a column named "pageType" the types range from 1-4. in my CMS i have a while that is supposed to check if the pageType is equal to 1 or 4, however my problem is, is its displaying pages that have a type that equals 2, which isnt supposed to happen. <?php echo "<h2>Default Pages</h2>"; $newVar = select("*", "pages", "pageType = 1 OR 4"); $num = mysql_num_rows($newVar); if($num != 0){ while($fetch = mysql_fetch_assoc($newVar)){ if($fetch["pageType"] == 1 OR 4){ if($fetch["active"] == 1){ echo "<div class='active'><img src='images/tick.png' /><a href='edit/edit-default-pages.php?name=".$fetch["name"]."'>".$fetch["name"]."</a></div>"; }else{ echo "<div class='non-active'><img src='images/cross.png' /><a href='edit/edit-default-pages.php?name=".$fetch["name"]."'>".$fetch["name"]."</a></div>"; } } } }else{ echo "<p>No Default Pages found.</p>"; } ?> The page can be seen at: http://www.janedealsart.co.uk/template/cms/ Edited September 28, 2012 by White_Lily Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/ Share on other sites More sharing options...
darkfreaks Posted September 28, 2012 Share Posted September 28, 2012 (edited) what happens when you do elseif($fetch['pageType'] == 2 OR 3) { echo "NO default page selected";} Edited September 28, 2012 by darkfreaks Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381618 Share on other sites More sharing options...
White_Lily Posted September 28, 2012 Author Share Posted September 28, 2012 Nothing changes... it then displaying all types, same as "1 or 4" displays 2 and 3 as well. "2 or 3" displays 1 and 4 as well as 2 and 3 Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381622 Share on other sites More sharing options...
darkfreaks Posted September 28, 2012 Share Posted September 28, 2012 (edited) have you tried the identical operator === if($fetch['pageType'] === 1 OR 4) { //***DO Stuff**// }else { echo 'no default pages found.'; } Edited September 28, 2012 by darkfreaks Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381624 Share on other sites More sharing options...
White_Lily Posted September 28, 2012 Author Share Posted September 28, 2012 Stays the same even with === Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381626 Share on other sites More sharing options...
White_Lily Posted September 28, 2012 Author Share Posted September 28, 2012 i changed one of the pages to type 11, and it was still being displayed Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381628 Share on other sites More sharing options...
darkfreaks Posted September 28, 2012 Share Posted September 28, 2012 is select a custom function can we see the code for that??? Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381629 Share on other sites More sharing options...
White_Lily Posted September 28, 2012 Author Share Posted September 28, 2012 (edited) <?php /*************************** *Select data from database ***************************/ function select($amount = "*", $table, $where = NULL, $order = NULL, $limit = NULL){ $query = "SELECT ".$amount." FROM ".$table; if($where != NULL){ $query .= " WHERE ".$where; } if($order != NULL){ $query .= " ORDER BY ".$order; } if($limit != NULL){ $query .= " LIMIT ".$limit; } $result = mysql_query($query); if($result){ return $result; }else{ return false; } } ?> Not sure the error is in this function as all the other pages using this function are working properly. Edited September 28, 2012 by White_Lily Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381630 Share on other sites More sharing options...
darkfreaks Posted September 28, 2012 Share Posted September 28, 2012 (edited) cleaned up the function abit not sure if it will help or not. <?php function select($amount = "*", $table, $where = NULL, $order = NULL, $limit = NULL){ $query = "SELECT ".$amount." FROM ".$table; if($where !== NULL){ $query .= " WHERE ".$where; } if($order !== NULL){ $query .= " ORDER BY ".$order; } if($limit !== NULL){ $query .= " LIMIT ".$limit; } $result = mysql_query($query); if($result!==FALSE){ return $result; }else{ return false; } } ?> Edited September 28, 2012 by darkfreaks Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381633 Share on other sites More sharing options...
White_Lily Posted September 28, 2012 Author Share Posted September 28, 2012 No difference. Im not sure where the problem is :/ Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381635 Share on other sites More sharing options...
darkfreaks Posted September 28, 2012 Share Posted September 28, 2012 print_r($newvar); what does it output? Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381637 Share on other sites More sharing options...
White_Lily Posted September 28, 2012 Author Share Posted September 28, 2012 print_r($newVar); outputs: Resource id #7 Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381638 Share on other sites More sharing options...
Barand Posted September 28, 2012 Share Posted September 28, 2012 if($fetch["pageType"] == 1 OR 4) NO! if( ($fetch["pageType"] == 1) OR ($fetch["pagetype"] == 4) ) Yes Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381641 Share on other sites More sharing options...
White_Lily Posted September 28, 2012 Author Share Posted September 28, 2012 O_O Didn't know that sort of if statment was possible. However it did work Barand, thank you. *Notes that one down* Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381644 Share on other sites More sharing options...
darkfreaks Posted September 28, 2012 Share Posted September 28, 2012 after researching you need to add mysql_fetch_array inside your select function. <?php function select($amount = "*", $table, $where = NULL, $order = NULL, $limit = NULL){ $query = "SELECT ".$amount." FROM ".$table; if($where !== NULL){ $query .= " WHERE ".$where; } if($order !== NULL){ $query .= " ORDER BY ".$order; } if($limit !== NULL){ $query .= " LIMIT ".$limit; } $result = mysql_query($query); $result_two =mysql_fetch_array($result); if($result_two!==FALSE){ return $result; }else{ return false; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381645 Share on other sites More sharing options...
Pikachu2000 Posted September 29, 2012 Share Posted September 29, 2012 what happens when you do elseif($fetch['pageType'] == 2 OR 3) { echo "NO default page selected";} That syntax isn't right. It should be: elseif( $fetch['pageType'] == 2 || $fetch['pageType'] == 3 ) { Quote Link to comment https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/#findComment-1381690 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.