Help - Search - Members - Calendar
Full Version: [resolved] Build-A-Blog: Categories problem/request
Codegrrl.com Forums > Script Help > Tutorial Help
mayfly
I think it's very annoying that you have to choose what category the entries belong to every time you make an update. I've looked for a script on other sites but I'm not very confident in my PHP-coding skills so I'm not sure what to do.

I'd like to have the previous chosen category as number one in the list all the time.
Like with the other lists in the update form:

CODE

<select name="month">
<option value="<?php echo $old_month; ?>"><?php echo $old_month; ?></option>
<option value="January">Januari</option>
<option value="February">Februari</option>
<option value="March">Mars</option>
<option value="April">April</option>
<option value="May">Maj</option>
<option value="June">Juni</option>
<option value="July">Juli</option>
<option value="August">Augusti</option>
<option value="September">September</option>
<option value="October">Oktober</option>
<option value="November">November</option>
<option value="December">December</option>
</select>


Does anyone know how to make a similar solution for the category list on the update entry page?
Amelie
It should do that automatically. Double-check that you have added the right code to your update page - it is different to that of the post page.

You should be using this code:

CODE
<?php
$result2 = mysql_query("SELECT * FROM php_blog_categories");

echo '<p><strong><label for="category">Category:</label></strong> <select name="category" id="category">';

while($row2 = mysql_fetch_array($result2)) { ?>
    <option value="<?php echo $row2['category_id']; ?>" <?php if ($row['category'] == $row2['category_id']) echo ' selected="selected"'; ?>><?php echo $row2['category_name']; ?></option>
    <?php
}
?>
</select></p>
Neuriel
Okay here you go:

Find
CODE

$old_time = date("H:i",$old_timestamp);

Under that put
CODE

$old_cat=$row['category'];


Now move on to this part
CODE

<option value="<?php echo $row2['category_id']; ?>" <?php if ($row['category'] == $row2['category_id']) echo ' selected'; ?>><?php echo $row2['category_name']; ?></option>

Change to
CODE

<option value="<?php echo $row2['category_id']; ?>" <?php if ($old_cat == $row2['category_id']) echo ' selected'; ?>><?php echo $row2['category_name']; ?></option>



Edit: Amelie, it doesn't work automatically. I just tested. Up above in edit, you close the while loop so then $row is nothing and there was no old category variable added in.
Sunnefa
Works like a charm! Thank you so much clap.gif I know I wasn't the one asking about this in the beginning, but I was looking for a solution to this same problem, so thanks!
mayfly
Yay it worked! Thank you so much Jamie. heart.gif
Neuriel
You're very welcome!
Sairah
YAY! Same here, I kept scrutinizing the code and wondering why there wasn't an $old_cat section, but I am so n00b in mySQL I figured I probably had it wrong. frusty.gif But thanks for clearing that up, now my blog pwns not just for readers but for meh, too!!! ^__^ Lol, sry, I get a little silly at times. blush.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.