Page 1 of 1

Please help, How to remember seleced?

Posted: Sun Sep 28, 2008 5:51 am
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

Re: Please help, How to remember seleced?

Posted: Sun Sep 28, 2008 2:08 pm
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.

Re: Please help, How to remember seleced?

Posted: Sun Sep 28, 2008 4:09 pm
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)

Re: Please help, How to remember seleced?

Posted: Mon Sep 29, 2008 10:11 am
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'.