Jump to content

Archived

This topic is now archived and is closed to further replies.

benji87

Live data

Recommended Posts

Hi all. Im currently trying to develop a posts approval system where an administrator has to approve the post before it is published live onto the web.

This includes the option to edit, delete and publish the article etc.

What i had in mind was a list of posts pending to be approved displayed when the admin logs in drawn from an sql database but i then want them to be able to click a button next to the title of the article for whatever action they wish to take.

Ive thought alot about this idea and cant see a logical way of doing it with PHP. Ive done some research and it seems the only way to do this kind of thing is by using ASP.

I have no knowledge of ASP what so ever so i dont know if its the right solution or not? If there is a way of doing this kind of thing using PHP then id love to know!! If not can someone confirm that ASP is the way forward for me...?

Thanks

Share this post


Link to post
Share on other sites
in your table that holds the post information, add another column called "published" or whatever. when the user first submits the posts, the published column would be inserted as false, 0 or whatever. On your page that displays the posts, select only ones that show published as true or 1 or whatever.

in your admin section, display the unpublished ones based on 'published' being false or 0. when you are echoing them out, echo your normal editing options. the admin can edit it or whatever, save it and update the database. But it would still be unpublished. So in your admin section also have a published/unpublished radio button or however you wish to set it up according to your own tastes, and when you click on it or whatever, it updates the "published" column to true/1 or whatever.

or in the admin just dump all of the posts out with add/edit options and maybe a radio tag to change it from published to unpublished.

Share this post


Link to post
Share on other sites
there would be no difference in implimenting this in php or asp, the concept would be simular no matter what the language.

The simplest approuch would simply to have a field called [i]islive[/i] in your articles table, set this to 0 by default (not live), then, as an articles goes [i]live[/i] update this value to 1.

To retrieve all [i]live[/i] articles a query might look like....
[code]
SELECT * FROM article WHERE islive = 1;
[/code]
Hope this helps.

Share this post


Link to post
Share on other sites
Ok that makes perfect sense. But when the admin logs in i want them to have options next to the title of the articles waiting to be published. Like so:

DATE | TITLE |
___________________________________________________________________
12/05/06 New times ahead | EDIT | | DELETE | | APPROVE |
___________________________________________________________________
23/06/06 Launch day | EDIT | | DELETE | | APPROVE |

This would be how the data called from the database would be shown with next to each title the three buttons if the user decides that the article is not suitable then they would click delete. How do i make it so it knows that i want to delete that article on that line? the same with edit and approve. Also how would i display the buttons would i base the img url in the database or stick them in html?

Share this post


Link to post
Share on other sites
Its quite simple. Just make your links pass some details through the querystring.... something like....
[code]
$id = row['aricleid']; // <-- retrieved from the database with article.
echo "<a href=\"actions.php?action=edit&id=$id\">edit</a>";
[/code]
Then... on actions.php decide what to do....
[code]
<?php
  if (isset($_GET['action'])) {
    switch ($_GET['action']) {
      case 'edit':
        // do edit stuff.
      case 'update'
        // do update stuff.
    }
  }
?>
[/code]

Share this post


Link to post
Share on other sites
I get this error when trying to execute the display page:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Parse error: parse error, unexpected '[' in /homepages/33/d69713911/htdocs/webs/examples/post/display.php on line 35
[/quote]

Share this post


Link to post
Share on other sites
Um... It helps if you actually post your problematic code.

Share this post


Link to post
Share on other sites
[code]<?
require_once('db.php');

$query=("SELECT * FROM postapproval ORDER BY id DESC");
$result=mysql_query($query);
$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$poster=mysql_result($result,$i,"poster");
$message=mysql_result($result,$i,"message");
$title=mysql_result($result,$i,"title");
$date=mysql_result($result,$i,"date");
$time=mysql_result($result,$i,"time");
$dellink=mysql_result($result,$i,"dellink");
?>

<body>
<table width="71%" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td width="18%"><? echo"$date" | "$time" ?></td>
    <td width="53%"><? echo "$title" ?></td>
    <td width="4%"><? $id = row['id'];
    echo "<a href='actions.php?action=edit&id=$id'><img src='editbutton.jpg'></a>" ?></td>
    <td width="20%"></td>
    <td width="23%"></td>
  </tr>
</table>
</body>
<?
$i++;
}
?>[/code]

the bit in question is $id = row['id']

Share this post


Link to post
Share on other sites
you should have this:

$id = $row['id'];

Although that wont work because you havent set the $row[] array anywhere.

What you should do is ditch the whole $id = row['id']; and leave it out, as you have already specified the $id variable above.

Share this post


Link to post
Share on other sites
Ok that worked fine thanks! Now i dont understand the actions.php

I dont have a clue what code i need to use with that snipet that was provided.

Obviously i want a a text box with the article text in it so the admin can just edit it then submit it
to update which is easy enough but will i need a seperate php file to do that?

Share this post


Link to post
Share on other sites
Really... were not going to write the thing. I'll try and explain a bit more.
[code]
<?php
  if (isset($_GET['action'])) {
    switch ($_GET['action']) {
      case 'edit':
        // here you'll need to run a query to retrieve the selected record
        // and display it in a textarea contained within a form. eg
        $sql = "SELECT message FROM postapproval WHERE id = '{$_GET['id']}'";
        // this form will then either need to post to another page, or you
        // could create another switch() to check the $_POST array.
      case 'update'
        // do update stuff.
    }
  }
?>
[/code]

Share this post


Link to post
Share on other sites
Ok that last post made it alot easier to understand so thanks!

Ive tried it and i keep getting a unexpected $ parse error on line 28. Im guessing this is something to do with it not picking up the id variable but im probably totally wrong!

[code]<?
  if (isset($_GET['action'])) {
    switch ($_GET['action']) {
      case 'edit':
    
    require_once('db.php');

$query=("SELECT message FROM postapproval WHERE id = '{$_GET['id']}'");
$message=mysql_query($query);

mysql_close();


?>
<body>
<form name="" method="post" action="">
<textarea name="textarea"><? echo "$message" ?></textarea>
</form>
</body>
</html>
[/code]

Thanks

Share this post


Link to post
Share on other sites
Try:

[code]<?php
  if (isset($_GET['action'])) {
    switch ($_GET['action']) {
      case 'edit':
    
    require_once('db.php');

$query=("SELECT message FROM postapproval WHERE id = '$_GET['id']'");
$message=mysql_query($query);

mysql_close();
break;
};
};

?>
<body>
<form name="" method="post" action="">
<textarea name="textarea"><?php echo($message) ?></textarea>
</form>
</body>
</html>[/code]

Orio.

Share this post


Link to post
Share on other sites
That worked great! Only trouble is it doesnt retrieve the message data for some reason it fills the text box with 'Resource id #3' anybody know what that came out of??

Thanks

Share this post


Link to post
Share on other sites
Right this is my complete code although it still does not work although i dont get any syntax errors!

[code]
<?php
session_start();
include ('db.php');
  if (isset($_GET['action'])) {
    switch ($_GET['action']) {
      case 'edit':
    
$query=("SELECT message FROM postapproval WHERE id = '{$_GET['id']}'");
$message=mysql_query($query);

mysql_close();

break;

    case 'delete':
$query=("DELETE FROM postapproval WHERE id = '{$_GET['id']}'");
mysql_close();
header("Location: display.php");

break;

    case 'approve':
$query=("UPDATE postapproval SET postlevel = 1 WHERE id = '{$_GET['id']}'");
mysql_close();
header("location: index.php");
};
};

?>
<body>
<form action="update.php" method="post" name="editarticle" id="editarticle">
<p>
  <textarea name="edited" id="edited"><?php echo ("$message") ?></textarea>
</p>
<p>
  <input name="Update" type="submit" id="Update" value="Update">
</p>
</form>
</body>
</html>
[/code]

As i said when i click update to carryon over to this code it fills the text box with text saying 'Resource id #3' i dont have a clue what that is all about. Ive also tried delete and that does absolutly nothing!

Please help me i really need to get this sorted! Thanks

Share this post


Link to post
Share on other sites
Ok ive got the update working finally! Now its just the delete function that wont work!

Share this post


Link to post
Share on other sites
What do you meen by [i]won't work[/i]?

Share this post


Link to post
Share on other sites
It doesnt delete the record from the database it just refreshes the page to display.php same with the approve it doesnt update the field to 1.

Thanks.

Share this post


Link to post
Share on other sites

×

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.