SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Query

  1. #1
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Query

    Hi all

    I have create a database where people can post comments, ideas enter jokes etc, but before displaying them on the screen i have to make sure that they are not offended to any one? I need some bulk place from where i can send to the screen.
    Any ideas??

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    So add a field to your database table along the lines of "moderated". Default value 0.
    If moderated = 0, dont show it on the main display page.
    Create a new screen for the administrator, which shows all unmoderated (moderated = 0) jokes.
    That page has buttons to approve the jokes (set moderated = 1).
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you show a simple example of what code will be look like?
    I am new to the PHP and MySQL

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    The filtering of the jokes would be handled by your query, so without that, i cant show you anything.

    Pushing a button on the moderator screen should execute an UPDATE query setting moderated = 1 WHERE id = <the jokes ID>
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is my index.php script:
    <?php
    include_once $_SERVER['DOCUMENT_ROOT'] .
    '/includes/magicquotes.inc.php';
    if (isset($_GET['addjoke']))
    {
    include 'form.html.php';
    exit();
    }
    if (isset($_POST['joketext']))
    {
    include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
    try
    {
    $sql = 'INSERT INTO joke SET
    joketext = :joketext,
    jokedate = CURDATE()';
    $s = $pdo->prepare($sql);
    $s->bindValue(':joketext', $_POST['joketext']);
    $s->execute();
    }
    catch (PDOException $e)
    {
    $error = 'Error adding submitted joke: ' . $e->getMessage();
    include 'error.html.php';
    exit();
    }
    header('Location: .');
    exit();
    }
    if (isset($_GET['deletejoke']))
    {
    include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
    try
    {
    $sql = 'DELETE FROM joke WHERE id = :id';
    $s = $pdo->prepare($sql);
    $s->bindValue(':id', $_POST['id']);
    $s->execute();
    }
    catch (PDOException $e)
    {
    $error = 'Error deleting joke: ' . $e->getMessage();
    include 'error.html.php';
    exit();
    }
    header('Location: .');
    exit();
    }
    include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
    try
    {
    $sql = 'SELECT joke.id, joketext, name, email
    FROM joke INNER JOIN author
    ON authorid = author.id';
    $result = $pdo->query($sql);
    }
    catch (PDOException $e)
    {
    $error = 'Error fetching jokes: ' . $e->getMessage();
    include 'error.html.php';
    exit();
    }
    foreach ($result as $row)
    {
    $jokes[] = array(
    'id' => $row['id'],
    'text' => $row['joketext'],
    'name' => $row['name'],
    'email' => $row['email']
    );
    }
    include 'jokes.html.php';
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •