Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/51133-the-best-way-to-reference/
Share on other sites

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.

 

 

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();
  }
  
?>

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..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.