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");
//get details about employee selected
$employeedetailsbgroup = mysql_query("SELECT name FROM employees WHERE bgroup = $employeebgroup");
<FORM ACTION="view.php" METHOD=POST>
By Business Group:
<SELECT NAME="$employeebgroup" SIZE=1>
<OPTION SELECTED VALUE="">Any Business Group
<INPUT TYPE=SUBMIT NAME="submit" VALUE="submit">
what do i need to do from here ? i am i headed in the right direction ?
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.
Helping Small Business Grow Online!
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 http://www.SitePoint.com/forums/smile.gif
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.
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:
<LI>You have a </SELECT> tag immediately following your <FORM> tag that has no business being there.
<LI>Your <SELECT> 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 <OPTION> 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 <OPTION> tags should be generated from a list of employee groups retrieved from the database.
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.
Helping Small Business Grow Online!
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 ="<?php echo($PHP_SELF);?>" , 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.