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 12-04-2008, 09:40 PM   PM User | #1
ubh
Regular Coder

 
ubh's Avatar
 
Join Date: Apr 2008
Location: Portland, Oregon U.S.A.
Posts: 443
Thanks: 108
Thanked 15 Times in 14 Posts
ubh is on a distinguished road
isset() Demo?

Its been a while since I played with the isset() function. What I am trying to create is a record update script for my database (MySQL). I have lots of records in the database that can get narrowed down by two columns.

1:Product Category.
2:Product Name.

What I want to have is when my php record edit page loads, to retrieve all product category's into an array that gets echoed out into a form select field.

Code:
<select id="product_category">
   <option></option>
   ...
   ...
</select>
Then when a user chooses a product category from the drop down my php page uses that selected product category to retrieve all product names listed under that category and echo them out into another form select field.

Code:
<select id="product_name">
   <option></option>
   ...
   ...
</select>
OK once a user then selects a product name from this second select form field I want to use both selected product_category and selected product_name to create a query that retrieves that specifically selected products information and echo it all out into form fields that the user uses to edit this products information.

Once an edit is finished I again want to use the product_category and product_name to update that specific row in my database.

WHERE DO I START... Like I said, its been a while since I played with isset() and I think this is where I start but since the last time I used it I can find a demo of what I am trying to create here on the net anymore nor in my archive of old scripts...

Anyone be kind enough to point me in the right direction here please???

Last edited by ubh; 12-04-2008 at 09:43 PM..
ubh is offline   Reply With Quote
Old 12-04-2008, 11:07 PM   PM User | #2
hinch
Regular Coder

 
hinch's Avatar
 
Join Date: Sep 2005
Location: UK
Posts: 921
Thanks: 25
Thanked 79 Times in 79 Posts
hinch is on a distinguished road
if (isset($_POST['postvar'])) {
echo "isset returns true as post var is populated";
} else {
echo "isset returns false as postvar is unpopulated";
}
__________________
A programmer is just a tool which converts caffeine into code

My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
My hobby: http://www.angel-computers.co.uk
My life: http://www.furious-angels.com
hinch is offline   Reply With Quote
Old 12-04-2008, 11:12 PM   PM User | #3
PHP6
Regular Coder

 
PHP6's Avatar
 
Join Date: Aug 2008
Location: Czech Republic
Posts: 234
Thanks: 17
Thanked 34 Times in 33 Posts
PHP6 is on a distinguished road
That seems to be a simple question. I could suggest you couple of solutions but you have asked about last part of the whole project, which by itself is the key of the problem.

First of all let’s find out how do you do this select category and select product? Are you using some AJAX or do you do simple POST/GET? Or may be you need the whole scenario how to implement this script?

Waiting for your reply
PHP6 is offline   Reply With Quote
Old 12-04-2008, 11:21 PM   PM User | #4
ubh
Regular Coder

 
ubh's Avatar
 
Join Date: Apr 2008
Location: Portland, Oregon U.S.A.
Posts: 443
Thanks: 108
Thanked 15 Times in 14 Posts
ubh is on a distinguished road
Hey guys.
Well to be honest all this is just in theory I am currently not populating my select fields at all yet.
If I have to use ajax to populate them seamlessly (no page refresh) then I will but I was certain I could do the same seamless approach with PHP alone... maybe not.

I think I may need "the whole scenario on how to implement this script".

I know this is not a wishing well for people to ask and shale recive sort of thing and that's not what I am looking for but maybe some little examples per step of my desired script would really help me out a lot.

Thanks.
ubh is offline   Reply With Quote
Old 12-05-2008, 12:05 AM   PM User | #5
PHP6
Regular Coder

 
PHP6's Avatar
 
Join Date: Aug 2008
Location: Czech Republic
Posts: 234
Thanks: 17
Thanked 34 Times in 33 Posts
PHP6 is on a distinguished road
Ok, now we have the basic requirements and we could make at list raw project Of cause we could do everything without AJAX but I will strongly recommend to study xAJAX it is really easy to use and once you will try it you will never do any project without it

So the first thing is that we will need a form with two select fields and probably two submit button on the right side of them with caption 'load'. They should have different names so we could identify which of them was pressed (of cause we could do with just one button or even "onchange" even of list box but in that case you will need to use JS and that is not a good idea since users used to disable JS). Lets say we have two buttons with names: do_load_category and do_load_product. All data will be sent to index.php file.

Now in index.php file we have to check which button was pressed (could be that none of them ). Here you will need your isset() function to check the existence of your button. The only one button name will be sent to the index.php, the one which was pressed. So you will have:

PHP Code:
if (isset($_REQUEST['do_load_category'])) {
  
// here you have to check that category was selected, some stupid user could miss it :)
} else if (isset($_REQUEST['do_load_product'])) {
  
// the same here but now you have to check that both category and product is selected
} else if (isset($_REQUEST['update'])) {
  
// that is the button at the bottom of the page which user will press when he wants to 
  // update the data. Here you have to check that category and product fields are selected
  // and if everything is ok then update your data in DB
} else {
  
// print default page, user have not pressed any button yet :)

The good idea is to disable product select field until the do_load_category button will not be pressed. The same for update button at the end of the page. You will enable it only when both category and product has the valid values.

I personally prefer to use HTML templates. I never mix PHP and HTML. Instead I like to use %%PRODUCTS%%, %%CATEGORIES%%, %%UPDATE_DISABLED%% marcros. That will allow you later to update your design without touching you PHP script

Good luck

Last edited by PHP6; 12-05-2008 at 12:09 AM..
PHP6 is offline   Reply With Quote
Old 12-05-2008, 04:34 AM   PM User | #6
ubh
Regular Coder

 
ubh's Avatar
 
Join Date: Apr 2008
Location: Portland, Oregon U.S.A.
Posts: 443
Thanks: 108
Thanked 15 Times in 14 Posts
ubh is on a distinguished road
yeah now that I am out of the office at home ha ha I see that I am making this harder than I need it to be.

I am going to go with Ajax I know it quite well been using it for sometime now, but I got so wrapped up into the whole php/MySQL database driven site that I actually made it harder than it needs to be.

My new plan of attack is to use php to populate both select fields and attach a JavaScript function to the onchange that collects their values and preform ajax get to my php file that will build my edit form to edit that particular products information.

Once edited again I will use the two select fields to preform an update query via ajax post to the database..

YAY everyone is happy, maybe its the lights at work that makes it so hard to concentrate lol.
ubh is offline   Reply With Quote
Old 12-05-2008, 09:19 AM   PM User | #7
johnish
New Coder

 
Join Date: Jun 2008
Posts: 64
Thanks: 25
Thanked 0 Times in 0 Posts
johnish is an unknown quantity at this point
you dont need ajax, just use switch statement, your options act as a name and do this
just change id to name
PHP Code:
$product_category $_POST['product_category']
if(!empty(
$product_category){
    switch(
$product_category){
        case 
"option1":
        
//.....
        
break;
        case 
"option2":
        
//.....
        
break;
    }


Last edited by johnish; 12-05-2008 at 09:27 AM..
johnish 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 11:42 AM.


Advertisement
Log in to turn off these ads.