Help - Search - Members - Calendar
Full Version: Categories
Codegrrl.com Forums > Script Help > Tutorial Help
Steven
Well, I searched the forum and read all about Categories. They just confused me. I have to add a field for it in my database, then make a drop down list, then display what category it is in on the blog page ans single view.

How?

Could someone help me with SQL code to add the field? I stink at SQL.

Is there anything else I need to know?

Steven
Marilyn
I use PHPMyAdmin so I don't know the SQL code - but you add the "category" the same way you add any other field to your database.

Then on your post form you can create a drop down list to choose the category to file your post under. The HTML code is fairly simple:
CODE

<p>
<select name="category">
<option value="topic00">Topic00</option>
<option value="topic01">Topic01</option>
<option value="topic02">Topic02</option>
</select>
</p>


You don't have to use a drop down box, you can use a text box if you would like, but the drop down box helps you keep consistent with how you categorize everything.

Then make sure you add "category" in your PHP code in the section that looks like this (forgive me I'm not sure what the function is called):
CODE

if (isset($_POST['submit'])) {

    $author = $_POST['author'];
    $title = $_POST['title'];
    $entry = $_POST['entry'];
    $category = $_POST['category'];


and this:
CODE

$sql = "INSERT INTO php_blog (author,title,entry,category) VALUES ('$author','$title','$entry','$category' )";


If you want to display the category on your blog, add it into the array on the "blog.php" file:
CODE

while($row = mysql_fetch_array($result)) {

    $title = $row['title'];
    $entry = $row['entry'];
    $author = $row['author'];
    $category = $row['category'];


And echo it on the page:
CODE
  
<h2><?php echo $title; ?></h2>
<div><?php echo $entry; ?></div>
<div><p>Posted by <?php echo $author; ?>. Filed under <?php echo $category; ?></p></div>


You can also display by category as in an archive page but that is the basics. If you search other posts here you can find a lot of information. I learned how to do it from these forums so if you look back at old posts you'll get a lot of good tips. Good luck!
Steven
Thanks! smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.