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. ^_^

Link to comment
Share on other sites


<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>

Edited by White_Lily
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.