Jump to content


Photo

Live data


  • Please log in to reply
19 replies to this topic

#1 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 12 June 2006 - 03:54 PM

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

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 12 June 2006 - 04:29 PM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 12 June 2006 - 04:31 PM

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 islive in your articles table, set this to 0 by default (not live), then, as an articles goes live update this value to 1.

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

#4 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 13 June 2006 - 02:39 PM

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?

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 13 June 2006 - 03:54 PM

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


#6 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 15 June 2006 - 01:49 PM

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]



#7 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 15 June 2006 - 02:35 PM

Um... It helps if you actually post your problematic code.

#8 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 15 June 2006 - 02:46 PM

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

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

#9 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 15 June 2006 - 02:58 PM

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.
wisewood: proven fact, I am both wise, and wooden.

#10 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 15 June 2006 - 03:18 PM

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?

#11 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 15 June 2006 - 03:52 PM

Really... were not going to write the thing. I'll try and explain a bit more.
<?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.
    }
  }
?>


#12 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 16 June 2006 - 01:03 PM

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!

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

Thanks

#13 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 20 June 2006 - 10:39 AM

Can someone please help?

#14 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 10:58 AM

Try:

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

Orio.
Think you're smarty?

(Gone until 20 to November)

#15 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 20 June 2006 - 11:13 AM

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

#16 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 20 June 2006 - 12:55 PM

Right this is my complete code although it still does not work although i dont get any syntax errors!

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

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

#17 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 20 June 2006 - 01:39 PM

Ok ive got the update working finally! Now its just the delete function that wont work!

#18 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 20 June 2006 - 01:44 PM

What do you meen by won't work?

#19 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 20 June 2006 - 02:19 PM

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.

#20 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 21 June 2006 - 08:02 AM

Anyone?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users