Welcome, Guest. Please Login.
04/28/24 at 16:47:46
News:
Home Help Search Login


Pages: 1
Send Topic Print
Linux Gurus: Drop down box (Read 5687 times)
Kelloggs
Active Member
*****


Do crazy people know
they are crazy?

Posts: 785
Gender: male
Linux Gurus: Drop down box
07/28/08 at 13:41:49
 
This code will populate the drow down box with values from a db table.
The box will show the Last Name and First name.  
 
How do I send the Employee ID, when a user select an Employee? I dont want to show the Emp ID on the drow down box.
 
The uni_emp_db.php show what the Employee has select : echo $_POST["D1"]; rather than the record ID
 
Any ideas?  
 
thank you all
 
 
 
<form method="post" action="uni_emp_db.php?">
<select size="1" name="D1">
<?
//SQL Query
$sql = "SELECT * FROM uni_emp";
 
mysql_connect("localhost", "root", "")  or die("Unable to connect to SQL server");
    $max = 0;
    $bmax = mysql_db_query("intranet", $sql);
    while ($result = mysql_fetch_array($bmax)) {
    $FN =$result['Y'];
    $LN=$result['MM'];
?>    
 <option value"<? echo $ID; ?>"><? echo $FN; ?> &nbsp;&nbsp;<? echo $LN; ?></option>
 
<?
}  
mysql_close();
?>
</select></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
Back to top
 
 

Evo ERP - 35 Users
Dumped MS Access like a hot potato (VB.Net rules!!!)
Email WWW   IP Logged
kkmfg
Senior Member
****


Ghost of the code

Posts: 411
Gender: male
Re: Linux Gurus: Drop down box
Reply #1 - 07/28/08 at 16:22:35
 
Woah... That all was kind of hard to follow. If I were you I'd not switch in and out of PHP so much. It just sprays <? and ?> all over the code and actually runs slower because the PHP interpreter has to start/stop/start/stop. I'm going to clean the code up a bit here. The main thing you'll notice is that once PHP is entered it does not exit until no more dynamic output exists. Then, when standard HTML will do PHP is exited. Also, you seem to want to set a value to the option tags.  This is the correct thing to do in your case. The value passed with the value tag is what is sent to the form handler (uni_emp_db.php)
 
<form method="post" action="uni_emp_db.php">   //I took the ? out. Why do you need it?
<select size="1" name="D1">
<?
//SQL Query
$sql = "SELECT * FROM uni_emp";
 
mysql_connect("localhost", "root", "")  or die("Unable to connect to SQL server");
    
    $max = 0;
    $bmax = mysql_db_query("intranet", $sql);
    while ($result = mysql_fetch_array($bmax)) {
      $FN =$result['Y'];
      $LN=$result['MM'];
      print("<option value='" . $ID . "'>" . $FN . "  " . $LN . "</option>"); //you didn't have a = between value and the value to set
    }  
    
   mysql_close();
?>
 
</select></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
 
 
That should work. The option lines that are output from the above should look like:
<option value='3424'>Collin  K</option>
 
When this option is selected the value returned by D1 would be 3424.
 
One last note: PHP doesn't automatically add line breaks and so you need to add them or the whole of the php output will be one really long line. The way to switch to a new line is to add \n to the output. So the line of code which generates the option tag could be switched to:
print("<option value='" . $ID . "'>" . $FN . "  " . $LN . "</option>\n");
Back to top
 
« Last Edit: 07/29/08 at 04:08:29 by kkmfg »  

Collin
K & K Manufacturing, Inc

EvoERP Version 1-22-10 SP3
5 User Workgroup Pervasive 10
Email WWW   IP Logged
kkmfg
Senior Member
****


Ghost of the code

Posts: 411
Gender: male
Re: Linux Gurus: Drop down box
Reply #2 - 07/28/08 at 16:26:03
 
Oh, and I'm pretty sure that if you use " to delineate strings (which I did in my example) then you don't need to terminate the string and use the concatenate operator like I did. You can just plain put the $FN and $LN right in the string. But I have a bad habit of breaking it up like I did in my example and I'm set in my ways... I haven't even bothered to double check whether I've been over complicating things.
Back to top
 
 

Collin
K & K Manufacturing, Inc

EvoERP Version 1-22-10 SP3
5 User Workgroup Pervasive 10
Email WWW   IP Logged
Kelloggs
Active Member
*****


Do crazy people know
they are crazy?

Posts: 785
Gender: male
Re: Linux Gurus: Drop down box
Reply #3 - 07/29/08 at 12:23:15
 
Thanks for you help.
I havent had the time to test it because i have big problems. Mysql server keeps crashing. It has been happening for at least 4 days every night around 11.00 PM
and today during bussiness hours. No idea what is happening, and no idea where to get a MySQl consultant if there is any here in alberta, canada.
 
Heres is the log:
 
mysqld[8287]: 080729 11:17:36 [Warning] Found an entry in the 'db' table with empty database name; Skipped
mysqld[8287]: 080729 11:17:36 [Note] /usr/sbin/mysqld: ready for connections.
mysqld[8287]: Version: '5.0.45-Debian_1ubuntu3.3-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  Debian etch distribution
/etc/mysql/debian-start[8555]: Upgrading MySQL tables if necessary.
/etc/mysql/debian-start[8559]: Looking for 'mysql' in: /usr/bin/mysql
/etc/mysql/debian-start[8559]: Looking for 'mysqlcheck' in: /usr/bin/mysqlcheck
"/etc/mysql/debian-start[8559]: This installation of MySQL is already upgraded to 5.0.45, use --force if you still need to run mysql_upgrade"
/etc/mysql/debian-start[8568]: Checking for insecure root accounts.
/etc/mysql/debian-start[8572]: WARNING: mysql.user contains 4 root accounts without password!
/etc/mysql/debian-start[8573]: Checking for crashed MySQL tables.
mysqld[8287]: 080729 11:17:41 [Note] /usr/sbin/mysqld: Normal shutdown
mysqld[8287]:
mysqld[8287]: 080729 11:17:41  InnoDB: Starting shutdown...
/etc/mysql/debian-start[8617]: WARNING: mysqlcheck has found corrupt tables
/etc/mysql/debian-start[8617]: intranet.ms_invcouny
/etc/mysql/debian-start[8617]: warning  : 1 client is using or hasn't closed the table properly
/etc/mysql/debian-start[8617]: intranet.sys_users
/etc/mysql/debian-start[8617]: warning  : 1 client is using or hasn't closed the table properly
/etc/mysql/debian-start[8617]: winventory.system_security_temp
/etc/mysql/debian-start[8617]: warning  : 1 client is using or hasn't closed the table properly
/etc/mysql/debian-start[8617]:
/etc/mysql/debian-start[8617]:  Improperly closed tables are also reported if clients are accessing
/etc/mysql/debian-start[8617]:  the tables *now*. A list of current connections is below.
/etc/mysql/debian-start[8617]:
mysqld[8287]: 080729 11:17:46  InnoDB: Shutdown completed; log sequence number 0 251877174
mysqld[8287]: 080729 11:17:46 [Note] /usr/sbin/mysqld: Shutdown complete
mysqld[8287]:
mysqld_safe[8620]: ended
mysqld_safe[8698]: started
mysqld[8701]: 080729 11:17:46  InnoDB: Started; log sequence number 0 251877174
mysqld[8701]: 080729 11:17:46 [Warning] Found an entry in the 'db' table with empty database name; Skipped
mysqld[8701]: 080729 11:17:46 [Note] /usr/sbin/mysqld: ready for connections.
mysqld[8701]: Version: '5.0.45-Debian_1ubuntu3.3-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  Debian etch distribution
/etc/mysql/debian-start[8736]: Upgrading MySQL tables if necessary.
/etc/mysql/debian-start[8741]: Looking for 'mysql' in: /usr/bin/mysql
/etc/mysql/debian-start[8741]: Looking for 'mysqlcheck' in: /usr/bin/mysqlcheck
"/etc/mysql/debian-start[8741]: This installation of MySQL is already upgraded to 5.0.45, use --force if you still need to run mysql_upgrade"
/etc/mysql/debian-start[8749]: Checking for insecure root accounts.
/etc/mysql/debian-start[8753]: WARNING: mysql.user contains 4 root accounts without password!
/etc/mysql/debian-start[8754]: Checking for crashed MySQL tables.
mysqld[8701]: 080729 11:18:22 [Note] /usr/sbin/mysqld: Normal shutdown
Back to top
 
 

Evo ERP - 35 Users
Dumped MS Access like a hot potato (VB.Net rules!!!)
Email WWW   IP Logged
kkmfg
Senior Member
****


Ghost of the code

Posts: 411
Gender: male
Re: Linux Gurus: Drop down box
Reply #4 - 07/30/08 at 04:33:51
 
Hmmm... I use MySQL but not on Debian... It's never done to me what is happening to you.
 
From the look of your log it appears that it's crashing pretty quickly, reloading, crashing, reloading, crashing time and time again. Is that accurate?
 
Have you tried running /usr/bin/mysqlcheck yourself?
 
Also, what I have done before to test daemon problems is to read the appropriate run script for the daemon, find the command that actually does the running, and manually type that in. You can bypass all the other junk that way but you may not be able to automatically shutdown the service anymore. You'd likely have to kill the processes to get rid of it (or reboot.) Mysql is usually started with mysqld_safe so you could look up how to properly call that yourself and try it.
Back to top
 
 

Collin
K & K Manufacturing, Inc

EvoERP Version 1-22-10 SP3
5 User Workgroup Pervasive 10
Email WWW   IP Logged
Kelloggs
Active Member
*****


Do crazy people know
they are crazy?

Posts: 785
Gender: male
Re: Linux Gurus: Drop down box
Reply #5 - 07/30/08 at 09:49:10
 
Thanks for the advice.
 
What was happing is that the "/" Drive was full (99%). Some how a cron job was not moving a backup tar file to the main server.
 
I notice that when I try to start mysql with is default values: datadir = /var/lib/mysql
 
I am a self taught linux user, and there lot of things learn still.
 
Thank again
 
Kelloggs
Back to top
 
 

Evo ERP - 35 Users
Dumped MS Access like a hot potato (VB.Net rules!!!)
Email WWW   IP Logged
kkmfg
Senior Member
****


Ghost of the code

Posts: 411
Gender: male
Re: Linux Gurus: Drop down box
Reply #6 - 07/30/08 at 10:59:12
 
Yeah, I wouldn't have initially guessed that the cause was that the drive was full but I have seen really odd things happen when that is the case. It's almost impossible to tell what sort of oddities will occur once a mount point gets full (be it /, /usr, /home, /var)
 
At least you figured it out!
Back to top
 
 

Collin
K & K Manufacturing, Inc

EvoERP Version 1-22-10 SP3
5 User Workgroup Pervasive 10
Email WWW   IP Logged
Kelloggs
Active Member
*****


Do crazy people know
they are crazy?

Posts: 785
Gender: male
Re: Linux Gurus: Drop down box
Reply #7 - 07/30/08 at 12:19:30
 
Your code does work.
I need to add the $ID=$result['ID'];
 
 Cheesy
 
Kelloggs
Back to top
 
 

Evo ERP - 35 Users
Dumped MS Access like a hot potato (VB.Net rules!!!)
Email WWW   IP Logged
kkmfg
Senior Member
****


Ghost of the code

Posts: 411
Gender: male
Re: Linux Gurus: Drop down box
Reply #8 - 07/30/08 at 14:44:00
 
Quote from Kelloggs on 07/30/08 at 12:19:30:
Your code does work.
I need to add the $ID=$result['ID'];

Cheesy

Kelloggs

 
 
Heh, yeah I kind of wondered about that. I had no idea where $ID was coming from but I just basically redid your code as it was.
Back to top
 
 

Collin
K & K Manufacturing, Inc

EvoERP Version 1-22-10 SP3
5 User Workgroup Pervasive 10
Email WWW   IP Logged
Pages: 1
Send Topic Print