View Single Post
  #7 (permalink)  
Old May 31st, 2006, 09:02 PM
Beebs Beebs is offline
Authorized User
 
Join Date: May 2006
Location: , , Australia.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Beebs
Default

mike, thanks for the repply

I have done the database update (creating section) and able to join them to display the result.

However I struggle them to make them appear in the compose.php ( which is going to be used for editing the article as well).

What I want is the section appear as a pull-down choice (a select form) that any new article going to be posted/edited have to chose the section.

Here's the code :

Code:
<?php

require_once 'conn.php';

$article = '';
$title = '';
$section_id = '';
$body = '';
$author_id = '';
if (isset($_GET['a'])
    and $_GET['a'] == 'edit'
    and isset($_GET['article'])
    and $_GET['article']) {
  $sql = "SELECT ar.* ".
          "FROM cms_articles ar " .

         "WHERE article_id=" . $_GET['article'];
  $result = mysql_query($sql, $conn)
    or die('Could not retrieve article data; ' . mysql_error());

  $row = mysql_fetch_array($result);
  $title = $row['title'];
  $section_id = $row['section_id'];
  $body = $row['body'];
  $article = $_GET['article'];
  $authorid = $row['author_id'];
}
require_once 'header.php';
?>

<form method="post" action="transact-article.php">

<h2>Compose Article</h2>

<p>
  Title:<br>
  <input type="text" class="title" name="title" maxlength="255"
    value="<?php echo htmlspecialchars($title); ?>">
</p>


<p>
Section:<br>
<select id="section_name" name="section_name" style="width:150px">
<?php
$section_name = "";
$sql = "SELECT section_id, section_name " .
         "FROM cms_section ORDER BY section_id";
  $result = mysql_query($sql)
    or die("Query Error" .
           mysql_error());
  while ($row = mysql_fetch_array($result)) {
    if ($row['section_id'] == $section_name) {
      $selected = " selected";
    } else {
      $selected = "";
    }
    echo '<option value="' . $row['section_id'] . '"' . 
         $selected.'>' . $row['section_name'] . '</option>' . 
         "\r\n";
  }

?>
</select>






</p>

<p>
  Body:<br>
  <textarea class="body" name="body" rows="10" cols="60"><?php
    echo htmlspecialchars($body); ?></textarea>
</p>
<p>
<?php
echo '<input type="hidden" name="article" value="' .
     $article . "\">\n"; 

if ($_SESSION['access_lvl'] < 2) {
  echo '<input type="hidden" name="authorid" value="' .
       $authorid . "\">\n";
}

if ($article) {
  echo '<input type="submit" class="submit" name="action" ' .
       "value=\"Save Changes\">\n";
} else {
  echo '<input type="submit" class="submit" name="action" ' .
       "value=\"Submit New Article\">\n";
}
?>
</p>
</form>

<?php require_once 'footer.php'; ?>
In that code I manage to run SQL query to pull section data in the pull down menu, but how can I make them having relational result that when any article is published/edited the section_id field in the cms_articles will also be filled/updated?

PS: I don't include the adjusted transac-article.php code here, but if you need please advise me.

Cheers

Reply With Quote