SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a form in which I am pulling data depending on a value in a dropdown box. The dropdown is defaulted to the user of the computer. I want to make it so when I change the user in the dropdown, it will pass that variable to the url so it changes the dropdown to reflect the change and therefore pull the appropriate data.

    This is what I have so far, but, obviously, it doesn't work.
    PHP Code:
    <?php
        
    if (!isset($clientRep)) {
            
    $clientRep=$visitor;
        }
        
    $result=mysql_query("SELECT * FROM users WHERE marketing='on' ");
        print(
    "<select name='clientRep' onchange=location.replace('gaContactsEdit.php?ContactID=$ContactID&edit=1&clientRep=$clientRep')> ");
        
    //print("<option>Client Rep ");
        
    while ($row mysql_fetch_array($result)) {
            
    $FirstName $row["FirstName"];
            
    $LastName $row["LastName"];
            
    $wholeName "$FirstName $LastName";
            
    $LoginID[] = $row["loginID"];
            while (list(
    $key$val) = each ($LoginID)) {
                if (
    $val==$clientRep) {
                    
    $wholeName "$firstName $lastName";
                    
    printf("<option value='%s' selected>%s "$val$wholeName);
                    
    $clientRep=$val;
                }
                else {
                    
    printf("<option value='%s'>%s "$val$wholeName);
                } 
                
            }
        } 
        print(
    "</select>");
    ?>
    I thought about putting it in a form with hidden fields to repass the variables to the url (the current page this code is in has variables passed to it already so I'll need to repass them again). But I don't think you can have a form-in-a-form. I couldn't come up with a good javascript to do the same either. I've been having brain farts all day, so any sudgestions, comments, or dirogitory remarks will be welcome.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  2. #2
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone??
    Joe Eliason
    Just a dog learnin' PHP from cat.

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry Joe, I have been back to this post several times today and had anticipated on answering you, but for the life of me I am just not following what you are trying to do here, could you clarify?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wouldnt JavaScript do this for you automatically and instantly? Where as in php, the user would have to reload the form or hit submit, to the new options.
    i dunno...

  5. #5
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The page I'm making is for our Intranet. I'm making an application for our marketing department. Each person in our marketing department has a certain number clients they are over. Each client has contact persons, with one default contact.

    The page I'm making is for editing/adding a new contact for a client. The marketing department want's the page to be able to only display the group of clients according to the individual marketing manager logged into the system. For example, if I'm logged in, it shows clients A, B and C. If fready is logged in it shows clients D, E and F, and so on. This way, when I am setting up a contact for a client, I only get the client list that pertains to me, no all 100. This part is easy and I can do.

    What I'm trying to do is improve this a little by allowing a marketing manager to choose which client group to show, incase they need to view/change/add to someone else's group. I want to do this by adding a dropdown box with the different client managers. It defaults to load the current manager logged into the system. Again, I can do this, no problem. Where I run into the problem is when I change the manager in the dropdown. This is what I want it to do:

    When the manager is changed in the dropdown, to re-query the page and load the client list for the new manager. If I'm editing a client contact, I need it to pass the contact info needed to re-query the database so it can reload the contact's information into the form for editing.

    My idea is basically simple. With an OnChange of a dropdown, refresh the page with the same contact information, but new client information.

    A little more information to help clarify. One contact can belong to several clients (like a broker). When the client group displays, it's in check box form so I can assign the contact to the appropriate client(s). All this is done and working already. I'm just having a problem with the re-querying of the page to display the new client group for the new manager in the dropdown.

    It sounds easy, and it probably is, but I can't get it to work. While writing this I've thought of just submitting the whole form, but passing a variable somewhere to let the page know not go the the database entry on submit, but to refresh the information on the screen. An if refresh then do this / else update the database type of deal. I'll work on it some more this morning and see if I can figure it out.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check out these two tutorials :

    chainedSelectors: A Better Way to Drop-down a PHP List :
    ----------------------------------------------------------
    http://www.zend.com/zend/tut/drop-down.php

    Loading JavaScript Arrays with MySQL Data :
    ----------------------------------------------------------
    http://devshed.com/Server_Side/MySQL/JS_Arrays/

  7. #7
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll check'em out and let you know what I find.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  8. #8
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I checked out the links by philip and though they are both good articles, they don't really do quite what I'm trying to do. All I want to do is have a dropdown box that, when changed, will re-query the database and refresh the screen with the new client list according to the manager in the dropdown box. If the contact form is for a new contact, all I need to do is update the clients for the manager. If I'm updating a contact, then I'll need to pass the contacts information back to the page so it fills the form fields so the contact information can be edited, AND update the client list to reflect the new manager.

    I'll keep working on it, but I welcome anyone other ideas.

    ps-The code in my first post is just a snip of the whole page. The whole page has over a couple hundred lines of code. It is a multi-purpose page that loads the form discribed above and then edits the database on submition. So if that confused anyone (thinking that that was my whole page), I'm sorry and should have clarified that better. I'll also see if I can put a link to a screen shot of the page.
    Last edited by HotDog; Mar 8, 2001 at 13:20.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  9. #9
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    The drop down is different than what I am doing on my page. but the answer to your question will answer a problem for me.
    Shop Table
    shop_id
    shop (Market Rep)

    Category Table
    category_id
    category (Customer)

    Shop_Category Table
    shop_id
    category_id

    This is a many to many table relationship and may be more than what you want. But it will also work for the many to one.

    One shop may have 5 categories. Another shop may have 2 categories (one of which is shared with the first shop).

    Now what you want is to be able to pull up the assignments and modify them by moving a customer from one Market Rep to another.

    What is the current table construction? That is the first step, what do we have to work with?

    peace

  10. #10
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I figured it out. First let me explain how the page works. It's a basic multi-function page. It starts out by asking if isset($edit). If not then it loads a list of all the contacts. After choosing a contact it passes a value of edit1 to the page and the edit form opens allowing me to edit the contact. I then have a couple hidden inputs. One just copies the contactID so when the form is resubmitted it knows who to look up. The other one is :

    Code:
    <input type="hidden" name="edit" value="2">
    This along with some handy-dandy javascript will allow me to submit the form but will tell the PHP page where to take the information.

    I then wrote a javascript:

    Code:
    <script language=javascript>
    function refresh() {
    	document.newContactFrm.edit.value= 1;
     	document.newContactFrm.submit();
    }
    </script>
    I then attached this function to an onChange="refresh()" of the managers select field of the form.

    The way I pass the manager to the <select> field is as follows:

    PHP Code:
    <?php
    if (!isset($clientRep)) {
        
    $clientRep=$visitor;
    }
    $result=mysql_query("SELECT * FROM users WHERE marketing='on' ");
    print(
    "<select name='clientRep' onchange=\"refresh()\">\n\t\t\t\t\t\t\t");
    //print("<option>Client Rep \n\t\t\t\t\t\t\t");
    while ($row mysql_fetch_array($result)) {
        
    $FirstName1 $row["FirstName"];
        
    $LastName1 $row["LastName"];
        
    $wholeName "$FirstName1 $LastName1";
        
    $LoginID[] = $row["loginID"];
        while (list(
    $key$val) = each ($LoginID)) {
            if (
    $val==$clientRep) {
                
    $wholeName "$FirstName1 $LastName1";
                
    printf("<option value='%s' selected>%s \n\t\t\t\t\t\t\t"$val$wholeName);
                
    //$clientRep=$val;
            
    }
            else {
                
    printf("<option value='%s'>%s \n\t\t\t\t\t\t\t"$val$wholeName);
            } 
            
        }

    print(
    "</select>\n\t\t\t\t\t\t\t");
    I look to see if $clientRep is set, and if not it inputs the value of the cookie $visitor, the user of the machine. But I gave the <select> field the name of clientRep so when the form gets passed it will update the php variable $clientRep with the new selection.

    I then have a 3rd check in my PHP file the if $edit=2 then it will update the database with the form information. At which point it just refresh the page back to the starting page.

    Works pretty slick. I just needed to sleep on it I guess.

    If anyone has the same problem, or would like the whole code behind it, just let me know.
    Last edited by HotDog; Mar 8, 2001 at 14:53.
    Joe Eliason
    Just a dog learnin' PHP from cat.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •