Member Avatar for LastMitch

Hi

I have a question. I don't know where to started. I recently installed CKEditor and would like to know how to create a Archive page.
It's kinda like a blog but for me it's kinda neat using the CKEditor.

For example:

Article: 

Hi ... page. 

I want to save that Article to the Archive.

I want to learn how to create a Archive page.

Any example will gave me an idea how this works.

So far this is the only way for me to learn php.

I really do appreciate if someone explained to me how this works!

Thanks

Recommended Answers

All 22 Replies

Member Avatar for diafol

You save the contents from the CKEditor and other fields to a DB.
The archive page just retrieves the info from the DB.

Member Avatar for LastMitch

@ Ardav

Thanks for the reply!

You save the contents from the CKEditor and other fields to a DB.

You mean once I created the article and I save it as a (name).php file in the DB? Is that right?

The archive page just retrieves the info from the DB.

Do I need to create a folder so the (name).php will directly save into it?

So everytime I saved a (name).php it will go directly to the folder I created.

To retrieve the (name).php I have to used something like this

 $sql= "SELECT * FROM pages WHERE pagename = ''";

and also this

mysql_fetch_array

or

mysql_fetch_assoc 

or

mysql_fetch_row

or

mysql_select_db

When you mention DB. This line always pop in my mind:

$sql= "SELECT * FROM pages WHERE pagename = ''";

This is the only thing I understand or start to write the first line after that I'm either lost or very lost.

Any example that I get learn from?

My MYSQL is awful I can try to read it and understand it but to write it is a bit of a challenge.

I really do appreciated your time answering my question!

Thanks

Member Avatar for diafol

You don't need to create a file for ach article. You just save all the info to a DB table called articles. This means you can easily create (insert), edit (update), delete articles.

The secret to displaying articles should be via parameters passed via form (e.g. search box) or link.

So you have just ONE page, let's call it articles.php:

articles.php?fetch=17

So you just use the $_GET var to extract that record from the db

if(isset($_GET['fetch'])){
    $get = intval($_GET['fetch']);
    $r = mysql_query("SELECT ... FROM articles WHERE id = $get");
    if(mysql_num_rows($r)){
        $d = mysql_fetch_assoc($r){
            //access the data via $d['...']
        }
    }
}

If you send via keyword search (for MyISAM tables only):

if(isset($_GET['fetch'])){
    $input = mysql_real_escape_string(trim($_GET['fetch']));
    $inputArray = explode(" ", $input); //or better to use preg_replace to REALLY work
    $strSQL = implode(" +",$inputArray);  
    $r = mysql_query("SELECT ... FROM articles WHERE MATCH(article_title, article_tags, article_body) AGAINST('+$strSQL' IN BOOLEAN MODE)");
    if(mysql_num_rows($r)){
        $d = mysql_fetch_assoc($r){
            //access the data via $d['...']
        }
    }
}

The above will work better if you apply indexes to the table fields (CREATE FULLTEXT INDEX).

Member Avatar for LastMitch

@ Ardav

Thanks for the reply! I really appreciated that you took your time to write and post this script!

You just save all the info to a DB table called articles.

So I just need to create a file called articles.php and put those 2 code you wrote in the file?

articles.php?fetch=17

So it's like this for example: www.daniweb.com/articles.php?fetch=1

Do I need to put "fetch=1" up to "fetch=xxxx" as many as I needed?

The above will work better if you apply indexes to the table fields (CREATE FULLTEXT INDEX).

I read that somewhere regarding about a table (CREATE FULLTEXT INDEX).

I forgot which site was that, there was an example of a script that has a table (CREATE FULLTEXT INDEX).

I will look into it, and get back to you if I can't run out the 2 scripts correctly.

Thanks again!

Member Avatar for LastMitch

@ Ardav

I apologize for not replying back. My home internet and phone serivce was down because of the weather, it's been raining and vey hot. I try to do this at work and never got a chance. I will look over the script that you posted either during lunch today. To see it how it goes.

FYI: Anti-Jubilee?

You got to give her credit for doing this for 60 years!

Diamond Jubilee of Elizabeth II is worth the same amount as Holy Tomato of Antioch (The Holy Hand Grenade of Antioch)!

Member Avatar for diafol

Doing what exactly for 60 years? Welsh and Scottish independence NOW. Stop this madness. Our last monarch died 800 years ago. We don't want more of them - especially foreign ones.

Member Avatar for LastMitch

@ Ardav

I ran in to some issues that I didn't notice til now.

I can't save any html files from CKeditor. The CKeditor works when I type something and published it but when I click on the menu link to the same page and it's blank.

Do I need to created another DB for that to work?

or I have to used a CMS to do that? The CMS it's a bit too much features for me to used. I only want to update two pages. One is home and the other is my hobby which is music. It's only html and php (is to upload music), the php is a simple upload script I created. I will post the script on the page.

Doing what exactly for 60 years?

She ran the UK for that long.

Welsh and Scottish independence NOW

Sir William Wallace won the battle over the Englishmen.

Our last monarch died 800 years ago

Was that Robert the Bruce?

Member Avatar for LastMitch

@ Ardav

This the backend page which on my admin section and it's called home.php.

<?php
session_start();
header("Cache-control: private");
require_once ('../include/init.php');
include_once("../ckeditor/ckeditor.php");?>

<html>
<head>
<title>ADMIN</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="/ckeditor/ckeditor.js?t=C3HA5RM"></script>
<style type="text/css">
<!--
.style3 {font-family: Arial, Helvetica, sans-serif;font-size: 16px;font-weight: bold;}
-->
</style>
</head>
<body>
<br>
<p align="center" class="style3">ADMIN </p>
<br>
<p align="center" class="style4">
<a href="index2.php">MAIN MENU</a>&nbsp;&nbsp;
<a href="logout.php">LOG OUT</a>
</p>
<? include("modifymenu.php");?>
<form action="../home.php" method="post" target="_blank">
<?php
$CKEditor = new CKEditor();
$CKEditor->basePath = '/ckeditor/';
$CKEditor->editor("textarea_id", "This is some sample text");
?>
<input type="submit" value="Submit">
<?
$initialized ['Enabled'] = true ; 
?>
</form>
</body>
</html>
Member Avatar for LastMitch

@ Ardav

This the frontend page

<?
session_start();
header("Cache-control: private");
include("../include/init.php");
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
<link href="css/style.css" type="text/css" rel="stylesheet">

</head>
<body>
<div id="leftcolumn"></div>
<div id="contentcolumn">
<? include("headerinc.php");?>
<div align="center">
<table>
<tr>
<td><?php echo $sValue = stripslashes( $_POST['editor1'] ) ;?></td>
</tr>
</table>
</div>

<? include("footerinc.php");?>
</div>
<div id="rightcolumn"></div>
</body>

</html>
Member Avatar for LastMitch

@ Ardav

My next question is about the article.php

On my** home.php** file in my admin section

Do I replace the

<form action="../home.php" method="post" target="_blank">

to

<form action="../article.php" method="post" target="_blank">

I really do appreciated that you are taking your time answering my question!

Thanks

Member Avatar for diafol

On vacation at the mo; so on phone. I'll be a few days before i can post code. Anyway in reply to your statements. Monarchs run nothing. We have a government to do that. Robert the Bruce was Scottish and they've had their own monarchs since. I was referring to Llywelyn Ein Llyw Olaf; killed at Cilmeri in 1282. This current Greek-German dynasty are about as worthy of my support as an unremarkable dried-out pile of sheep droppings. Don't get me started about the English Prince of Wales...

Member Avatar for LastMitch

@ Ardav

Thanks for the head up! I'll keep work on for the rest of the week and post the a different results. But, Thanks!

I was referring to Llywelyn Ein Llyw Olaf; killed at Cilmeri in 1282. This current Greek-German dynasty are about as worthy of my support as an unremarkable dried-out pile of sheep droppings. Don't get me started about the English Prince of Wales...

My European history is pretty out of date. I forgot what learn.

Saw this movie recently: Ironclad (film), it was pretty good, it does show some history about the Royal Empire.

I guess you still sing this song "Yma o Hyd" everyday.

Member Avatar for LastMitch

@ Ardav

Someone actually fixed my home phone and internet issue this morning. It's working now.

The two previous scripts I posted, there were some errors and not corrected. I will post the correct one on the bottom.

This is the article.php

<?php
session_start();
header("Cache-control: private");
require_once ('../include/init.php');
?>

<?php
if(isset($_GET['fetch'])){
    $get = intval($_GET['fetch']);
    $r = mysql_query("SELECT ... FROM articles WHERE id = $get");
    if(mysql_num_rows($r)){
    $d = mysql_fetch_assoc($r){
    //access the data via $d['...']
        }
    }
}

if(isset($_GET['fetch'])){
    $input = mysql_real_escape_string(trim($_GET['fetch']));
    $inputArray = explode(" ", $input); //or better to use preg_replace to REALLY work
    $strSQL = implode(" +",$inputArray);  
    $r = mysql_query("SELECT ... FROM articles WHERE MATCH(article_title, article_tags, article_body) AGAINST('+$strSQL' IN BOOLEAN MODE)");
    if(mysql_num_rows($r)){
    $d = mysql_fetch_assoc($r){
    //access the data via $d['...']
        }
    }
} 
?>

I got a error regarding about the $d I think I didn't identify it.

This is bit hard then I thought. The Ascending Order and Descending Order was bit easy because it has a database and some MYSQL script that I can work at for me to see how it works. For this example I have no database to work at. This is a bit of a challenge. I don't know where to start. I'll keep working on it and try to figure it out.

Member Avatar for LastMitch

@ Ardav

This is my backend section. This script is called home1.php and is in my admin section.

<?php
session_start();
header("Cache-control: private");
require_once ('../include/init.php');
include_once("../ckeditor/ckeditor.php");?>

<html>
<head>
<title>ADMIN</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="../ckeditor/ckeditor.js"></script>
<style type="text/css">
<!--
.style3 {font-family: Arial, Helvetica, sans-serif;font-size: 16px;font-weight: bold;}
-->
</style>
</head>
<body>
<br>
<p align="center" class="style3">ADMIN</p>
<br>
<p align="center" class="style4">
<a href="index2.php">MAIN MENU</a>&nbsp;&nbsp;
<a href="logout.php">LOG OUT</a>
</p>
<? include("modifymenu.php");?>
<form action="../home.php" method="post" target="_blank">
<?php
$CKEditor->basePath = '/ckeditor/';
$CKEditor = new CKEditor();
$CKEditor->editor("editor1", $initialValue);
$initialValue = '<p>This is some <strong>sample text</strong>.</p>';
?>
<input type="submit" value="Submit"/>
<?
// SECURITY: You must explicitly enable this "connector". (Set it to "true").
$initialized ['Enabled'] = true ; 
?>
</form>
</body>
</html>
Member Avatar for LastMitch

@ Ardav

This is my frontend section. This script is called home.php and it my homepage.

<?php
session_start();
header("Cache-control: private");
include("include/init.php");
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="../ckeditor/ckeditor.js"></script>
<link href="css/style1.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="leftcolumn"></div>
<div id="contentcolumn">
<? include("headerinc.php");?>
<div align="center">
<table>
<tr>
<td>
<?php
$editor_data = $_POST[ 'editor1' ];
echo $editor_data;
?>
</td>
</tr>
</table>
</div>
<? include("footerinc.php");?>
</div>
<div id="rightcolumn"></div>
</body>
</html>
Member Avatar for LastMitch

@ Ardav

I can't save any html files from CKeditor. The CKeditor works when I type something and published it but when I click on the menu link to the same page and it's blank. I shouldn't click "Solve" on my other thread.

Do I need to created another DB for that to work? I mean if it's a MYSQL, then do you have a sample for me to work at?

As for the article.php.

The letter d

What does the d stand for?

I apprecaite your insight and grateful that you are helping me.

Member Avatar for LastMitch

@ Ardav

I'm actually at church right now but

the past couple days I try to used this:

$d ="SELECT * FROM pages WHERE pagename = '".$page."'";
        while($rowcats = mysql_fetch_array($rscats))
        {
        $pagename = $rowcats["pagename"];
        }

to save the page but it won't work.

Do I need to created another DB for that to work? I mean if it's a MYSQL, then do you have a sample for me to work at?

As for the article.php.

The letter d

What does the d stand for?

I apprecaite your insight and grateful that you are helping me.

Member Avatar for diafol

I'm actually at church right now but

Asking for forgiveness for your community posts? Seriously uncool.

You can't use $rowcats in the snippet above to fetch results as you've not run the query yet. I guess you knew that being an IT Pro.

I use $r as a rule to hold the 'result resource' and $d for 'datarow'. It's personal preference, nothing else.

Bye.

Member Avatar for LastMitch

@ Ardav

Asking for forgiveness for your community posts? Seriously uncool.

I do bible study, then service there's a 15 minute break before the service starts. No, I don't accept calls or texts. I email during between the 15 minutes.

I guess you knew that being an IT Pro.

You a bit Sacrasm, I'm not in a mood for fighting. I do networking for a living.

I use $r as a rule to hold the 'result resource' and $d for 'datarow'. It's personal preference, nothing else.

I don't know what do?

Member Avatar for LastMitch

@ Ardav

I apologizes if I snap. I had a rough couple of days, today is Sunday. I just want to relaxed and work on this script.

<?php
session_start();
header("Cache-control: private");
require_once ('../include/init.php');
include_once("../ckeditor/ckeditor.php");?>

     $page = $_GET['page'];
     $sqlcats="SELECT * FROM pages WHERE pagename = '".$page."'";
     //echo $sqlcats;
     $rscats= mysql_query($sqlcats) ;

    while($rowcats = mysql_fetch_array($rscats))
    {
    $thetext = $rowcats["editor1"];
    $pagename = $rowcats["pagename"];
    }

<html>
<head>
<title>ADMIN</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="../ckeditor/ckeditor.js"></script>
<style type="text/css">
<!--
.style3 {font-family: Arial, Helvetica, sans-serif;font-size: 16px;font-weight: bold;}
-->
</style>
</head>
<body>
<br>
<p align="center" class="style3">ADMIN</p>
<br>
<p align="center" class="style4">
<a href="index2.php">MAIN MENU</a>&nbsp;&nbsp;
<a href="logout.php">LOG OUT</a>
</p>
<? include("modifymenu.php");?>
<form action="../home.php" method="post" target="_blank">
<?php
$CKEditor->basePath = '/ckeditor/';
$CKEditor = new CKEditor();
$CKEditor->editor("editor1", $initialValue);
$initialValue = '<p>This is some <strong>sample text</strong>.</p>';
 ?>
<input type="submit" value="Submit"/>
<?
// SECURITY: You must explicitly enable this "connector". (Set it to "true").
 $initialized ['Enabled'] = true ;
?>
</form>
</body>
</html>

I keep getting

mysql_fetch_array() expects parameter 1 to be resource, boolean given..?

I'm try to used the $page to grab the home.php but it's not working so I think it will save the home.php file once I type it and publish it?

Member Avatar for LastMitch

@ Ardav

I'm working on another thread. I think I need to resolve the other thread first.

I'm still getting

mysql_fetch_array() expects parameter 1 to be resource, boolean

on this line:

while($rowcats = mysql_fetch_array($rscats))

I know if you don't want to help me, it's fine with me. I'm not going to be upset. Someone on Daniweb will help me sooner or later.

Member Avatar for LastMitch

Hi

I don't know where to started. I recently installed and would like to know how to create a Archive page.
It's kinda like a blog but for me it's kinda neat using the CKEditor .

I still can used a script that I can practice on. I can't used Ardav script because it's incomplete, it's wasting not just my time or anyone time who read this not know where to start. I actually as ask someone who is a professor at a college regarding about this script he mention to me it's incomplete. He explained to me base on the script I have that it's pretty hard for anyone to understand this unless it's a whole script not part of a script but a whole script to understand how it works. So now, I'm starting over again.

For example:

Article:

Hi ... page. 

I want to save that Article to the Archive.

I want to learn how to create a Archive page. Any example will gave me an idea how this works. So far this is the only way for me to learn php.

I really do appreciate if someone explained to me how this works!

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.