1

I have a CMS Page module and when you go to a page it shows it twice. This is what calls the function:

$pages = new pages;
if(isset($_GET['action']) && ($_GET['action'] == "pages")){
if($_GET['action'] === 'pages' && isset($_GET['page'])){
$pages->pages();
} elseif ($_GET['action'] === 'pages' && !isset($_GET['page'])) {
$pages->pagelist();
}
$pages->pagesAdminBar();

if(isset($_GET['mode'])){
if($_GET['mode'] == "edit"){
$pages->editPage();
}
if($_GET['mode'] == "addpage"){
$pages->addpage();
}
if($_GET['mode'] == "pageadmin"){
$pages->pageadmin();
}
$pages->pagesAdminBar();
}
}

and this is the function:

public function pages(){
    global $dbc, $parser, $layout, $main, $settings, $core;

        if(isset($_GET['page'])){
        $page = mysqli_real_escape_string($dbc, $_GET['page']);

        if(!isset($_GET['page']) && !isset($_GET['action'])){
        $page = $settings['home_display'];
        }
        $query = "SELECT * FROM pages WHERE pagename = '$page'";
        $data = mysqli_query($dbc, $query);

        while ($row = mysqli_fetch_array($data)) {

            echo '<div class="shadowbar">';
                echo'<h3>' . $row['pagename'] . '</h3>';
            $parsed = $parser->parse($row['body']);
                echo '<pre>'.$parsed.'</pre>';
            echo '</div>'; 
    }
    }
    }

but when I go to the page in the browser it shows the query data twice.

2 Answers 2

1

I think your code in pages() is called twice because your class doesn't have a constructor and you have two lines $pages = new pages; and $pages->pages(); producing same results.

Sign up to request clarification or add additional context in comments.

Comments

1

Try DISTINCT select data. It will merge same rows as one.

SELECT DISTINCT * FROM pages WHERE pagename = '$page'

Try this might be work because sometime when calling $rows = mysqli_fetch_array($data) in while loop must be problem.

public function pages(){
    global $dbc, $parser, $layout, $main, $settings, $core;

        if(isset($_GET['page'])){
        $page = mysqli_real_escape_string($dbc, $_GET['page']);

        if(!isset($_GET['page']) && !isset($_GET['action'])){
        $page = $settings['home_display'];
        }
        $query = "SELECT * FROM pages WHERE pagename = '$page'";
        $data = mysqli_query($dbc, $query);

        $row = mysqli_fetch_array($data);
        echo '<div class="shadowbar">';
        echo'<h3>' . $row['pagename'] . '</h3>';
        $parsed = $parser->parse($row['body']);
        echo '<pre>'.$parsed.'</pre>';
        echo '</div>'; 
    }
    }

8 Comments

Hmm, so it's still doing it, which tells me that there must be something telling it to display twice
It's still outputting twice. If you look at ded.ccp2.us/cb/… You'll see what I mean. It is outputting twice but I can't see why
@Cheesecake How many columns are there in your data? Besides pagename and body? Perhaps, your data has versions of same documents? Try select distinct pagename, body from pages where ... instead of selecting all fields. You can study results of the query in phpMyAdmin first to get some idea.
@TimothyHa The thing is, it shows what it should in PHPMyAdmin, but on the page it displays two. I'll edit my question to show all of the display settings
After changing it it shows a bunch of numbers and letters randomly. If you go the the same link above you'll see
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.