SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have created a page that has a query on it.
    it's intent is to select a business group and
    have the names of everyone who belongs to that group be displayed on another page.
    this is what i have so far:<?php

    $dbcnx = @mysql_connect("localhost", "root", "password");
    mysql_select_db("employeeprofiles");

    //get details about employee selected
    $employeedetailsbgroup = mysql_query("SELECT name FROM employees WHERE bgroup = $employeebgroup");

    ?>


    <FORM ACTION="view.php" METHOD=POST>
    </SELECT><BR>
    By Business Group:
    <SELECT NAME="$employeebgroup" SIZE=1>
    <OPTION SELECTED VALUE="">Any Business Group
    <option>Transportation
    <option>Information Systems
    <option>Mep
    <option>Telecom
    <option>Marketing
    <option>Accounting
    </SELECT><BR>
    <BR>
    <INPUT TYPE=SUBMIT NAME="submit" VALUE="submit">
    </FORM>

    what do i need to do from here ? i am i headed in the right direction ?


    ------------------
    bl@cky

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Check out Part 4 of my series: Building a Database-Driven Web Site using PHP and MySQL for plenty of sample code in this area. If you have any specific questions after reading that, feel free to post back and I'll help you in any way that I can.


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  3. #3
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow! Kevin youíre the reason I started writing
    this php/mysql app. I did your tutorial last week it was great. It was very clear and precise. After finishing it, I decided to see if I could apply php/mysql in the workplace.
    I chose to make an employee database for my company's intranet. Although it probably doesn't look like in now, this is based on you joke database. At first I tried to simply structure around your database, but I quickly got lost. So I decided to see if I could do it from scratch. I looked around the web at other php sites and did some more tutorials. This is the result so far. It goes without saying that I am more of a butter knife than a butch knife, I ain't to sharp! I am not at a loss as what I need to do. I am not sure if I have just absorbed too much in a sort time period or jus reached my mental limits
    If you have any comments as to what I should be doing I want to hear them. Like I said youíre the one that got me hooked on php and now I all want is to learn more about it.
    I think itís really cool to know that the authors here look at the forums.

    Thanks



    ------------------
    bl@cky

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ok, well the code you have so far (above) can be divided into two parts: some PHP code and an HTML form.

    The PHP code connects to the MySQL server, specifies which database it wants to use, then retrieves a list of all the names of the employees in group $employeegroup. Obviously, $employeegroup must be specified somehow for this code to work (more on that in a moment). Also, you'll need to write some code to actually display the result set (the list of names) you have retrieved. The section "Handling SELECT Result Sets" in Part 4 of my series covers that.

    The form code you've come up with seems to be intended to let the user pick the $employeegroup to be used by the PHP code. There are several problems with the code you've come up with -- some more fundamental than others:

    <UL TYPE=SQUARE>
    <LI>You have a &lt;/SELECT&gt; tag immediately following your &lt;FORM&gt; tag that has no business being there.
    <LI>Your &lt;SELECT&gt; tag has NAME="$employeegroup". If you want this selection to be translated into a PHP variable when the form is submitted, it should be NAME="employeegroup" (notice no dollar sign).
    <LI>The &lt;OPTION&gt; tags should have VALUE's assigned to them, so that the resulting $employeegroup variable gets the selected VALUE.
    <LI>Presuming you're not only storing your employees, but also your employee groups in the database (just as I stored the jokes as well as the joke categories in the database in my article), the &lt;OPTION&gt; tags should be generated from a list of employee groups retrieved from the database.
    </UL>

    If that wasn't enough to stress those brain cells, you have to consider th fact that you want to display the form first, then have it submit to the PHP code that uses the employee group selected in the form to get the listing from the database. So you'll have to break your page up into a "multipurpose page" (a term I coined in Part 3 of my series), which displays only the form when it is first loaded, but when reloaded as a result of that form being submitted will run the PHP code and get the listing of employees from the database.

    Hope this gives you plenty of food for thought. I'm at your disposal if you need any help with the specifics.

    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  5. #5
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for helping me Kevin.
    At first I did have the form pull the different business groups from a separate table at referenced back to the employee table, just like you had in you tutorial.
    I started to have problems with other parts of the form when I added an option to select a specific user and view that data.
    So to simplify things I just added the business groups to the employee table. The line of thinking was that it would just be easier to perform a query on the groups that way. I haven't yet started to write the part of the form to select just a user. I wanted to get this to work first.
    About making this a multipurpose page, in order to do that don't I need to change
    FORM ACTION="view.php" to Form action ="&lt;?php echo($PHP_SELF);?&gt;" , then add some kind of echo statement ?
    well on a happy note, I just created a form to add all the info to the database and it works great! one thing I did was make a drop down box with the groups so that way all entries into that part of the table would be uniform.
    thank you for helping me with all this, it is really nice being able to talk to someone about php/mysql issues.




    ------------------
    bl@cky


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
  •