Please help, How to remember seleced?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SaLing007
Forum Newbie
Posts: 2
Joined: Sun Sep 28, 2008 5:16 am
Location: UK

Please help, How to remember seleced?

Post by SaLing007 »

Hello guys,

Maybe someone can help me to sort this out with my code please?
Well, here is that I have this code between html:

$result2 = $db->get_results("SELECT * FROM Groups ORDER BY Group_ID");
foreach($result2 as $row) {
$grp_id = $row->Group_ID;
$grp_nm = $row->Group_NAME;
$value = 'subscribe_view.php?group=' . $grp_id;

$option = '<option value="' . $value . '">' . $grp_nm . '</option>';

echo $option;
}

So as you noticed I need to get drop down options as a rows. This is the way I can have exact names of groups from table. For the values I have javascript which transfers me selection to the value link (maybe there is another way to do this with php?). But When I click for example on one of those options aka. Sounding, it refreshes the page {as it has to be on the same page} and the selected option has not been assigned.
Does anyone of you guys know how can I have <selections> html drop down list to remember selection?


Please help me so I can continue with my coding. I am desperate with that :) And massive THANK YOU to those who have their say.

All your help are really appreciated. Thank you all!

S
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Please help, How to remember seleced?

Post by califdon »

I didn't fully understand your question, but as soon as I saw the phrase "..it refreshes the page {as it has to be on the same page}..", it was obvious that you have to use Ajax, which is a combination of Javascript, using the XmlHttpRequest object and a server script written in PHP or other server language. So my advice is to look at the Ajax tutorial at w3schools.com and see if that will help you accomplish what you want to do.
Teknotica
Forum Newbie
Posts: 1
Joined: Sun Sep 28, 2008 4:06 pm

Re: Please help, How to remember seleced?

Post by Teknotica »

Hi.

I didn't fully understand either but what I do to keep the values throughout the pages (or refreshing it) is assign the value to a SESSION variable.... (Starting a Session previously).

I hope it helps. 8)
SaLing007
Forum Newbie
Posts: 2
Joined: Sun Sep 28, 2008 5:16 am
Location: UK

Re: Please help, How to remember seleced?

Post by SaLing007 »

Hey guys, thanks a lot for your respondse.

Well, I will try to explain better what I am looking for.
I have got form on file index.php and drop down list for selecting category. As soon I select category which by the way data comes from mysql it has to refresh page to index.php?category=1. Everything is working with the refresh as I am using tiny javascript for values.
Anyway, when page refreshing the drop down list comes to default selection, however I need somehow to do that php remembered whic value in drop down list has been selected.

Am I was better this time in explaining? :) Please, I heared about some code which is something like this:

<SELECT name="fieldname" size="1"><OPTION <?php if($fieldname=="0"){ echo "selected"; } ?>>0</OPTION><OPTION <?php if($fieldname=="1"){ echo "selected"; } ?>>1</OPTION><OPTION <?php if($fieldname=="2"){ echo "selected"; } ?>>2</OPTION></SELECT>

But it does not work. :banghead:

Any ideas?

PS Don't really want use sessions for this. I know there is other ways to do just cannot get the 'BINGO BULB'.
Post Reply