Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



Are you a Google Analytics enthusiast?

Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE! 

 



 

 www.CustomReportSharing.com 

From the folks who brought you High Rankings!



Photo
- - - - -

Set 2 Values With One Form Option


  • Please log in to reply
11 replies to this topic

#1 piskie

piskie

    HR 7

  • Active Members
  • PipPipPipPipPipPipPip
  • 1,098 posts
  • Location:Cornwall

Posted 10 December 2010 - 07:17 PM

I am using MYSQL and PHP
Can anyone help me with a suggestion of how I can set 2 field values on an Insert from a single <option value="catid-catname">.
I would like to set catid and catname from the one select option value "catid-catname".

MYSQL Insert:
$ins_products->addColumn("catname", "STRING_TYPE", "POST", "catname");
$ins_products->addColumn("catid", "NUMERIC_TYPE", "POST", "catid");

When I started, I intended and expected to only need the numeric value "catid" but I now need to have "catname" in the table for various functions.

#2 Michael Martinez

Michael Martinez

    HR 10

  • Active Members
  • PipPipPipPipPipPipPipPipPipPip
  • 5,065 posts
  • Location:Georgia

Posted 10 December 2010 - 09:27 PM

If I understand what you're asking correctly, one method is to insert a divider character into the cat-id + cat-name data and then parse the strings for those values before doing the SQL inserts.

So you get back a variable, say $cat_selection, and you extract $cat_id from the first part of the data in the variable and then assign the remaining part to $cat_name. Examples of divider or marker characters include:

/
~
^
&
|
\
*

It's purely arbitrary.

#3 piskie

piskie

    HR 7

  • Active Members
  • PipPipPipPipPipPipPip
  • 1,098 posts
  • Location:Cornwall

Posted 11 December 2010 - 04:47 AM

Thanks for that Michael
The Insert is by a quite complex form which includes asomef pre-populated hidden fields plus user filled in input fields. There are also a number of dropdown select options. Added to a file upload with image resize and the form has a whole lot happening on submit.

So to parse from a Dropdown option into 2 values each into a MYSQL field is very difficult for me to accomplish. In fact I cant worrk out how to Parse and Submit in one action.

One way I see of doing this, is to use an auto submit return form.
The main form would insert and then goto a return page that parsed and updated the 2 fields on auto submit then going to a second return page showing all the product details.

#4 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 6,793 posts
  • Location:Blackpool UK

Posted 11 December 2010 - 11:58 AM

So where is the problem in getting "catname" from the database when catid is passed from the form?

#5 piskie

piskie

    HR 7

  • Active Members
  • PipPipPipPipPipPipPip
  • 1,098 posts
  • Location:Cornwall

Posted 11 December 2010 - 07:11 PM

Well Chris, from anywhere within the CMS Admin, a dropdown selects the department from 12 or more to add a product passing this to the add product page. The Add a Product page form is has a hidden field for that department.

Within each department, there are between 15 and 20 product categories. I would like a single action (like a dropdown) to select the category.

The categories are sorted to just the 15 to 20 within that department. So as well as all the product specific info, the Category ia assigned by this dropdown. At the point of loading this Add Product form, the Category is still to be selected.

That is why I am trying to enter values in 2 fields (catid + catname) with the single selection. I can either select catid or catname or catid-catname.

Innitialy I thought just assigning the catid would suffice, but an unforeseen requirement now changes that and I need to use both catid and catname.

#6 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 6,793 posts
  • Location:Blackpool UK

Posted 12 December 2010 - 07:08 AM

That just seems to me to be a piece of pi$$ poor programming or a very poor database/table schema.

The category ID OR the category name are going to be the same record in the database table and even if the system allows for duplicate category names in different departments, requiring the id AND the name is somewhat superfluous. One or the other plus the deparment id/name should suffice.


Solving the problem is really going to depend on how much you can (or are willing to) rewrite.

1/ Build an javascript associative array and concatenate the values into the select element value attribute using the select element onChange event.

2/ rewrite the code that structures the select element so that it creates the value attribute of the option elements with both the id & name concatenated.


#7 piskie

piskie

    HR 7

  • Active Members
  • PipPipPipPipPipPipPip
  • 1,098 posts
  • Location:Cornwall

Posted 12 December 2010 - 08:47 AM

QUOTE
That just seems to me to be a piece of pi$$ poor programming

Thanks for the flattery Chris, there's no one better than you when it comes to that type of response.

#8 Michael Martinez

Michael Martinez

    HR 10

  • Active Members
  • PipPipPipPipPipPipPipPipPipPip
  • 5,065 posts
  • Location:Georgia

Posted 13 December 2010 - 02:41 PM

I don't want to dwell on the quality of programming or database design but I think you and I may have miscommunicated.

What I was envisioning was something like this:
  • User sees a form with combined cat-id/cat-name values in a dropdown
  • User picks an option from that list
  • Your form triggers a script
  • Your script parses the form and extracts the data
  • INSERT NEW STEP: Parse the dropdown list variable, dividing its contents between two new variables
  • ALTERED STEP: Use the new variables from the previous step to do whatever you need to do


#9 piskie

piskie

    HR 7

  • Active Members
  • PipPipPipPipPipPipPip
  • 1,098 posts
  • Location:Cornwall

Posted 13 December 2010 - 07:43 PM

Thanks Michael
I have pondered the suggestions in this thread and now have a working solution.
I know I can enter catid_catname as the combined label and use parsing to manipulate every time I need to use the field as a select/sort/anything process. Rather than have this (for me) complication/handicap multiple times forever, I decided to have the 2 separate fields catid and catname.

Anyway, the way I ended up doing this was by entering catid_catname as a temporary value for catname. After creating the record, the return is to an update form which parsed the combined catid_catname and placed the separate values into their own fields. This update form then uses a simple auto-submit script.
Job done.

Probably not as elegant as some solutions could have been, but within my capabilities whereas I was finding the scripting alternatives quite difficult.

Thanks again for the suggestions which helped kick-start my thoughts to solve the problem.

#10 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 6,793 posts
  • Location:Blackpool UK

Posted 15 December 2010 - 02:26 PM

QUOTE(piskie @ Dec 12 2010, 01:47 PM) View Post
Thanks for the flattery Chris, there's no one better than you when it comes to that type of response.


You'll never get less than a honest opinion.



#11 Michael Martinez

Michael Martinez

    HR 10

  • Active Members
  • PipPipPipPipPipPipPipPipPipPip
  • 5,065 posts
  • Location:Georgia

Posted 15 December 2010 - 03:11 PM

Well, as long as it works, that's what counts, right? That was an honest question.

Honest man to dishonest man: "Pay no attention to me as I may be lying to you."
Dishonest man to Honest man: "How can you be certain of that?"


#12 piskie

piskie

    HR 7

  • Active Members
  • PipPipPipPipPipPipPip
  • 1,098 posts
  • Location:Cornwall

Posted 15 December 2010 - 08:32 PM

Not very good programmer to whoever is listening: It works and it was simple enough for me to achieve.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

SPAM FREE FORUM!
 
If you are just registering to spam,
don't bother. You will be wasting your
time as your spam will never see the
light of day!