Jump to content

Recommended Posts

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 by White_Lily
Link to comment
https://forums.phpfreaks.com/topic/268892-cms-pagetype-problem/
Share on other sites

<?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 by White_Lily

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 by darkfreaks

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;
}
}
?>

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 ) {

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.