Jump to content

Displaying Pages In A Drop Down Menu Via Page Types


White_Lily

Recommended Posts

Hi, I have a page that allows you to select pages that you want have related pages on. The problem I'm having is that its not displaying anything, not even the types of pages that I want it to display and have specified.

 


<?php
$getCategories = select("pages", "id, name", "page_switch = 1");
while ($categories = mysql_fetch_array($getCategories))
{
//if(!isset($usedCats[$categories['id']])){
if($categories["type"] == 2 && $categories["type"] == 4 && $categories["type"] == 5){
echo "<option value='".$categories['id']."'>".$categories['name']."</option>";
}
//}
}
?>

 

I can't seem to figure out why it's not displaying anything :(

 

Any help would be appreciated. ^_^

White_Lily,

 

Have you ever searched the internet with a problem only to find many posts all asking similar questions but no-one actually posting a solution. Don't you find it frustrating and annoying?


<label>Page:</label>
<select name="catSel" style="width: 300px;">
<?
$getCategories = select("pages", "id, name", "(page_switch = 1) AND (type = 2 OR type = 4 OR type = 5)"); // this line is the fix
while ($categories = mysql_fetch_array($getCategories))
{
echo "<option value='".$categories['id']."'>".$categories['name']."</option>";
}
?>
</select>

You should use the full PHP tags instead of the short tags, and you need to/should use htmlspecialchars () to ensure that there are no problems with (accidental) HTML injections.

 

Also, labels without a for attribute, pointing to a identically named id attribute of an input element, is quite useless.

 

Lastly, you could have solved this using MySQL's IN() function. Allows for a much cleaner solution, especially if you have many IDs you want to match.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.