guyfromfl Posted May 13, 2007 Share Posted May 13, 2007 Im creating a payroll program for a local business to clock in and out. The customer wants a drop box with the 9 employees that work for him, then the employee enters a pin as their password. The problem is he wants the drop box to be formated like this: Shmoe, Joe where the lastname and first name are different rows in the db but I made them into 1 string when i populated the <select>. I would like to return the value of the empId I have in the table but I don't want to display the number-- just the name. Is there anyway to reference empId or should i just use str_getcsv or a function like that get the employee's row from the db? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/ Share on other sites More sharing options...
karatekid36 Posted May 13, 2007 Share Posted May 13, 2007 Are you saying that you do not want the empId in the pull down menu? Quote Link to comment https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/#findComment-251709 Share on other sites More sharing options...
guyfromfl Posted May 13, 2007 Author Share Posted May 13, 2007 right he only wants lastName, firstName in the drop box, but its not really a good idea to reference the different employees by only their name.... kinda what i wanted was for each entry in the drop box it would say their name and then some how associate their employee number with out showing it in the drop box. Quote Link to comment https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/#findComment-251712 Share on other sites More sharing options...
MadTechie Posted May 13, 2007 Share Posted May 13, 2007 erm.. drop down menus can "display" the name but have a value of the "id" i use this all the time.. Quote Link to comment https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/#findComment-251714 Share on other sites More sharing options...
guyfromfl Posted May 13, 2007 Author Share Posted May 13, 2007 damn it. i just tried adding that tag...thats what i wanted thanks Quote Link to comment https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/#findComment-251718 Share on other sites More sharing options...
karatekid36 Posted May 13, 2007 Share Posted May 13, 2007 Okay here is the code that will create the pull down menu for you. This will get the menu to pull the name from the table. You obviously need to replace the right database info into the query. I was having a similar issue with this because I also did not want to refer to people by their name. I wanted to use their ID number. I think I have thought of a way around it, but let me know if you want to know about that. <?php $query = "SELECT empID, CONCAT_WS(' ', last_name, first_name) AS name FROM emp ORDER BY last_name, first_name ASC"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"{$row['user_id']}\">{$row['name']}</option>\n"; } } else { echo "No results found"; } } else { echo "Query failed<br />$query<br />". mysql_error(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/#findComment-251719 Share on other sites More sharing options...
guyfromfl Posted May 13, 2007 Author Share Posted May 13, 2007 i like your code better thanks alot!! Quote Link to comment https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/#findComment-251722 Share on other sites More sharing options...
guyfromfl Posted May 13, 2007 Author Share Posted May 13, 2007 so how do you get the employee # on the other page? Quote Link to comment https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/#findComment-251723 Share on other sites More sharing options...
karatekid36 Posted May 13, 2007 Share Posted May 13, 2007 The # is the value in the pull down menu. You can submit it to a another table or pass the variable in any way you want. Quote Link to comment https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/#findComment-251769 Share on other sites More sharing options...
guyfromfl Posted May 13, 2007 Author Share Posted May 13, 2007 according to HTML i have: <select> <option value=0>mom, your</select> <option value=1>mom, my</select> </select> (where 0 & 1 are the empId [primary keys from my MySQL db]) then the form is post... so in formPostFile.php: $mom = $_post['value'] ? i cant get php to return any thing from the html tags. the problem im having is just passing the empId from 1.php to 2.php and still associating the employee names with the empId....I know how to $_POST and $_GET but not when the identifier is a tag within an <option>... thanks for your help. sorry i went to the pub for a few so that might not make sense.. Quote Link to comment https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/#findComment-251831 Share on other sites More sharing options...
Barand Posted May 13, 2007 Share Posted May 13, 2007 Your select needs a name <select name='employee'> <option value=0>mom, your</select> <option value=1>mom, my</select> </select> When form is posted, $emp = $_POST['employee']; Quote Link to comment https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/#findComment-251869 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.