Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-08-2007, 07:03 PM   PM User | #1
fishnyc22
New Coder

 
Join Date: Apr 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
fishnyc22 is an unknown quantity at this point
select OPTION not SELECTED - Am I losing my mind?

Ok. I'm either going crazy or I've just been plain sitting here to long.

I have this simple loop to build a select field showing page numbers. But for some weird reason. its compeltely ignoring the SELECTED copy that should be written into the option field.

Code:
$page = (!isset($_GET['page'])) ? 1 : $_GET['page']; 
$pagenumbers = "";
$pagenumbers .= "  <form><select name='menu1' onchange=\"MM_jumpMenu('parent',this,0)\">\n";

 
for($i = 1; $i <= $total_pages; $i++) { 
	$pagenumbers .= "	 <option value='" . $_SERVER['PHP_SELF'] . "?a=" . $ashort. "&page=" . $i . "'";
	if($page == $i) $pagenumbers .=  " selected";
	$pagenumbers .= ">Page $i</option>\n";
} 

$pagenumbers .= "  </select></form>\n";

I've checked al values for $page, and $i, ran and echo test to see what its doing and still nothing. When I view the source on the page I see:

Code:
<select name="menu1" onchange="MM_jumpMenu('parent',this,0)">
	 <option value="index.php?a=test&amp;page=1">Page 1</option>
	 <option value="index.php?a=test&amp;page=2">Page 2</option>
	 <option value="index.php?a=test&amp;page=3">Page 3</option>
	 <option value="/index.php?a=test&amp;page=4">Page 4</option>
  </select>
Am I going nuts. why would it not write in the selected. there is definately a match when it sees 'page' number in the URL string.

Whats weird is that its writing "&amp;" and it also converted my single quotes to double (but maybe thats normal)....

Please bail me out of this ridiculous hole I'm in
fishnyc22 is offline   Reply With Quote
Old 11-08-2007, 07:20 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
I tried your exact code (with an added echo $pagenumber; at the bottom) and it worked just as you'd expect. So yes, you are going crazy.

How is $pagenumber getting outputted?
__________________
Fumigator is offline   Reply With Quote
Old 11-08-2007, 07:31 PM   PM User | #3
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,602
Thanks: 2
Thanked 398 Times in 391 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Yep, the code works. Are you sure you're looking at the right code in the right place?
Inigoesdr is offline   Reply With Quote
Old 11-08-2007, 07:48 PM   PM User | #4
aedrin
Senior Coder

 
Join Date: Jan 2007
Posts: 1,648
Thanks: 1
Thanked 58 Times in 54 Posts
aedrin will become famous soon enough
Quote:
if($page == $i) $pagenumbers .= " selected";
PHP Code:
    if($page == $i$pagenumbers .=  ' selected="selected"'
</nitpicking>
aedrin is offline   Reply With Quote
Old 11-08-2007, 07:52 PM   PM User | #5
fishnyc22
New Coder

 
Join Date: Apr 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
fishnyc22 is an unknown quantity at this point
thanks guys. I output it simply with:

Code:
echo "<div id='pg'>\n";
echo $pagenumbers;
echo "</div>\n";
I swear I'm not crazy!
fishnyc22 is offline   Reply With Quote
Old 11-08-2007, 07:53 PM   PM User | #6
fishnyc22
New Coder

 
Join Date: Apr 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
fishnyc22 is an unknown quantity at this point
tried that too.

I even tried to just hard code "selected" into the area and it isnt showing up.


Quote:
Originally Posted by aedrin View Post
PHP Code:
    if($page == $i$pagenumbers .=  ' selected="selected"'
</nitpicking>
fishnyc22 is offline   Reply With Quote
Old 11-08-2007, 09:42 PM   PM User | #7
fishnyc22
New Coder

 
Join Date: Apr 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
fishnyc22 is an unknown quantity at this point
OK. I think whats going on is related to the "&amp;" in the URLs. What would cause them to not be converted to &?

Could it be an HTML error that I'm not seeing?
fishnyc22 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:28 PM.


Advertisement
Log in to turn off these ads.