Search the Community
Showing results for tags 'lists'.
-
Can you figure this out? I've got two tables, `articles` and `categories`. Each article has been assigned to a category. I want to present all of the articles on a single page, one list per category, thus: Category Article 1 Article 2 Article 3 Article 4 Category Article 1 Article 2 Article 3 Category Article 1 Article 2 Article 3 Article 4 I want the categories to be in alphabetical order and the articles to be in alphabetical order. So far, I have only managed to get the categories in alphabetical order. How can I also get the articles in alphabetical order? As always, any help will be much appreciated. Here's my code: $sql = "SELECT title, url, cat FROM `articles` LEFT JOIN `categories` ON articles.catid = categories.catid ORDER BY cat ASC"; $results = mysql_query($sql, $conn) or die(mysql_error()); if(mysql_num_rows($results)) { $last_cat = ''; while($row = mysql_fetch_assoc($results)) { if($row['cat'] != $last_cat) { if($last_cat) { echo "</ol>"; } $last_cat = $row['cat']; echo "<h3>$last_cat</h3>"; echo "<ol>"; echo "<li><a href=\"{$row['url']}\">{$row['title']}</a></li>"; } else { echo "<li><a href=\"{$row['url']}\">{$row['title']}</a></li>"; } } echo "</ol>"; } else { echo "<p>No articles found.</p>"; }
- 4 replies
-
- alphabetical order
- mysql select
-
(and 1 more)
Tagged with:
-
Disclaimer: This is my first attempt at doing anything with php, which might be overkill for what's required. Many of the pages of our website have one or more products with multiple selections (drop-down lists). Quite a few orders come in without a selection for one of the critical choices, which necessitates contacting the customer and waiting for a reply. A script which validates required fields could make things run much more smoothly for everyone. I've downloaded such a script and attempted to validate just one list (outside color) but have been unable to get the validation to work. Any guidance will be much appreciated. The files in question are attached for convenience. formvalidator.php 111-php-test.html
- 4 replies
-
- form
- validation
-
(and 2 more)
Tagged with: