Connecting Tech Pros Worldwide Forums | Help | Site Map

Select box help

Jon
Guest
 
Posts: n/a
#1: May 2 '06
All,

I have a problem that I'm not quite sure what algorithm will help me on. I'm
bringing in records from MySQL using PHP and need to spit this records into
a select box. Fairly simple, here's my code for the first select box:

<option selected
value="<?=$currentCatID?>"><?=$currentCategoryName ?><option>
<?php
while($rowGetCat = mysql_fetch_array($resultGetCat)){
if($rowGetCat['pCatID'] != $currentCatID){
echo "<option
value=\"".$rowGetCat['pCatID']."\">".$rowGetCat['pCatName']."</option>";
}
}
?>
</select>

Problem is - based on their choice with the first select box, I need to
query the DB and populate a second select box. So basically, I need a 2nd
select box that is populated on the fly based on their choice from the first
select box. The only solutions I have found so far use their own form, and
the form I have now has numerous other options and values that I need to
save the state of for editing.

I was thinking AJAX might help, or maybe just regular javascript, but
without having the entire page reload I'm not sure. Any ideas?



Regenuluz
Guest
 
Posts: n/a
#2: May 2 '06

re: Select box help


I'm pretty sure AJAX would be the best choice here.
And the only one I can think of, where you don't have to reload the
entire page.

Andy Jeffries
Guest
 
Posts: n/a
#3: May 2 '06

re: Select box help


On Tue, 02 May 2006 13:47:08 -0700, Regenuluz wrote:[color=blue]
> I'm pretty sure AJAX would be the best choice here. And the only one I can
> think of, where you don't have to reload the entire page.[/color]

You could also use a regular Javascript data structure within <script>
tags dynamically printed/echoed using PHP, then filter the data structure
using Javascript to only display the relevant items.

However, it could make page weight enormous, so it may not be possible
with your dataset (plus you may not like the idea of your dataset being
easily viewable, although anyone can read the AJAX source and pull it
using a script if they're interested so neither way is secure).

I do, however, agree with Regenluz that AJAX would be the best solution,
but in case writing custom AJAX code is out of your realm of abilities,
there is the way I suggest above.

Cheers,


Andy


--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Jon
Guest
 
Posts: n/a
#4: May 2 '06

re: Select box help



"Andy Jeffries" <news@andyjeffries.co.uk> wrote in message
news:pan.2006.05.02.21.42.07.505570@andyjeffries.c o.uk...[color=blue]
> On Tue, 02 May 2006 13:47:08 -0700, Regenuluz wrote:[color=green]
>> I'm pretty sure AJAX would be the best choice here. And the only one I
>> can
>> think of, where you don't have to reload the entire page.[/color]
>
> You could also use a regular Javascript data structure within <script>
> tags dynamically printed/echoed using PHP, then filter the data structure
> using Javascript to only display the relevant items.
>
> However, it could make page weight enormous, so it may not be possible
> with your dataset (plus you may not like the idea of your dataset being
> easily viewable, although anyone can read the AJAX source and pull it
> using a script if they're interested so neither way is secure).
>
> I do, however, agree with Regenluz that AJAX would be the best solution,
> but in case writing custom AJAX code is out of your realm of abilities,
> there is the way I suggest above.
>
> Cheers,
>
>
> Andy
>
>
> --
> Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
> http://www.gphpedit.org | PHP editor for Gnome 2
> http://www.andyjeffries.co.uk | Personal site and photos
>[/color]

Yeah, that's definitely an option I considered - Bringing in all of the
subcategories and running a case on the onchange event using the value
they've passed in. But like you said, it makes the page pretty heavy having
to bring in this data - plus, I need this same process to be run on a few
different pages - and many times users aren't going to be updating the
categories, so I just need them to stay the same but still be available.

Looks like my options are down to: AJAX, making the category options a
separate form/choice, or weighting my page down.

AJAX might be out of my realm unfortunately - We do have some books, and I'm
confident in my code, but I've never written any real-world stuff and I have
until June 1 to have this project completed. Thanks for the info guys. If
anyone else has suggestions, I'm always open :)


Andy Jeffries
Guest
 
Posts: n/a
#5: May 2 '06

re: Select box help


On Tue, 02 May 2006 16:55:30 -0500, Jon wrote:[color=blue]
> AJAX might be out of my realm unfortunately - We do have some books, and
> I'm confident in my code, but I've never written any real-world stuff and
> I have until June 1 to have this project completed. Thanks for the info
> guys. If anyone else has suggestions, I'm always open :)[/color]

I've got some fairly simple AJAX javascript functions and can give you
some advice on it, but it's OT on this group. Feel free to email me if
you like, I can give you some code to get you started with AJAX and
then help you implement it if you like*... Use my first name at
andyjeffries dot co dot uk.

* I'd love to offer to really get my hands dirty and help implement it for
you, but I really don't have time. However, I'll happily send you code
snippets for the AJAX stuff and help with explanations however I can.

Cheers,


Andy


--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

william.clarke@gmail.com
Guest
 
Posts: n/a
#6: May 3 '06

re: Select box help


Ajax would work fine for this, but why not reload the page (if you
haven't used AJAX) and store any previous data entered and redisplay it
when the second list is filled, that works fine and the user experience
shouldn't be badly effected, unless you have a very large/complicated
page.

Andy Jeffries
Guest
 
Posts: n/a
#7: May 4 '06

re: Select box help


On Wed, 03 May 2006 15:11:27 -0700, william.clarke@gmail.com wrote:[color=blue]
> Ajax would work fine for this, but why not reload the page (if you haven't
> used AJAX) and store any previous data entered and redisplay it when the
> second list is filled, that works fine and the user experience shouldn't
> be badly effected, unless you have a very large/complicated page.[/color]

Because AJAX really isn't that difficult for a competant programmer. Your
method should be used as a backup plan if AJAX isn't available
(feature-test for it and if it's available hide the button that submits
the form with the first drop down filled in).

Cheers,


Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Closed Thread