Re: [PHP-DB] printf() in a variable, or alternative to printf()
Are you looking for the sprintf() function? graeme mayo wrote: I need to be able to format data. Printf() is perfect because I need a certain amount of characters (30 for address). However I need this formatted data to be inside a file that's fwrite() and then FTPed to a distributor who will parse it and input into their database. printf(% 4d,$orderID[0]); does not work in $thisContent= data . moredate . evenmoredata . ; In effect I need the output of printf() to be placed inside a variable and I don't see how to do that. Str_pad(), of course, does not work. Thx for any hints. mayo -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL JOIN query : Seeking solution - Please Help
Get those with transaction into a php array Get those without transaction into a php array Then use array_diff() (or one of its variants) graeme. jinxed wrote: I am still new to this, but I turned the manual upside down, or at least I tried. I am designing a payroll application by which payslips can be processed for each employee for each period. The problem lays where I would like to display a list of employees that don't have transactions (payslips) for a particular period. I can easily display a list of employees that do have transactions (payslips) for a particular period. I tried reversing this, but it doesn't seem to work, or I'm missing something somewhere. Please help. # Table structure for table `employees` emp_idemp_numemp_titleemp_surnameemp_nameemp_initials emp_termdate // etc. INSERT INTO `employees` VALUES (1, 'EMP001', 'Mrs.', 'Surname1', 'Name1', 'N1.', '-00-00'); INSERT INTO `employees` VALUES (2, 'EMP002', 'Mr.', 'Surname2', 'Name2', 'N2.', '-00-00'); INSERT INTO `employees` VALUES (3, 'EMP003', 'Mr', 'Surname3', 'Name3', 'N3.', '-00-00'); INSERT INTO `employees` VALUES (4, 'EMP004', 'Mr.', 'Surname4', 'Name4', 'N4.', '2003-08-31'); INSERT INTO `employees` VALUES (5, 'EMP005', 'Mr.', 'Surname5', 'Name5', 'N5.', '2004-02-28'); INSERT INTO `employees` VALUES (6, 'EMP006', 'Mr.', 'Surname6', 'Name6', 'N6.', '-00-00'); INSERT INTO `employees` VALUES (7, 'EMP007', 'Mr.', 'Surname7', 'Name7', 'N7.', '-00-00'); # Table structure for table `payperiods` pp_idpp_periodpp_status INSERT INTO `payperiods` VALUES (1, 'JAN 2004', 'inactive'); INSERT INTO `payperiods` VALUES (2, 'FEB 2004', 'active'); # Table structure for table `transactions` CREATE TABLE `transactions` ( `tran_id` int(11) NOT NULL auto_increment, `pp_id` int(11) NOT NULL default '0', `emp_id` int(11) NOT NULL default '0', `tran_basicsal` decimal(11,2) NOT NULL default '0.00', `tran_OT_rate` decimal(11,2) NOT NULL default '0.00', `tran_OT_qty` decimal(11,2) NOT NULL default '0.00', `tran_DT_rate` decimal(11,2) NOT NULL default '0.00', `tran_DT_qty` decimal(11,2) NOT NULL default '0.00', `tran_bonus` decimal(11,2) NOT NULL default '0.00', `tran_commission` decimal(11,2) NOT NULL default '0.00', `tran_travelall` decimal(11,2) NOT NULL default '0.00', `tran_cellall` decimal(11,2) NOT NULL default '0.00', `tran_leavepdout_days` decimal(11,2) NOT NULL default '0.00', `tran_leavepdout_rate` decimal(11,2) NOT NULL default '0.00', `tran_uif_emp` decimal(11,2) NOT NULL default '0.00', `tran_uif_com` decimal(11,2) NOT NULL default '0.00', `tran_sdl` decimal(11,2) NOT NULL default '0.00', `tran_paye` decimal(11,2) NOT NULL default '0.00', `tran_staffloan` decimal(11,2) NOT NULL default '0.00', `tran_unpaidleave_days` decimal(11,2) NOT NULL default '0.00', `tran_unpaidleave_rate` decimal(11,2) NOT NULL default '0.00', `tran_leave_taken` decimal(10,2) NOT NULL default '0.00', `tran_sl_taken` decimal(11,2) NOT NULL default '0.00', PRIMARY KEY (`tran_id`) ) TYPE=MyISAM PACK_KEYS=0 AUTO_INCREMENT=12 ; # # Dumping data for table `transactions` # INSERT INTO `transactions` VALUES (6, 1, 1, '3500.00', '29.84', '1.00', '39.78', '1.00', '40.00', '10.00', '20.00', '30.00', '0.00', '159.12', '36.70', '36.70', '36.70', '366.96', '50.00', '0.00', '159.12', '0.00', '0.00'); INSERT INTO `transactions` VALUES (7, 1, 2, '2000.00', '17.04', '1.00', '22.72', '1.00', '40.00', '10.00', '20.00', '30.00', '0.00', '90.88', '21.40', '21.40', '21.40', '213.98', '50.00', '0.00', '90.88', '0.00', '0.00'); INSERT INTO `transactions` VALUES (8, 1, 3, '9000.00', '68.18', '1.00', '90.90', '1.00', '40.00', '10.00', '20.00', '30.00', '0.00', '409.05', '92.59', '92.59', '92.59', '925.91', '50.00', '0.00', '409.05', '0.00', '0.00'); INSERT INTO `transactions` VALUES (11, 2, 1, '3500.00', '29.84', '1.00', '39.78', '1.00', '40.00', '10.00', '20.00', '30.00', '0.00', '159.12', '36.70', '36.70', '36.70', '366.96', '50.00', '0.00', '159.12', '0.00', '0.00'); INSERT INTO `transactions` VALUES (10, 2, 7, '2200.00', '16.67', '1.00', '22.22', '1.00', '40.00', '10.00', '20.00', '30.00', '0.00', '99.99', '23.39', '23.39', '23.39', '233.89', '50.00', '0.00', '99.99', '0.00', '0.00'); # My query is as follows: ?php // IF COUNT OF EMPLOYEES DIFFER WITH COUNT OF TRANSACTIONS, DO THIS // DISPLAY ONLY EMPLOYEES THAT DON'T HAVE TRANSACTIONS FOR THE CURRENT (active) PERIOD. else { $t1 = 'employees'; $t2 = 'transactions'; $selectempquery = mysql_query(SELECT DISTINCT $t1.*, $t2.emp_id FROM $t1 LEFT JOIN $t2 ON $t1.emp_id=$t2.emp_id WHERE NOT $t1.emp_termdate AND ($t2.pp_id != '$pp_id' OR $t2.pp_id IS NULL)); // This doesn't work right // if i replace the above AND with: AND $t2.emp_id IS NULL); // it won't
Re: [PHP-DB] php and tables
1st Get your SQL to ORDER BY points DESC 2nd use PHP to get the details on row at a time and display the results in an HTML table. The specifics will depend on what your table looks like, for example if you don't have a points column then you may need to get SQL to calculate it. graeme. Vikas Nanda wrote: Hi I am new to php and mysql and am having a few problems that I hope someone can help with. What I am trying to do is to display ratings for particular teams using some basic code. I needed to print the information out on a table with the highest average at the top and then ascending. I have all this info stored in a mysql db. eg TEAMPLAYED WIN LOSS DRAW POINTS AVERAGE ENGLAND 16 6 6 4 16 1.00 I don't know how to print variables out in a table and I don't know how to make it ascending. Any help would be much appreciated. Thanks Vikas Send instant messages to your online friends http://uk.messenger.yahoo.com -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySql and PHP question
From memory earlier versions of MySQL don't support subselects. The latest (and greatest) does so you may want to check the version you are using - I can't remember when it was introduced, I have since switched to PostGreSQL... all the best, graeme. Juffermans, Jos wrote: Hi, I'm afraid I can't help you with the query - I'm used to Oracle which as a bigger set of SQL commands. I can help you with your PHP question. If you want to put a variable in a query, you can add the variable directly into the string: $sql_query = select zg_longitude from zip_code where zg_zipcode = '$zipcode'; Or (my favorite choice) you can break the string and add the variable with .'s: $sql_query = select zg_longitude from zip_code where zg_zipcode = ' . $zipcode . '; With the first option, it is not always clear what is the variable and what not. Jos -Original Message- From: ReClMaples [mailto:[EMAIL PROTECTED] Sent: 07 April 2005 06:04 To: PHP Subject: [PHP-DB] MySql and PHP question All, I have a question as how I can return some results that I am looking for. Ideally I'd like to run this sql statement but for some reason MySql won't allow me to run it: SELECT * FROM zip_code WHERE zg_latitude between ((select zg_latitude from zip_code where zg_zipcode = '78730')- 2) and ((select zg_latitude from zip_code where zg_zipcode = '78730') + 2) and zg_longitude between ((select zg_longitude from zip_code where zg_zipcode = '78730') - 2) and ((select zg_longitude from zip_code where zg_zipcode = '78730') + 2) I get an error to check the mysql manual. This statement runs in an oracle environment though. I guess I am stuck with writing multiple queries and them tying them together. In PHP how can I put a variable into the sql statement (if that's possible). Let's say I have these queries: select zg_longitude from zip_code where zg_zipcode = '78730' This one pulls the zg_longitude from the zip_code table where the zip_code is 78730 for instance. I want to take the result (one record) and put it in this sql statment replacing 'result here': select * from zip_code where zg_longitude = ('result here'-2) and zg_longitude = ('result here'+2) order by zg_city asc Can anyone help me with this or point me in a better direction? Thanks -Rich -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] changing output method
Try putting your print \t$col_value\n immediately after the foreach... foreach ($line as $col_value) print \t$col_value\n; remember to remove teh semi-colon after the foreach line. graeme. chintan wrote: as usual my database is in mysql and there are lots of records available i had wrote my script like this $link = mysql_connect(localhost, chintan,hellomysql) or die(Could not connect); mysql_select_db(chintan) or die(Could not select database); $query = SELECT * FROM stockiestandbookingagents; $result = mysql_query($query) or die(Query failed); $i=0; while($imysql_num_fields($result)) { echo (mysql_field_name($result, $i)); print \t; while ($line = mysql_fetch_array($result)) { foreach ($line as $col_value); } $i++; print \t$col_value\n; } mysql_free_result($result); mysql_close($link); but it just displays the pincode of the city only(the last column) the table structure is like below; +--+--+--+-+-+---+ | Field| Type | Null | Key | Default | Extra | +--+--+--+-+-+---+ | CompanyName | varchar(50) | | PRI | | | | AddressLine1 | varchar(100) | YES | | NULL| | | AddressLine2 | varchar(100) | YES | | NULL| | | City | varchar(50) | YES | | NULL| | | PostalCode | varchar(50) | YES | | NULL| | +--+--+--+-+-+---+ -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Why isn't this working?
For more efficient code try the explode() function (You really only want to use the regular expression functions for complex pattern matching, looking for a comma is about as simple as it gets so use the standard string functions) explode (',',$Agent_Rep); graeme. Rasmus Lerdorf wrote: Chris Payne wrote: Hi everyone, Im trying to split a string by comma, but its not working, can you see any reason that the below doesnt work? $keywords = preg_split(',','$Agent_Rep'); Not sure why you sent this to php-db, but have another look at the preg_split documentation. You need '/,/' there to split on a comma. -Rasmus -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] password in md5 to connect to mysql instead of clear password
Not answering your question but I'd put the connect info into a separate include file. This should then be placed in a directory that can be accessed by the Web Server but not by any other user (except root). Then when you need to establish a connection you just need to include the file. graeme. Gael Lams wrote: Hi all I use the classic following rows to connect to a mysql database. I always put $passsword in clear in the php connection file and I wonder whether there is a way to have it in md5 so that someone reading the file could not use it to connect to the db. I googled a bit but find only threads explaining how to have password saved in md5 inside a mysql table which is not I would like to do Regards, Gaƫl function SQLConnect() { $server_name = 'localhost'; $db_name = 'cmsdb'; $user_name = 'user'; $password = 'clearpassword'; if (!$dbconnect = mysql_connect($server_name, $user_name, $password)) { echo Connection failed to the host 'localhost'.; exit; } if (!mysql_select_db($db_name)) { echo Cannot connect to database '.$db_name.'; exit; } } __ Do you Yahoo!? Yahoo! Mail - Easier than ever with enhanced search. Learn more. http://info.mail.yahoo.com/mail_250 -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Connecting To Mysql through php/mysqli
I like the idea of a mysqli_queasy() function. Maybe it would allow you to sumbit SQL statements that don't conform to any standard? ;) graeme. Bastien Koert wrote: the second error is a misspelling in the mysqli_query command bastien Call to undefined function mysqli_quesry() in C:\Apache -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] foreach()
try... $z = array('foo' = array('bar'), 'dis' = array('dat')); foreach($z as $key = $value) { echo $key br $value[0] /p; } graeme. Yemi Obembe wrote: Hi folks. wat can be done to dis: $z = array('foo' = array('bar')), 'dis' = array('dat')); foreach(//???) { echo //??? br //?? /p; } to output dis: foo bar dis dat - A passion till tomorrow, Opeyemi Obembe | ng.clawz.com - Do you Yahoo!? The all-new My Yahoo! What will yours do? -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] foreach()
or even... $z = array('foo' = array('bar'), 'dis' = array('dat')); while (list($key, $val) = each($z)) { echo $keyBR $val[0]p; } You need to remove the superfluous close bracket on after bar, and the val is an array hence $val[0] to get the element displayed. graeme. Han wrote: Try this : -- $z = array('foo' = array('bar')), 'dis' = array('dat')); while (list($key, $val) = each($z)) { echo BR$key $val; } - Original Message - From: Yemi Obembe [EMAIL PROTECTED] To: php-db@lists.php.net Sent: Monday, January 31, 2005 9:47 AM Subject: [PHP-DB] foreach() Hi folks. wat can be done to dis: $z = array('foo' = array('bar')), 'dis' = array('dat')); foreach(//???) { echo //??? br //?? /p; } to output dis: foo bar dis dat - A passion till tomorrow, Opeyemi Obembe | ng.clawz.com - Do you Yahoo!? The all-new My Yahoo! - What will yours do? -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] timestamp
Can you post your code up and tell us what system you are using? cheers, graeme Balwant Singh wrote: dear bastien thanks for the reply... but i checked it again but it is giving only 1970-01-01. is something else needs to be done. with best wishes balwant On Mon, 2005-01-31 at 19:46, Bastien Koert wrote: This code : ? $timestamp = Fri Jan 28 19:53:09 2005; $date = date(Y-m-d,strtotime($timestamp)); echo $date; ? gave me this result 2005-01-28 Exactly as it should. Bastien From: Balwant Singh [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: Bastien Koert [EMAIL PROTECTED] CC: php-db@lists.php.net Subject: RE: [PHP-DB] timestamp Date: 31 Jan 2005 10:02:04 +0530 thanks I tried strtotime also but getting 1970-01-01 not 2005-01-28. my problem is that the date is given to me in string format i.e.Fri Jan 28 19:53:09 2005. Any other help will be appreciated. with best wishes balwant On Sat, 2005-01-29 at 22:45, Bastien Koert wrote: try $date = date(Y-m-d,strtotime($timestamp)); Best thing to use if you want to do calcs on date/time data is to use the unix time stamp...translates the timestamp into seconds since 01-01-1970...Much simpler to use in sql queries Bastien From: Balwant Singh [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] timestamp Date: 29 Jan 2005 19:47:35 +0530 i am facing a problem i have timestamp in string format -- Fri Jan 28 19:53:09 2005 now i want to get the date from it. is it possible? pls. help. on using strftime(%D,$timestamp) it is giving 01/01/70. May pls. help me. Also pls. let me know whether calculation can be done in mysql on this string timestamp. pls. inform. with best wishes balwant -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim
Re: [PHP-DB] timestamp
The code works fine on my system, so what version of php are you using and what is your operating system? graeme. Balwant Singh wrote: i just copy your code and paste into a test file. ? $timestamp = Fri Jan 28 19:53:09 2005; $date = date(Y-m-d,strtotime($timestamp)); echo $date; ? with best wishes balwant On Tue, 2005-02-01 at 10:33, Bastien Koert wrote: pls post relevant code bastien From: Balwant Singh [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: Bastien Koert [EMAIL PROTECTED] CC: php-db@lists.php.net Subject: RE: [PHP-DB] timestamp Date: 01 Feb 2005 10:13:40 +0530 dear bastien thanks for the reply... but i checked it again but it is giving only 1970-01-01. is something else needs to be done. with best wishes balwant On Mon, 2005-01-31 at 19:46, Bastien Koert wrote: This code : ? $timestamp = Fri Jan 28 19:53:09 2005; $date = date(Y-m-d,strtotime($timestamp)); echo $date; ? gave me this result 2005-01-28 Exactly as it should. Bastien From: Balwant Singh [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: Bastien Koert [EMAIL PROTECTED] CC: php-db@lists.php.net Subject: RE: [PHP-DB] timestamp Date: 31 Jan 2005 10:02:04 +0530 thanks I tried strtotime also but getting 1970-01-01 not 2005-01-28. my problem is that the date is given to me in string format i.e.Fri Jan 28 19:53:09 2005. Any other help will be appreciated. with best wishes balwant On Sat, 2005-01-29 at 22:45, Bastien Koert wrote: try $date = date(Y-m-d,strtotime($timestamp)); Best thing to use if you want to do calcs on date/time data is to use the unix time stamp...translates the timestamp into seconds since 01-01-1970...Much simpler to use in sql queries Bastien From: Balwant Singh [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] timestamp Date: 29 Jan 2005 19:47:35 +0530 i am facing a problem i have timestamp in string format -- Fri Jan 28 19:53:09 2005 now i want to get the date from it. is it possible? pls. help. on using strftime(%D,$timestamp) it is giving 01/01/70. May pls. help me. Also pls. let me know whether calculation can be done in mysql on this string timestamp. pls. inform. with best wishes balwant -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim
Re: [PHP-DB] timestamp
what output do you get from the following? ?php $timestamp = Fri Jan 28 19:53:09 2005; echo $timestamp .br; $date = date(Y-m-d,strtotime($timestamp)); echo $date .br; phpinfo(); ? graeme wrote: The code works fine on my system, so what version of php are you using and what is your operating system? graeme. Balwant Singh wrote: i just copy your code and paste into a test file. ? $timestamp = Fri Jan 28 19:53:09 2005; $date = date(Y-m-d,strtotime($timestamp)); echo $date; ? with best wishes balwant On Tue, 2005-02-01 at 10:33, Bastien Koert wrote: pls post relevant code bastien From: Balwant Singh [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: Bastien Koert [EMAIL PROTECTED] CC: php-db@lists.php.net Subject: RE: [PHP-DB] timestamp Date: 01 Feb 2005 10:13:40 +0530 dear bastien thanks for the reply... but i checked it again but it is giving only 1970-01-01. is something else needs to be done. with best wishes balwant On Mon, 2005-01-31 at 19:46, Bastien Koert wrote: This code : ? $timestamp = Fri Jan 28 19:53:09 2005; $date = date(Y-m-d,strtotime($timestamp)); echo $date; ? gave me this result 2005-01-28 Exactly as it should. Bastien From: Balwant Singh [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: Bastien Koert [EMAIL PROTECTED] CC: php-db@lists.php.net Subject: RE: [PHP-DB] timestamp Date: 31 Jan 2005 10:02:04 +0530 thanks I tried strtotime also but getting 1970-01-01 not 2005-01-28. my problem is that the date is given to me in string format i.e.Fri Jan 28 19:53:09 2005. Any other help will be appreciated. with best wishes balwant On Sat, 2005-01-29 at 22:45, Bastien Koert wrote: try $date = date(Y-m-d,strtotime($timestamp)); Best thing to use if you want to do calcs on date/time data is to use the unix time stamp...translates the timestamp into seconds since 01-01-1970...Much simpler to use in sql queries Bastien From: Balwant Singh [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] timestamp Date: 29 Jan 2005 19:47:35 +0530 i am facing a problem i have timestamp in string format -- Fri Jan 28 19:53:09 2005 now i want to get the date from it. is it possible? pls. help. on using strftime(%D,$timestamp) it is giving 01/01/70. May pls. help me. Also pls. let me know whether calculation can be done in mysql on this string timestamp. pls. inform. with best wishes balwant -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] i am lost (php warning)
The mysql_num_rows function requires that the argument passed to it should be a valid MySQL result from a Select statement. Your script doesn't explicitly establish a connection with the database so you could be getting an error from that call, hence $sql_query would not be a valid MySQL result. Try adding the following: if (!$sql_query) { die('Invalid query: ' . mysql_error()); } graeme Earl Clare wrote: Hi ya'll, I am lost as to why I am getting this error in my script. Can anyone kindly explain why this is so. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/cm/public_html/cell/login.php --- My script --- if($_POST['submit'] == 'Log In') { $user=$_POST[email]; $pass=$_POST[pass]; $sql_query = mysql_query(SELECT * FROM cm_customer WHERE emial='$user'); $sql_query = mysql_num_rows($sql_query); if (($sql_query) 0) { $valid = $user; session_start(); session_register(valid); } } if (session_is_registered(reg)) { echo ok; } else { echo sorry; } -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim
Re: [PHP-DB] Assistance on Query
Can you do what you require by grouping by your type. setting a count field and then a where count 3? However if you then need to know the details from the three consecutive fields then I don;t think it can be done in SQL so you'll need to revert to php. graeme Jochem Maas wrote: Shannon Doyle wrote: Hi Jochem, My apologies, when I typed consecutive, I meant by date. Basically the query is for a report. The client wants to be able to see when there have been 3 or more entries of non_services_type between services_type entries, and then display these entries. I am using MySQL and would Order the entries by date. I hope that clears things up a little. yeah! I can't think how to do that offhand in SQL but in php it would go a little like this...(I'm assuming an array of results is being passed - where each item in the array is an object.): function filter3ConsecutiveNST($rows) { $output = $tmp = array(); $cNSTcount = 0; foreach ($rows as $row) { if ($row-type == 'non_service_type') { $cNSTcount++; if ($cNSTcount == 3) { $output =+ $tmp; $output[] = $row; $tmp = array(); } else if ($cNSTcount 3) { $output[] = $row;} else { $tmp[] = $row; } } else { $tmp = array(); $cNSTCount = 0; } } return $output; } hope that give you an idea. - Shannon -Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Monday, January 17, 2005 1:37 AM To: Shannon Doyle Cc: php-db@lists.php.net Subject: Re: [PHP-DB] Assistance on Query Shannon Doyle wrote: Hi People, I would like some assistance on the following scenario. I have to pull out all records for a particular userid (easy enough) and then only show those entries where the follwing occurs. These records from the table will contain either an entry in the services_type field or the non_services_type field. What I need to do is show only those where the number of consecutive records that contain an entry in the non_services_type field is greater than or equal to 3 so example:- record 1 contains an entry in non_services_type record 2 contains an entry in services_type record 3 contains an entry in non_services_type record 4 contains an entry in non_services_type record 5 contains an entry in non_services_type record 6 contains an entry in services_type so I would need to display records 3,4,5 only Can anyone assist me with this? Could you explain what the logic behind doing this is. i.e. Why? (it might help to understand the problem, and possibly give a solution that does not rely on 'consecutiveness') I'm guessing you are using MySQL which is a relational DB, that means the order of records stored is essentially abstracted from the DB user, for instance using an ORDER BY clause will change the order of the result and therefore the 'consectiveness' of the values. It looks as if you will need to post-process the result set in PHP to get what you want, alternatively your DB may support stored procedures which could be an alternative (but harder to do than to do it in PHP) i.e. the stored procedure works out the correct rows and then outputs the result when you something like: SELECT * FROM getConsecServiceRows( 3 ) rgds, Jochem Cheers, Shannon -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Dealing With MySQL's new Time Calculations
Set your select to group by userid, select on min(tourney.start) value and max(tourney.start) value where closed = 1 etc. graeme. [EMAIL PROTECTED] wrote: I have an interesting problem I'm trying to solve. Right now, I'm keeping track of sessions starting and ending times with a PHP datetime field, and calculating the total time spent in all sessions with the new PHP time command... something like this: $total_minutes = mysql_query(select ((sum(time_to_sec(timediff(tourney.finish, tourney.start/ (60*60)) FROM tourney WHERE tourney.closed = '1' AND tourney.userid = '$userid'); but the problem is that in some cases, there are overlapping sessions or tourneys. That is, someone might have a tourney.start at 10:00 with a tourney.finish at 10:45 and start another tourney.start at 10:15 and finish at 10:55. right now, i'd get the sum of both sessions, 45 minutes + 40 minutes = 85 minutes, where I'd rather have the calculation of 10:00 (the earliest start) to 10: 55 (the latest finish), for a total of 55 minutes. I can't get my head around the right logic to use to get to an answer like that. There may be hundreds of registered tourneys, so testing one against the rest to see if there is a matching time seems very wasteful and sloppy. Any suggestions on how I might proceed? Perhaps a one time query when I add the record into the database (that would make changing the record difficult) to compare the session time to other session times somehow? Thanks in advance Jake mail2web - Check your email from the web at http://mail2web.com/ . -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Dealing With MySQL's new Time Calculations
Sorry that should have been max(tourney.finish) :-[ graeme graeme wrote: Set your select to group by userid, select on min(tourney.start) value and max(tourney.start) value where closed = 1 etc. graeme. [EMAIL PROTECTED] wrote: I have an interesting problem I'm trying to solve. Right now, I'm keeping track of sessions starting and ending times with a PHP datetime field, and calculating the total time spent in all sessions with the new PHP time command... something like this: $total_minutes = mysql_query(select ((sum(time_to_sec(timediff(tourney.finish, tourney.start/ (60*60)) FROM tourney WHERE tourney.closed = '1' AND tourney.userid = '$userid'); but the problem is that in some cases, there are overlapping sessions or tourneys. That is, someone might have a tourney.start at 10:00 with a tourney.finish at 10:45 and start another tourney.start at 10:15 and finish at 10:55. right now, i'd get the sum of both sessions, 45 minutes + 40 minutes = 85 minutes, where I'd rather have the calculation of 10:00 (the earliest start) to 10: 55 (the latest finish), for a total of 55 minutes. I can't get my head around the right logic to use to get to an answer like that. There may be hundreds of registered tourneys, so testing one against the rest to see if there is a matching time seems very wasteful and sloppy. Any suggestions on how I might proceed? Perhaps a one time query when I add the record into the database (that would make changing the record difficult) to compare the session time to other session times somehow? Thanks in advance Jake mail2web - Check your email from the web at http://mail2web.com/ . -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Input ++90 causing problems
Hi, I was able to trick IE but not Firefox to display some of the characters you had displayed. 212- By selecting the encoding Arabic ASMO 708 and then selecting auto select in the encoding. On IE with right to left it appears -212 followed by the two characters that look like a sleepy 9 with a u on top. I suspect that it is an issue with the encoding. Have you tried to state the encoding to use in your HTML? graeme ioannes wrote: When I copy the php page and paste in a new page, upload that, and view with the same ? variables, it works (the css works and no js errors), however when I use the original php page, and then change the URL manually in the IE address line, it again does not work (css screwed up etc)! - Original Message - From: graeme [EMAIL PROTECTED] To: ioannes [EMAIL PROTECTED] Cc: php-db@lists.php.net Sent: Friday, January 14, 2005 8:17 AM Subject: Re: [PHP-DB] Input ++90 causing problems It appears as plus sign and numbers on my computer. graeme. ioannes wrote: It appears that the code below in short has the following problematic strings: ++90 ++90-212- gives 212- on my test page below: error2.htm. A clue might be that a search on google turns up Arabic unicode, and the input here was done in Turkey. check the link: http://www.londonriverside.co.uk/error2.htm and let me know if it appears the same to you or is a function of my computer, which includes Japanese libraries. (In order to send this message I need to choose unicode formatting.) ++90 ++90 gives ++90 ++90 on error3.htm - and is correct The string ++90 came from a web input form, where someone was putting in their phone number. It was stored in a database and retrieved onto a web page, all using php, on which page it screwed up the css and caused unusual javascript errors. Although when the same person input the same phone number on the same form again, the same problem did not occur all the time but did re-occur at least twice. I cut down the HTML and finally found these few figures seemed to be the cause, though if I used my HTML editor to applyt auto-formatting to the page the error did not occur. Also if I simply deleted the ++90 characters and typed them in again and uploaded that, there were no errors. Confusingly, href links to other pages requiring a query to be run on the same record in the database - although it does not require to retrieve and show the phone number on the htm page but does use the index reference of the record - fails to retrieve any information for the record, eg my dates just default to 01/01/1970 erroneously and other info is retrieved on the record, in this case there is no css problem or javascript error in the static HTML, just no data to show within the page. Also note that when I get into the table and cut and paste all the info to a new record, the new record works - ie I can retrieve it with same tel numbers and everything works. Is there something about this string ++90 that is problematic, possibly in relation to being sent from an internet form initially? If it's simply a familiar error from Arabic unicode perhaps I should be filtering this out on all input pages? are there other such problematic strings? what am I searching for if I search for good input filtering for web input forms? John I did the following test pages: error2.htm: html head titletest/title LINK href=styles/test.css type=text/css rel=stylesheet /head body text=#00 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 bgcolor=#ff table width=1000 border=1 cellspacing=0 cellpadding=0 trtd class=textset3 colspan=12 ++90 ++90-212- /td/tr/table /body /html error3.htm: html head titletest/title LINK href=styles/enquiries_css.css type=text/css rel=stylesheet /head body text=#00 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 bgcolor=#ff table width=1000 border=1 cellspacing=0 cellpadding=0 trtd class=textset3 colspan=12 ++90 ++90 /td/tr/table /body /html -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim
Re: [PHP-DB] Input ++90 causing problems
It appears as plus sign and numbers on my computer. graeme. ioannes wrote: It appears that the code below in short has the following problematic strings: ++90 ++90-212- gives 212- on my test page below: error2.htm. A clue might be that a search on google turns up Arabic unicode, and the input here was done in Turkey. check the link: http://www.londonriverside.co.uk/error2.htm and let me know if it appears the same to you or is a function of my computer, which includes Japanese libraries. (In order to send this message I need to choose unicode formatting.) ++90 ++90 gives ++90 ++90 on error3.htm - and is correct The string ++90 came from a web input form, where someone was putting in their phone number. It was stored in a database and retrieved onto a web page, all using php, on which page it screwed up the css and caused unusual javascript errors. Although when the same person input the same phone number on the same form again, the same problem did not occur all the time but did re-occur at least twice. I cut down the HTML and finally found these few figures seemed to be the cause, though if I used my HTML editor to applyt auto-formatting to the page the error did not occur. Also if I simply deleted the ++90 characters and typed them in again and uploaded that, there were no errors. Confusingly, href links to other pages requiring a query to be run on the same record in the database - although it does not require to retrieve and show the phone number on the htm page but does use the index reference of the record - fails to retrieve any information for the record, eg my dates just default to 01/01/1970 erroneously and other info is retrieved on the record, in this case there is no css problem or javascript error in the static HTML, just no data to show within the page. Also note that when I get into the table and cut and paste all the info to a new record, the new record works - ie I can retrieve it with same tel numbers and everything works. Is there something about this string ++90 that is problematic, possibly in relation to being sent from an internet form initially? If it's simply a familiar error from Arabic unicode perhaps I should be filtering this out on all input pages? are there other such problematic strings? what am I searching for if I search for good input filtering for web input forms? John I did the following test pages: error2.htm: html head titletest/title LINK href=styles/test.css type=text/css rel=stylesheet /head body text=#00 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 bgcolor=#ff table width=1000 border=1 cellspacing=0 cellpadding=0 trtd class=textset3 colspan=12 ++90 ++90-212- /td/tr/table /body /html error3.htm: html head titletest/title LINK href=styles/enquiries_css.css type=text/css rel=stylesheet /head body text=#00 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 bgcolor=#ff table width=1000 border=1 cellspacing=0 cellpadding=0 trtd class=textset3 colspan=12 ++90 ++90 /td/tr/table /body /html -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Slow Query
How many agents do you have? If the number of agents is small then you could set up a temp table which has a link to the agent, the client, and a calculation of the distance between the two. Then do your search on this temp table. Once you have the answer you want delete the records for this client. (that should allow for more than one client entering data at the same time, although you may want to properly think that scenario through) graeme. Wendell Frohwein wrote: First of all I would like to thank anyone who lends a hand in this matter. Here is what im working with. Redhat 9, PHP 5.0.2, Apache/2.0.50, MySQL 4.1.8-standard Binary Installation for pc-linux-i686, OpenSSL 0.9.7d, gcc version 3.2.2. PHP compiled with mysql, and mysqli capability. This is how the script works: The client submits a property for an appraisal. Based on the appraisal type and property zip code, It searches the database for agents / appraisers with the zip code in question (property zip code) in there coverage area (zip codes they are willing to do appraisal work for). So when it finds a match, It adds that order to there potential order list. It then waits for the to accept or decline the order. If accepted the order becomes there's and alerts all the other agents / appraisers that this order has already been accepted. The do the work, send it back job is done. This works fine right now rather it be a single order placed by a client, or a spreadsheet imported to the system with 2000 orders or more. So now you're saying if it works, why are you here asking for help? Well instead of searching agents with the exact zip code match, I would like to search a radius of zip codes. The first search would be a 2 mile radius, the next search (incase the first did not return any result) would be 5 mile radius. I purchased some software (php / mysql sql files) that contains every zipcode in the united states along with a longitude and latitude for each zip code. So the zip code script provided with this software allows you to 1) enter a zip code and miles in radius, it will then spit out all the zip codes in that radius into an array. 2) you can give it 2 zip codes and it will tell you the distance in miles between the 2 (give or take). So I rewrote my script to do the follow: The client submits a property for an appraisal. Based on the appraisal type and property zip code, It does a radius search of 2 miles from the property zip. If no matches are found, it does a 5 mile radius search. For every zip code returned by each radius search, It searches the database for agents / appraisers with the zip code in question (zip codes from radius search) in there coverage. This is the most stressful part I am assuming. This works fine for 1 - 10 orders. But when I import 30 or more, the script pretty much hangs as well as mysql. I have to kill mysql with signal 9, start mysql it up again. Then all is back to normal. I would paste the code in here but it is really long and complicated. I was hoping on the based on the operation of the script, someone would suggest a better and faster way to search zip code radius, while matching the results to agents within the system. If I am asking for way to much time from someone, I apologize. If someone is really interested in helping me sort this out, I could send you code samples to see the process. -Wendell Frohwein -- Experience is a good teacher, but she sends in terrific bills. Minna Antrim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Problem using session bu submitting the session id through a form
Hi, Not certain what is happening try the following script. On my machine the form retains the session ID. Note the sending the ID as a GET is only done for cross checking. You can remove it and there will be no change in the display. ?php session_start(); ? html body ?php $id = session_id(); echo $id ? form action=test1.php??php echo $id? method=post input type=submit/form /body /html If you run this and don't get the session ID being maintained then there would appear to be some problem with your set up but we'll probably require more info OS php version etc. graeme. Henk Jan Wils wrote: Hi, My session only seems to work when I use the link-tag (like a href=nextpage.php?PHPSESSIONID=blahblahblah/a But when I send the sessionid within a form in a hidden tag (input type=hidden name=phpsessionid value=blahblah) the session stops. For my session working correct i have to send my sessionid at every link and at every submit. My question now is, how can i send the sessionid by using a form and not by putting the sessionid in the a-tag? Greetz Henk Jan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] SQL statement
Hi, To stop the return receipt dialog appearing in Tbird... Tools... Options... Advanced... Return Receipt and select Never send a return receipt. Or you can choose some of the other selections. graeme Jochem Maas wrote: Jason, can you please turn off the return receipts on emails you send to the list. it's bloody annoying to have 'The Sender wishes to be notified' popup messages everytime I read one of your emails (and, alas, I don't have the skill to hack the return receipt crap right out of Tbird). BTW your not the only one that has it turned on - so this goes to the rest of you as well :-) cheers! Jason Walker wrote: First off - $_POST['CompanyName'] is valid, right? ... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP query to mysql database returns emtpy data, but Query Browser shows records
Sorry I was in a hurry for lunch.. I meant category='39 ' OR category '47' etc... which of course the IN clause would address. But if it is a character string '39 47 48 172' that is required then double check the number of spaces that are required against those that are produced. Maybe is is a double digit and two spaces trip[le digit and one? Without an example of the data and what is produced it's hard to help. graeme Jochem Maas wrote: graeme wrote: Hi, You have: $query example = SELECT description from cpProducts where category='39 47 48 172' don't you want to add a logical operator such as OR, possibly AND $query example = SELECT description from cpProducts where category='39 OR 47 OR 48 OR 172' graeme. whatever it is that he is trying to do - I doubt he wants to put 'OR's in the character string, besides which AFAIK you can't do something like: SELECT description from cpProducts where category=39 OR 47 OR 48 OR 172; (possibly the SQL above will actually return all rows because any number greater than zero will evaluate to true - e.g. ($x = true || 1) is always true regardless of the value of $x, I am assuming the same general logic goes for SQL or'ing) it should be: SELECT description from cpProducts where category=39 OR 47 OR 48 OR 172; Jason, read on for more (possible) help (well I gave it a shot but I don't think it will be any help, sorry): Jason Walker wrote: Here is the query: function ReturnPackageDescriptions($pack, $cat, $hotcat, $hotid){ $comIB = $cat . . $pack . . $hotcat . . $hotid; $catLength = strlen($comIB); echo $catLength; $query = SELECT description from cpProducts where category=' . $cat . . $pack . . $hotcat . . $hotid . '; echo bR . $query . br; echo combined package number = . $comIB . br; $retval = ; $link = mysql_connect($config['host'],$config['user'],$config['pass']) or die(Could not connect); mysql_select_db('stc_store') or die(Unable to connect to the default database); $result = mysql_query($query) or die(Unable to pull the menu objects for main event details); echo mysql_affected_rows() . br; while ($results = mysql_fetch_array($result, MYSQL_ASSOC)){ extract($results); echo $description; $retval = $description; } mysql_free_result($result); mysql_close($link); return $retval; } I have some extra 'echo' statements to see the progress on the web page. If I remove the 'where' clause within the SQL statement, I get rows. But when I add the 'where' portion, no records are returned. Here is an example of what the query looks like: $query example = SELECT description from cpProducts where category='39 47 48 172' I'll assume that your table has a field named 'category' - otherwise the statement should throw you a big error :-) BUT is it a character data field (i.e. does it contain text)? AND do you actually have rows where the value of the category field is '39 47 48 172' - in order to get rows returned when running your example query the value needs to match this string EXACTLY. Given the fact that using mysql control center give you the desired result the above probably was a waste of time typing. Given that fact the only thing I can think of is that you have a extra space floating about (but I can't see it in the code your provided) does the output of mysql_error() provide any feedback? (what an odd problem!) When I run the same query in MYSQL Control center or Query Browser, no problem. I use this function template for my SELECT statements. Please let me know if there is something missing from the code. Thanks. Jason Walker [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] http://www.desktophero.com No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.298 / Virus Database: 265.6.8 - Release Date: 1/3/2005 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] str_replace question
Hi, Wild guess but does the original WHILE AND have two spaces between the WHILE and the AND? us an echo before and after and count the number of spaces. But yes it would be possible to avoid this with the judicious appearance of an if statement. graeme Chris Payne wrote: Sorry if this already went through, my SMTP server was having problems. Hi there everyone, Im having a weird problem and Im not sure why, if I try to replace WHERE AND with just WHERE it wont do it, but if I try to replace WHERE or AND by themselves it WILL do it, but I cannot replace BOTH of them from a single string, is something wrong below? $additionalsql = str_replace(WHERE AND, WHERE, $additionalsql); Basically Im trying to replace WHERE AND with just WHERE as Im building a very complex SQL query and its a difficult one, and I have a solution that works perfectly but I need this to work in order to do it. I would appreciate any help on this, as its very important. Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP query to mysql database returns emtpy data, but Query Browser shows records
Hi, You have: $query example = SELECT description from cpProducts where category='39 47 48 172' don't you want to add a logical operator such as OR, possibly AND $query example = SELECT description from cpProducts where category='39 OR 47 OR 48 OR 172' graeme. Jason Walker wrote: Here is the query: function ReturnPackageDescriptions($pack, $cat, $hotcat, $hotid){ $comIB = $cat . . $pack . . $hotcat . . $hotid; $catLength = strlen($comIB); echo $catLength; $query = SELECT description from cpProducts where category=' . $cat . . $pack . . $hotcat . . $hotid . '; echo bR . $query . br; echo combined package number = . $comIB . br; $retval = ; $link = mysql_connect($config['host'],$config['user'],$config['pass']) or die(Could not connect); mysql_select_db('stc_store') or die(Unable to connect to the default database); $result = mysql_query($query) or die(Unable to pull the menu objects for main event details); echo mysql_affected_rows() . br; while ($results = mysql_fetch_array($result, MYSQL_ASSOC)){ extract($results); echo $description; $retval = $description; } mysql_free_result($result); mysql_close($link); return $retval; } I have some extra 'echo' statements to see the progress on the web page. If I remove the 'where' clause within the SQL statement, I get rows. But when I add the 'where' portion, no records are returned. Here is an example of what the query looks like: $query example = SELECT description from cpProducts where category='39 47 48 172' When I run the same query in MYSQL Control center or Query Browser, no problem. I use this function template for my SELECT statements. Please let me know if there is something missing from the code. Thanks. Jason Walker [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] http://www.desktophero.com No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.298 / Virus Database: 265.6.8 - Release Date: 1/3/2005
Re: [PHP-DB] how to connect new html page in PHP.
The following two scripts should help you... in file Page1.php ?php echo Hello this is the first page br\n; echo This is in file Page1.phpbr\n; echo form method=\POST\ action=\Page2.php\\n; echo \tinput type=\submit\ name=\submit\ value=\Next Page\\n; echo /form\n; echo Note the input button must be wrapped in a form tagbr; echo 'Also the name attribute is the variable name that will be held in the $_POST variable'; ? in file Page2.php ?php echo We're now in Page2.phpbr\n; echo 'The submit variable is held in the $_POST variablebr'; echo $_POST[submit]; echo brTo find out what has been POSTed use the var_dump functionbr\n; echo pre\n; var_dump($_POST); echo /pre\n; ? graeme amol patil wrote: hallo , i wrote this , echo Submit = $submit;as you said. but comments in echo statements are appearing on same pages before clicking submit button and in between same pages content . i want these comment on new page or same page but without original content of that page how to connect new html page in PHP after clicking submit button let simple code is like this, ?php echo --Submit= $submit--; if ($submit) { $dbh=mysql_connect (localhost, root, ) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db (dollar1_allinfo); mysql_query(INSERT INTO totalinfo (username,password,) VALUES ('$loginusername','$loginpassword',)); echo'thank you'; echo' Hurry Up'; } ? THANK YOU. Mike S. [EMAIL PROTECTED] wrote: hallo , i have wriiten simple php script , below. created databse dollar1_allinfo with table 'totalinfo' but on clicking submit button , information entered is not entering in database. also, echo statements are also not displaying after submit if ($submit) { $db = mysql_connect(localhost,root); mysql_select_db(dollar1_allinfo,$db); mysql_query(INSERT INTO totalinfo (username,password,) VALUES ('$loginusername','$loginpassword')); echo 'thank you'; echo 'So Hurry Up'; } ? thank you. Because your query and echoes are within an if block, I'd say that $submit is evaluating to FALSE, and thus not executing the query and echoes. Add (before the if statement): echo Submit = $submit; Make sure that $submit is evaluating to TRUE. To All Beginning Programmers (Newbies), or just people who want to easily debug their code: Try adding debugging statements to help you find problems. A few echoes or prints in selected locations will help identify the issue. Make sure your variables are evaluating to values that you think they should be. If you want to keep the debugging statements in your code and just activate them when you need to see them, do something like: // near the top of your code $debug=TRUE; // and anywehere in your code if ($debug) { echo DEBUG: Submit = $submit \n; } // or whatever echo might help you nail down the problem. Put as many of these in your code and you can turm them ON and OFF very easily, by changing one line of code. OR for even quicker debugging, replace $debug=TRUE; with $debug=$_GET['debug']; and then you can turn it on in by adding ?debug=TRUE at the end of the URL. Example: http://www.php.net/path/my.html?debug=TRUE or: http://www.php.net/path/my.html?debug=1 **DISCLAIMER** Using the URL method is NOT a secure way to do this!!! And I'm sure there's plenty of folks groaning out there because it is a BIG security hole. You really would want to do this on a development machine and network, and remove the debug code for production. That really should go without saying. Good luck. :Mike S. :Austin TX USA - Do you Yahoo!? Jazz up your holiday email with celebrity designs. Learn more.
Re: [PHP-DB] data is not entering in created database
I suspect that your $submit is not set up, try the following echo statements before the if statement: echo --$submit--; echo --$_POST[submit]--; amol patil wrote: hallo , i have wriiten simple php script , below. created databse dollar1_allinfo with table 'totalinfo' but on clicking submit button , information entered is not entering in database. also, echo statements are also not displaying after submit ?php if ($submit) { $db = mysql_connect(localhost,root); mysql_select_db(dollar1_allinfo,$db); mysql_query(INSERT INTO totalinfo (username,password,) VALUES ('$loginusername','$loginpassword')); echo 'thank you'; echo 'So Hurry Up'; } ? thank you. - Do you Yahoo!? Yahoo! Mail - Easier than ever with enhanced search. Learn more. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] want to execute comments on new pages after clicking submit.
The purpose of putting the echo Submit = $submit; is to find out what is happening with your code. Once everything is working correctly they will be removed. What you need to find out is what is being held in the variable submit when you move from one page to the next, a point when you are expecting to enter the if($submit) clause. I hope that clarifies it a bit. all the best, graeme. amol patil wrote: hallo, i wrote this echo Submit = $submit; before 'if statement' but , the sentences in echo statements are executing on same pages , showing original page with these echo statement. i want to execute , some comments and tables on same page(without original contents) or on new pages , after clicking on submit button what to do for it. thank you. Mike S. [EMAIL PROTECTED] wrote: hallo , i have wriiten simple php script , below. created databse dollar1_allinfo with table 'totalinfo' but on clicking submit button , information entered is not entering in database. also, echo statements are also not displaying after submit if ($submit) { $db = mysql_connect(localhost,root); mysql_select_db(dollar1_allinfo,$db); mysql_query(INSERT INTO totalinfo (username,password,) VALUES ('$loginusername','$loginpassword')); echo 'thank you'; echo 'So Hurry Up'; } ? thank you. Because your query and echoes are within an if block, I'd say that $submit is evaluating to FALSE, and thus not executing the query and echoes. Add (before the if statement): echo Submit = $submit; Make sure that $submit is evaluating to TRUE. To All Beginning Programmers (Newbies), or just people who want to easily debug their code: Try adding debugging statements to help you find problems. A few echoes or prints in selected locations will help identify the issue. Make sure your variables are evaluating to values that you think they should be. If you want to keep the debugging statements in your code and just activate them when you need to see them, do something like: // near the top of your code $debug=TRUE; // and anywehere in your code if ($debug) { echo DEBUG: Submit = $submit \n; } // or whatever echo might help you nail down the problem. Put as many of these in your code and you can turm them ON and OFF very easily, by changing one line of code. OR for even quicker debugging, replace $debug=TRUE; with $debug=$_GET['debug']; and then you can turn it on in by adding ?debug=TRUE at the end of the URL. Example: http://www.php.net/path/my.html?debug=TRUE or: http://www.php.net/path/my.html?debug=1 **DISCLAIMER** Using the URL method is NOT a secure way to do this!!! And I'm sure there's plenty of folks groaning out there because it is a BIG security hole. You really would want to do this on a development machine and network, and remove the debug code for production. That really should go without saying. Good luck. :Mike S. :Austin TX USA - Do you Yahoo!? Yahoo! Mail - Helps protect you from nasty viruses.
Re: [PHP-DB] New to the Mailing List
Try using the if statement. Ben wrote: Morning all. I attach a document, which is used to send an email with attachments. What I need to do though, is if a form field is left blank, then that tag is not included in the email. Any clues anybody? It is vital that no information is sent for blank fields because it goes to a system that would reject and email that has tags eg '1010: ' Many thanks in advance Ben -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Question: For no results
You might want to use: mysql_num_rows function.mysql-num-rows.html -- Get number of rows in result Stuart Felenstein wrote: I want to send back a message when no matches are found on my search page. Basically No matches found. I assumed that mysql_fetch_assoc would be the determining factor on whether any rows will come back. As you can see below I do a if ($row_rsCS == false). Apparently though (while the message is sharp and centered ;)), it is not to right place, since it sends the message and exits whether records / matches exist or not. Any suggestions ? Thank you Stuart $query_limit_rsCS = sprintf(%s LIMIT %d, %d, $query_rsCS, $startRow_rsCS, $maxRows_rsCS); //print_r($query_limit_rsCS); $rsCS = mysql_query($query_limit_rsCS, $Pmmodel) or die(mysql_error()); //print_r($rsCS); $row_rsCS = mysql_fetch_assoc($rsCS); if ($row_rsCS == false) ? p align=centerstrong?php print_r (No Matches Found); ? /strong/p ?php exit; //print_r($row_rsCS); if (isset($_GET['totalRows_rsCS'])) { $totalRows_rsCS = $_GET['totalRows_rsCS']; } else { $all_rsCS = mysql_query($query_rsCS); $totalRows_rsCS = mysql_num_rows($all_rsCS); } $totalPages_rsCS = ceil($totalRows_rsCS/$maxRows_rsCS)-1;
Re: [PHP-DB] session_destroy();
Hi, I've been struggling with the same problem. The following code will destroy the session information and remove the cookie session_start(); $_SESSION = array(); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } session_destroy(); However my problem is that if I recreate the session in the same script the session file is created with exactly the same file name and creation time. Making me believe that the session is held in cache somewhere graeme. Chris Payne wrote: Hi there everyone, I need to destroy a session in the browser so when they log out it clears all the session data from the browser, I have tried: session_destroy(); But it doesnt seem to do it as the browser keeps the same PHPSessionID. What is the best way to destroy a session and generate a new sessionid without having to close the browser and go back again? Chris --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.791 / Virus Database: 535 - Release Date: 11/8/2004 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Loading large volumes of data
I'd think you want to index the table. Since you are doing a search on an un-index table for each word, that overhead will be more than creating an entry in an index table. Entering an index entry will require the routine to determine where the entry should be but it will be looking for that in a sorted list and so it will be able to determine if the entry exist or not fairly quickly, whereas the search on the unsorted list requires a search of all entries 340,000 and counting (a binary search would only require 19 comparisons ln N, sure there will still be some overhead on insert and the occasional re indexing) graeme. Evan Morris wrote: This is more a process question that is not specific to PHP, but maybe someone can help me. I have a text file containing strings. The text file is pretty massive, about 895 MB. I need to load the words in the text file into the database in such a way that there is a single occurrence of each word in the table. What this means is the script has to read each word in the file, check if the word is in the table, and if not, add it. Obviously as the table grows, the rate of execution drops because the number of checks that have to be made increases as more words are added to the table. Does anyone know of an efficient way to do this? There are over a million lines in the file, and my script is at about 340 000 having run overnight. I need to get the data into the table much faster than that. I considered hashing the file in memory (ie, doing the uniqueness checking in an associative array) but am not sure how much RAM that would consume and I don't want to crash the server. I have also not indexed the table because my gut feel was that the overhead of constantly updating an indexed table would cancel out the gain of checking an indexed table. Is that true? Any and all help, comments, etc, appreciated as always. Thanks Evan Morris [EMAIL PROTECTED] Tel: +27 11 797 3840 Fax: +27 11 803 0211 Cell: +27 82 926 3630 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Generate Menu based on database structure
Hi, Rather than writing a recursive function I'd suggest that you create a menu class and store each record as an object of the class. The menu class will have variables of id, parent, title, children, and tree. The children will be initialised to 0 and tree will be initialised to 1. You will need to write a function to find any menu object given the menu's ID, should be easy if you store each object in an array (keyed on the ID) 1) Read in a record and create a menu object 2) Get the parent object, using the parent variable and the find method 3) Increment the children variable in the parent menu object by one 4) Set the tree variable in the new menu object to the tree object in the parent object plus the value in the children object. Now add method to display the menu items and your problem should be solved. Gavin Amm wrote: Hi guys, I need to generate a menu based on the content structure of my database. The data is structured using an 'id' 'parent' relationship, for eg: id parent title 1 0 Home Page 6 1 My Page 2 9 6 My Page 3 15 9 My Page 4 21 6 My Page 5 22 9 My Page 6 23 22 My Page 7 24 22 My Page 8 25 1 My Page 9 28 25 My Page 10 I need to create a recursive loop that will create the menu. The text in the brackets is what I'm trying to achieve, the rest is just for aesthetics ease of reading. (The children of the row id=1 are the top of the menu tree, ie they will be the menu categories at the top of the web page to display the menu when the mouse hovers over it.) (Each menu item, being a menu, will have a href to it's id number.) My Page 2 (Menu_1) My Page 3 (Menu_1_1) My Page 4 (Menu_1_1_1) My Page 6 (Menu_1_1_2) My Page 7 (Menu_1_1_2_1) My Page 8 (Menu_1_1_2_2) My Page 5 (Menu_1_2) My Page 9 (Menu_2) My Page 10 (Menu_2_1) I just can't for the life of me get the numbering to work correctly in the recursion. I seem to get things like (1_1_2_1_2_3_1_2_3_4) which I can see the pattern in, but it's obviously not what I'm after.. Appreciate your help. Thanks, Gav. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Capturing a sql query
Just a thought, Could you use the set data type rather than a text to store your multiple selections? graeme. Stuart Felenstein wrote: It's more then keywords actually. There are 3 list boxes, one for states, one for industries and one for taxterm., so 50 states , industries, something like 20 i think but may grow, taxterm - not many. Plus city search, job title search, how far back in days do you want to search, and finally records per page. I'm still debating about a keyword search on the details field. It will probably be implemented. If you wanted to see the form: http://www.lurkingforwork.com/LFWSearch.php Stuart --- Joseph Crawford [EMAIL PROTECTED] wrote: why do you need more than a varchar? the persons keywords shouldnt be that much text for each agent maybe PHP+Programming+Vermont -- Joseph Crawford Jr. Codebowl Solutions [EMAIL PROTECTED] 802-558-5247 For a GMail account contact me OFF-LIST -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Newby variable error
Hi, first step in debugging...learn to love the var_dump() function :) just add the following code to the do_calculate.php function ... ?php var_dump ($_POST); echo br; // set up the pricing assignments ... This will display what is held in your $_POST variable. When you run the script at the start of your output will be the following array(2) { [beans]= string(16) Ethiopian Harrar [quantity]= string(1) 3 } Notice that beans and quantity are in double quotes. From now it should be east to fix ;) graeme. W Roothman wrote: Wizards, I am VERY new to PHP, paging through Meloni's 'PHP Essentials' I get the following error which I assume is very simple to solve, but for me. I have tried different approaches in identifying the 'price' variable with no luck: error: Notice: Undefined variable: price in c:\inetpub\wwwroot\php exercises\do_calculate.php on line 20 Notice: Undefined variable: price in c:\inetpub\wwwroot\php exercises\do_calculate.php on line 24 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Mail Function
Evening all, I've written a script which sends emails, there is no problem with that. I was wondering how I can check for email bounces, anyone know how to do that? Cheers, G :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] test post
please delete this -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Query works but can't echo variable :'(
Hey everyone, the following query and code works fine but I can't understand why I can't echo the $Date variable. I guess it doesn't work fine then :( Any ideas ? G :) $TheDate = mysql_query(select DATE_FORMAT(DateOfOrder, '%d, %m, %Y') as date from Orders Where Orders.ID = '$TransID'); while($OrderDate = mysql_fetch_array($TheDate)) { $Date = $OrderDate[DateOfOrder]; } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Replacing + with question
Hi all I want the contents of a variable to be returned to the user without the + symbols, how do I do that? This is what I have so far by the string replace function doesn't replace the spaces and display bla bla bla as I want: $AddressLine1 = urlencode($AddressLine1); $AddressLine1 = str_replace( , +, $AddressLine1); echo First Line Of Address: BR input type=text Name=AddressLine1 value=$AddressLine1BRBR; Cheers, Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Replacing + with question
Jason, thank you for reply. I tried switching the 1st 2 parameters in the str_replace function so that it now looks like this: $AddressLine1 = urlencode($AddressLine1); $AddressLine1 = str_replace(+, , $AddressLine1); Unfortunately as I am now replacing the + symbols with a space only the part up to the first space is displayed back to the user. Any ideas? Cheers again, Graeme :) - Original Message - From: Jason Wong [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, September 30, 2003 7:12 PM Subject: Re: [PHP-DB] Replacing + with question On Wednesday 01 October 2003 01:06, Graeme McLaren wrote: This is what I have so far by the string replace function doesn't replace the spaces and display bla bla bla as I want: Probably it's because you're trying to replace spaces with +. Swap your first 2 parameters. $AddressLine1 = urlencode($AddressLine1); $AddressLine1 = str_replace( , +, $AddressLine1); -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* Surprise your boss. Get to work on time. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] basic php question
Darryl, I'm not completely clear on what you mean by I need to walk table employee and see if emp2 has a record that matches by employee number From what I understand I would do something like: $query = mysql_query(select * from employee where EmployeeNo = $EmployeeNo and emp2.EmployeeNo = '$EmployeeNo'); if(mysql_num_rows($query) == 1) { mysql_query(update emp2 where emp2.id = '$SomeValue'); } else { mysql_query(insert into emp2 set X = '$X'); } hope this helps, Graeme :) - Original Message - From: Darryl [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 03, 2003 10:14 PM Subject: [PHP-DB] basic php question Greetings, I have php and mysql installed on my freebsd machine. I have a database iweb with tables employee and emp2. I need to walk table employee and see if emp2 has a record that matches by employee number. If it matches, I need to update some values in emp2. If there is no match, I need to create a new record in emp2 and load values. Is there a tutorial that shows how to do something this basic ? tips ? thanks, Darryl -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_fetch_array() question
Josh, Thank you for reply. Thank you to everyone else who replied to my email also. I solved the problem shortly after posting my question, I've now got a massive SQL query which does the trick. I was interested when you replied and part of it read: Just remember that you can only work with one mysql result per connection at a time. Can you explain a little more about that please? I don't think I fully understand what you mean. Cheers, Graeme :) - Original Message - From: Josh Johnson [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 06, 2002 12:29 PM Subject: RE: [PHP-DB] mysql_fetch_array() question I concur with Jason, but if restructuring is out of the question, just rearrange your queries like this: $query = SELECT Name, Address FROM users; $result = mysql_query($query); while($details = mysql_fetch_array($result)){ echo Name: $details[Name]; echo Address: $details[Address]; } $query2 = SELECT EmailAddress From Members; $result2 = mysql_query($query2); while($details = mysql_fetch_array($result2)){ echo Email: $Email[EmailAddress]; } The results won't come out at the same time, but you could use some logic to combine the results into an array by a common factor. Just remember that you can only work with one mysql result per connection at a time. You *may* (untested!) be able to accomplish what you want to do with two separate connections, but again, this is seriously overkill. :) I'd definitely recommend restructuring your talbes as Jason suggested. -- Josh -Original Message- From: Jason Wong [mailto:phplist;gremlins.com.hk] Sent: Wednesday, November 06, 2002 5:24 AM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] mysql_fetch_array() question On Tuesday 05 November 2002 05:47, Graeme McLaren wrote: Hi, Anyone know how I can use two mysql_fetch_array() functions similar to the code below? I've tried a few different ways but I keep getting Resource ID #4. I need to do this to retrieve an email address from one table and retrieve details from another. Cheers for any tips - I'm stumped with this one, Graeme :) $query = SELECT Name, Address FROM users; $query2 = SELECT EmailAddress From Members; $result = mysql_query($query); $result2 = mysql_query($query2); while($details = mysql_fetch_array($result) and $Email = mysql_fetch_array($result2)) { echo Name: $details[Name]; echo Address: $details[Address]; echo Email: $Email[EmailAddress]; } Unless I've missed something you're going about this the wrong way. For what you want to do, you should (in general) be able to accomplish it using just a single query. What fields do the tables 'users' and 'Members' contain? There should be a field there (like eg. userid) which links the two together. If there isn't one then you should seriously restructure your tables so that there is one. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Cats are smarter than dogs. You can't make eight cats pull a sled through the snow. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: mysql_fetch_array() question
Hi everyone, I think I've got the problem sorted, I'll soon let y'all know if it doesn't work ! Cheers, Graeme :) On Mon, 2002-11-04 at 21:47, Graeme McLaren wrote: Hi, Anyone know how I can use two mysql_fetch_array() functions similar to the code below? I've tried a few different ways but I keep getting Resource ID #4. I need to do this to retrieve an email address from one table and retrieve details from another. Cheers for any tips - I'm stumped with this one, Graeme :) $query = SELECT Name, Address FROM users; $query2 = SELECT EmailAddress From Members; $result = mysql_query($query); $result2 = mysql_query($query2); while($details = mysql_fetch_array($result) and $Email = mysql_fetch_array($result2)) { echo Name: $details[Name]; echo Address: $details[Address]; echo Email: $Email[EmailAddress]; } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql_fetch_array() question
Hi, Anyone know how I can use two mysql_fetch_array() functions similar to the code below? I've tried a few different ways but I keep getting Resource ID #4. I need to do this to retrieve an email address from one table and retrieve details from another. Cheers for any tips - I'm stumped with this one, Graeme :) $query = SELECT Name, Address FROM users; $query2 = SELECT EmailAddress From Members; $result = mysql_query($query); $result2 = mysql_query($query2); while($details = mysql_fetch_array($result) and $Email = mysql_fetch_array($result2)) { echo Name: $details[Name]; echo Address: $details[Address]; echo Email: $Email[EmailAddress]; } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] PHP Case Sensitivity
Hey all, I've had a bizarre experience. When I uploaded a php script it worked fine and when I was looking through my code I found that it shouldn't have worked because two variables had been used instead of one. What I'm meaning is, I used $Year and $year where I was just supposed to use $Year, the case insensitivity didn't seem to make a blind bit of difference. I've corrected it now and the script runs as it did previously. Did PHP just correct this at run time? Anyone know why this worked? Cheers, Graeme :) P.S. Seabird: I had a quick look at your site, it seems to work fine but I didn't look at it in any great depth. But so far so good ! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Infinite Loop?
Greetings list members. I've written the code below as part of an automatic email script. The problem with this is it seems to run in to an infinite loop. The for loop seems to get completely ignored by emails get sent constantly. I deleted the script after receiving 2500 emails ! :'( Can anyone point out what the problem with this is? while($tmp = $NowUnix) { for($i=0; $i=2; $i++) { $sendto = [EMAIL PROTECTED]; $subject = Test Automatic Email; $message = If you get this then age3.php works $message = If you get this then age3.php works $message = If you get this then age3.php works; mail($sendto, $subject, $message); } } Cheers, Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Infinite Loop?
Ah right, I thought that once the while loop condition is true it would execute the for loop then quit once the for loop had reached its condition. But really, whats happening is the while loop is continuing to run the for loop and then run through the while loop again. Ok I've got it now. Thanks for your advice. Graeme :) On Sat, 2002-11-02 at 20:41, Jason Wong wrote: On Sunday 03 November 2002 04:26, Graeme McLaren wrote: Greetings list members. I've written the code below as part of an automatic email script. The problem with this is it seems to run in to an infinite loop. The for loop seems to get completely ignored by emails get sent constantly. I deleted the script after receiving 2500 emails ! :'( Can anyone point out what the problem with this is? while($tmp = $NowUnix) You're not updating $tmp or $NowUnix inside your loop. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Time is an illusion perpetrated by the manufacturers of space. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Dealing with Unchecked Checkboxes
Hi all, thanks for all your replies, I got the problem with checkboxes fixed :) Cheers, Graeme :) - Original Message - From: [EMAIL PROTECTED] To: Graeme McLaren [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Monday, October 28, 2002 3:53 PM Subject: Re: [PHP-DB] Dealing with Unchecked Checkboxes how about a default value...so if you use a CHECKBOX_FIELD1 ENUM('Y', 'N') DEFAULT N type of definition, then if box is not checked, then it will deault to N otherwise a Y will override the default. just a thoughtdont' know if it will work for you or not... Jeff Brent Baisley brent@landove To: Graeme McLaren [EMAIL PROTECTED] r.com cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Dealing with Unchecked Checkboxes 10/28/2002 10:49 AM If you want to have an answer for each item, you should use yes/no radio buttons. With checkboxes you only get yes answer, as you are aware. The assumption is that you could care less about no answers since you are only interested in the yes set. Checkboxes reveal yes answers, radio buttons can reveal yes or no (or perhaps no answer if there is no default). If you want to stick with checkboxes, then I would have a hidden field for each checkbox you have. The hidden field could then be set with a yes or no value via javascript and an onChange event capture. On Saturday, October 26, 2002, at 05:02 PM, Graeme McLaren wrote: Hey all, I'm trying to get my head around checkboxes. I can insert checked checkboxes into a DB no problem but I get an error when the checkboxes are unchecked. -- Brent Baisley Systems Architect Landover Associates, Inc. Search Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Dealing with Unchecked Checkboxes
Hey all, I'm trying to get my head around checkboxes. I can insert checked checkboxes into a DB no problem but I get an error when the checkboxes are unchecked. I've used the following to try and handle unchecked checkboxes but I still get the error query was empty can anyone point me in the right direction? $number=count($GiftWrapping); for($a=0;$a$number;$a++) { echo $GiftWrapping[$a]; if ( empty( $GiftWrapping ) ) { $GW = 'N'; } INSERT INTO DB CODE HERE GiftWrapping = '$GW'; } Cheers in advance, Graeme :) Public Sub House() On Error Resume drink If Pint.empty = True Then Pint.refill Else Pint.drink End if stomach.add Pint MsgBox I've had stomach.count Pints MsgBox VERY DRUNK End Sub
Re: [PHP-DB] Dealing with Unchecked Checkboxes
Mihail, do u mean something like this? ? if (!isset($pick)) { echo Fill out and submit the form below.; } else { $j = count($pick); for($i=0; $i$j; $i++) { echo Pick b$pick[$i]/b is Checkedbr /; } } ? form action=? echo $PHP_SELF; ? ol liPaintinginput name=pick[] type=checkbox value=Painting //li liPlumbinginput name=pick[] type=checkbox value=Plumbing //li liElectricinput name=pick[] type=checkbox value=Electric //li /ol input type=submit value=Submit! / input type=reset value=Reset / /form Cheers, Graeme :) - Original Message - From: Mihail Bota [EMAIL PROTECTED] To: Micah Stevens [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Saturday, October 26, 2002 10:01 PM Subject: Re: [PHP-DB] Dealing with Unchecked Checkboxes Try to assign a value for each of these variables, or elements of array. If it is checked let's say is =1,otherwise=0. Then grab the whole set of variables with GET_VARS or something like this. Create the new array in the page where you insert data, and then use if's to insert data in your tables. I am pretty sure is not the cleanest way, but I hope it makes sense. Mihai On Sat, 26 Oct 2002, Micah Stevens wrote: Unchecked checkboxed do not return a value. They don't return a NULL or empty string or anything. So what you have to do is check to see if the variable is set. If it is set, then it's checked, if it's not set, then it's unchecked. Kinda sucks if your variable names are dynamic, I just erase the whole record and re-insert in that case. -Micah At 09:02 PM 10/26/2002 +0100, Graeme McLaren wrote: Hey all, I'm trying to get my head around checkboxes. I can insert checked checkboxes into a DB no problem but I get an error when the checkboxes are unchecked. I've used the following to try and handle unchecked checkboxes but I still get the error query was empty can anyone point me in the right direction? $number=count($GiftWrapping); for($a=0;$a$number;$a++) { echo $GiftWrapping[$a]; if ( empty( $GiftWrapping ) ) { $GW = 'N'; } INSERT INTO DB CODE HERE GiftWrapping = '$GW'; } Cheers in advance, Graeme :) Public Sub House() On Error Resume drink If Pint.empty = True Then Pint.refill Else Pint.drink End if stomach.add Pint MsgBox I've had stomach.count Pints MsgBox VERY DRUNK End Sub -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Inserting checkbox data
Hi all, I'm having a problem inserting a value from a checkbox into a MySQL DB. I can print out what the variable holds, the problem is it just won't go into the DB. Weird thing is when I login to SSH there isn't a NULL value for it instead that field is just blank. Anyone got any ideas what the problem is? The HTML that is used for the checkbox is: Gift Wrapping: input type=checkbox Name=GiftWrapping[] Value=\Y\ So it should theoretically insert Y into the DB Here is the code that appears to be causing the problem: $number=count($GiftWrapping); for($a=0;$a=$number;$a++) { echo $GiftWrapping[$a]; $GW = $GiftWrapping[$a]; echo $GW; } if ($Submit == Submit) { $sql = INSERT INTO SiteMember SET FirstName = '$FirstName', LastName = '$LastName' Username = '$Username', Password = '$Password', GiftWrapping = '$GW'; } Thank you in advance for any help. Graeme :) Public Sub House() On Error Resume drink If Pint.empty = True Then Pint.refill Else Pint.drink End if stomach.add Pint MsgBox I've had stomach.count Pints MsgBox VERY DRUNK End Sub
Re: [PHP-DB] Inserting checkbox data
Mihail, thanx for your advice, I've got it going now ! :) Thank you ! Richard, your points were valid, the HTML code with the slashes was just a copy n' paste from a PHP script and the comma I think I deleted by accident so its all sorted now. Thank you again! Graeme :) - Original Message - From: Mihail Bota [EMAIL PROTECTED] To: Graeme McLaren [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Friday, October 25, 2002 7:47 PM Subject: Re: [PHP-DB] Inserting checkbox data Graeme, first, extend the for loop over the if and the query for insertion of data. As you have it now, it just inserts the last element of the array. second, I think that the for loop should be $a$number. if you put =, then the loop is processing the array with the last value not assigned by you (an extra element in the array). Hope it helps. Mihai On Fri, 25 Oct 2002, Graeme McLaren wrote: Hi all, I'm having a problem inserting a value from a checkbox into a MySQL DB. I can print out what the variable holds, the problem is it just won't go into the DB. Weird thing is when I login to SSH there isn't a NULL value for it instead that field is just blank. Anyone got any ideas what the problem is? The HTML that is used for the checkbox is: Gift Wrapping: input type=checkbox Name=GiftWrapping[] Value=\Y\ So it should theoretically insert Y into the DB Here is the code that appears to be causing the problem: $number=count($GiftWrapping); for($a=0;$a=$number;$a++) { echo $GiftWrapping[$a]; $GW = $GiftWrapping[$a]; echo $GW; } if ($Submit == Submit) { $sql = INSERT INTO SiteMember SET FirstName = '$FirstName', LastName = '$LastName' Username = '$Username', Password = '$Password', GiftWrapping = '$GW'; } Thank you in advance for any help. Graeme :) Public Sub House() On Error Resume drink If Pint.empty = True Then Pint.refill Else Pint.drink End if stomach.add Pint MsgBox I've had stomach.count Pints MsgBox VERY DRUNK End Sub -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql_fetch_assoc question
Hey all, I managed to find that if I do: $MemberID = mysql_query(SELECT ID FROM SiteMember WHERE Username = '$valid_user'); $array = mysql_fetch_assoc($MemberID); print_r($array); this will produce: Array ( [ID] = 3 ) All I want is the value 3 so that I can go ahead and insert that into the Lookup table. Any ideas how I can just extract this value? I'm also not 100% clear on what mysql_fetch_assoc does, can anyone explain it? Cheers in advance, Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP and OCI NLS behaviour
Rouvas Stathis wrote: Hi, place appropriate NLS_LANG definitions in the Apache startup script (/etc/rc.d/apache ?). As a background to this, it's essential to do this because certain things happen when the module is initialised in PHP. Hence if you use putenv() to alter some Oracle defaults, it may well be too late because that option has already been set then the module was loaded (i.e. when Apache starts). Cheers, Graeme -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Help -- Oracle
Help, i'm trying to connect to a remote oracle database from win98/apache/php4 and win2k/iis/php4 but it always gives me tns error. Other apps however, works fine with the tns configuration. the php oracle module was loaded successfully on both platforms. I've tried all sorts of possibilities. path to tnsnames.ora is correct. I've even tried with ODBC but when i used it with php, i get server refused connection. However, ODBC test was successfull and other apps can work with it. Can you give us the exact error message? Cheers, Graeme -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Oracle Oci*Logon
Quoting Andrey Hristov [EMAIL PROTECTED]: Can someone tell more about OciPLogon. I'm sure Theis will add to this but here goes... :) I know that OciLogon is used frequently but the connection to the DB is shared amongst the pages so as in the common way where every page in a site uses one pair user/password use the only channel. When one script makes commit it commits all, so if two scripts subsequently made insert but one thinks that there was a fail it will issue rollback. The problem is that the other script issued commit and rollback does nothing. Someone can tell that the decision is using OciNLogon - ok but I know that this is the most time consuming way to connect to Oracle. The refined question is: Does OciPlogon is like OciLogon - one channel, one scripts commits/rollbacks all statements, or it is like OciNLogon but the connection is not made everytime a scripts want such but used already created one?. Oracle connections work across 3 levels, the server, the session and the service. AFAIK, transactions work at the service level which is the 'top' level. Persistent connections operate at the session level. Tus a persistent connection is maintained across Apache children by keeping the bottom level or server context open. We did run into problems because we have very high traffic sites and we have 100 Apache children running. Because our junior programmer decided to hammer the server with a web stress tool, al the children ran up connections which combined with connections on other web server made us run out of sessions. Dropping back to icologon() for a while helped the problem. Anyway, to answer your question, persistent logins will not affect transactions across processes as far as I'm aware. There may be some locking/isolations issues if a simultaneous read/write occurs but Oracle should handle that anyway. ocinlogon() is used to guarantee an isolated connection which will not affect any outstanding transactions. You only usually do this when you want to do a seperate set of operations in the middle of a transaction in a script. One more question : When PHP and Oracle works on one machine to make all work the enviroment variable ORACLE_HOME has to be set for example : /***/ // set ORACLE Dir to get the NET8 name resolver working // tnsnames.ora has to be in $ORACLE_HOME/networking/admin/ putenv(ORACLE_HOME=/home/oracle01/app/oracle/product/8.1.5); This is bad. As Theis has pointed out proviously, PHP modules perform certain operations at Apache startup and shutdown as well as script startup and shutdown. Setting things like ORACLE_HOME, NLS_LANG and so on in your script can cause some problems as some of the module has already been initialised before your script executes. You're better off putting this stuff in somewhere like the apachectl script. /***/ but if my web server is an Apache under windows and the oracle is on other machine under Linux(RH), what have to be done to make my PHP work with the DB. Windows is a slightly different beast. Normally the environment stuff is handled in windows and you don't need to setup anything with putenv. Use your Net8 Configuration assistant which is part of the Oracle Windows client libraries to create the correct TNSNAMES.ORA. AFAIK (I've never tried not to) you must specify the SID when connecting under windows in a PHP script. Cheers, Graeme -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] oracle (oci8) intro
Quoting Cynic [EMAIL PROTECTED]: Hi there, I'm in a situation where I need to produce a small app on top of an Oracle server really quickly. I'm quite a seasoned developer, but have only experience with MySQL so far. It's my understanding that Oracle lacks the MySQL's LIMIT feature. Looking at the OCI section of the PHP manual, it also looks like there's no OCIDataSeek() or some equivalent. Since the app I need to build will be a standard report builder with paging, I need this functionality. What is the common way to achieve this? Always fetch all rows, cycling through the resultset, discarding the records that preceed the one I want to start displaying with, and quit when I reach the one where the page should end? Is there a PHP + OCI tutorial somewhere? I need an intro to Oracle, and I need it now. :( Thies has an Oracle/PHP tutorial online at http://conf.php.net/ which may be of some assitance. The LIMIT problem is a real bitch is Oracle. There are a few ways to get around it, the most obvious people use being ROWNUM. However, ROWNUM does not listen to sorting which makes life amusing. One option is to try a query like the following: SELECT * FROM (SELECT field1, field2 FROM table WHERE id10 ORDER BY field1 DESC) WHERE ROWNUM11 which gives you 10 rows, but still leaves the question of paging behind unless you use between values. I can't say I've tried paging record sets though. Cheers, Graeme -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] OCIDefineByName/OCIBindByName help?
Quoting Barry Prentiss [EMAIL PROTECTED]: Hi, Can anyone help me to understand the OCIBindByName/OCIDefineByName functionality when used with the Oracle 'returning' clause? These two functions are seriously under-documented at PHP.net. I need the sequence-generated ID created during an insert for further manipulation. I tried sequence-name.currval but got an error. Here's some code that doesn't work: $sql = insert into mdfaq values (null,'$Question','$Answer') returning ID into :ID; $stmt = ociParse($conn,$sql); OCIBindByName($stmt,:ID,$faq_ID,-1); You don't need to pass by reference and you should be able to ommit the length parameter. You should probably bind $Question and $Answer as well. That way your queries will be more efficient and you dont have to worry about escaping quotes. Also your SQL should be INSERT INTO mdfaq VALUES (sequence.nextval, '$Question', '$Answer') returning ID into :id ID should be the column name of your primary key column. ocidefinebyname is useful for pulling columns out of Oracle so you don't need to make calls to ociresult() all the time. I actually don't see much benefit over using fetchstatement() Cheers, Graeme Cheers, Graeme -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] OCIDefineByName/OCIBindByName help?
Quoting Barry Prentiss [EMAIL PROTECTED]: Hi, Can anyone help me to understand the OCIBindByName/OCIDefineByName functionality when used with the Oracle 'returning' clause? These two functions are seriously under-documented at PHP.net. I need the sequence-generated ID created during an insert for further manipulation. I tried sequence-name.currval but got an error. Here's some code that doesn't work: $sql = insert into mdfaq values (null,'$Question','$Answer') returning ID into :ID; $stmt = ociParse($conn,$sql); OCIBindByName($stmt,:ID,$faq_ID,-1); You don't need to pass by reference and you should be able to ommit the length parameter. You should probably bind $Question and $Answer as well. That way your queries will be more efficient and you dont have to worry about escaping quotes. Also your SQL should be INSERT INTO mdfaq VALUES (sequence.nextval, '$Question', '$Answer') returning ID into :id ID should be the column name of your primary key column. ocidefinebyname is useful for pulling columns out of Oracle so you don't need to make calls to ociresult() all the time. I actually don't see much benefit over using fetchstatement() Cheers, Graeme Cheers, Graeme -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] MSSQL: Spaces in database name
Quoting Robert D. Young [EMAIL PROTECTED]: That did it! Using: ... stuff $dbname = [Test Database]; ... more stuff mssql_select_db($dbname); worked perfectly. Again, Thanks! This is standard Microsoft (and maybe ODBC?) syntax. Using square brackets will work on most things including table names and field names with spaces in them. This will work fine SELECT [table space].[field space] FROM [table space] It doesn't mean that you should go around putting spaces in your database objects. That's never a good idea :) Cheers, Graeme -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] ORACLE 8 randomly unsucessful execution
Do you get an Oracle error code back? What version of PHP are you using? Cheers, Graeme -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Ludo Sent: Saturday, 23 June 2001 1:31 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] ORACLE 8 randomly unsucessful execution Hi! We encounter a weird problem here: from time to time, after a up-time of one week for instance, the PHP pages cannot execute some PL/SQL stored procedures (most of the time it works, but sometimes it doesn't). We solve the problem by restarting Apache, but having no idea of where the problem comes from ... Any idea? Ludo. Here is ou PHP configure script: ./configure \ --with-oracle=/home/oracle/u01/app/oracle/product/8.1.6 \ --with-oci8=/home/oracle/u01/app/oracle/product/8.1.6 \ --with-apache=/usr/local/apache \ --enable-curl \ --enable-track-vars \ --disable-debug \ --without-gd \ --without-mysql \ --enable-sigchild And this is our Apache one: ./configure \ --prefix=/usr/local/apache \ --activate-module=src/modules/php4/libphp4.a \ --enable-module=rewrite \ --enable-rule=SHARED_CORE \ --enable-module=so -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] RE: Informix user wierdness
This is more an Informix question rather than a PHP question but I hope someone can help I've installed the Linux-SE version and CSDK of Informix from informix.com and installation has gone fine including createing the demo DB. I can also start 'dbaccess' and browse/query the tables so the envvars seem fine. However, when I endeavour to use the PHP functions, I get an error in ifx_connect() I constantly get the error: E [SQLSTATE=IX 000 SQLCODE=-952] User ()'s password is not correct for the database server. Note how the username field is empty. What's the procedure for 'logging in' to the DB? I created the demo DB as a normal user and I've read that the user auth stuff is done through the operating system. Using 'dbaccess' to try and connect to the DB as the same user rather then starting dbaccess in the DB dir causes the same error to occur so it's obviously something in the setup. My sqlhosts line is 'demo_se seipcpipdev sqlexec' and the ifx_connect line is 'ifx_connect("stores7@demo_se", "testuser", "mypasswd")' Answered my own question after taking some time out ;). Here's what I found for the sake of the archives. Turns out Informix has some sort of PAM/shadow password problem which means it won't talk nicely because it tries to auth the user, but because of the bug it can't get the user and therein lies the problem. Luckily I'm on a dev box so I was able to run 'pwunconv' to return my passwd file to a non shadow state which in a production system is 'not a good thing'(tm) A search in comp.databases.informix on google/deja on shadow and PAM etc will reveal the problem. Apparently there are workarounds for this but I haven't found the, yet. I suspect they will require surgery to something important :) Cheers, Graeme -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Informix user wierdness
This is more an Informix question rather than a PHP question but I hope someone can help I've installed the Linux-SE version and CSDK of Informix from informix.com and installation has gone fine including createing the demo DB. I can also start 'dbaccess' and browse/query the tables so the envvars seem fine. However, when I endeavour to use the PHP functions, I get an error in ifx_connect() I constantly get the error: E [SQLSTATE=IX 000 SQLCODE=-952] User ()'s password is not correct for the database server. Note how the username field is empty. What's the procedure for 'logging in' to the DB? I created the demo DB as a normal user and I've read that the user auth stuff is done through the operating system. Using 'dbaccess' to try and connect to the DB as the same user rather then starting dbaccess in the DB dir causes the same error to occur so it's obviously something in the setup. My sqlhosts line is 'demo_se seipcpipdev sqlexec' and the ifx_connect line is 'ifx_connect("stores7@demo_se", "testuser", "mypasswd")' Cheers, Graeme -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] pg_put_line and file()
Hi. I was tinkering around with pg_put_line and pg_end_copy and rather than inserting data from a variable as per the example, I was wondering if it was posible to insert the data from a delimited file via these two functions. I produced a dump from postgres and tried inserting the data raw $text = file("test.sql"); $db = pg_connect("host=localhost dbname=testing user=testing"); pg_exec($db, "COPY test FROM stdin"); foreach($text as $line) { echo $line, "BR"; pg_put_line($db,$line); flush(); } pg_end_copy($db); but this caused an error to occur. The example in the docs had the new lines and tabs escaped so I tried that as well with addslashes() $text = file("test.sql"); $db = pg_connect("host=localhost dbname=graeme user=graeme"); pg_exec($db, "COPY test FROM stdin"); foreach($text as $line) { $line = addslashes($line); $line = ereg_replace(9,"\\t",$line); $line = ereg_replace(10,"\\n",$line); echo $line, "BR"; pg_put_line($db,$line); flush(); } pg_end_copy($db); and while the data was exactly the same format as the example, I managed to get postgres stuck in COPY and had to manually kill the postgres COPY process to recover. Any one have any ideas? Cheers, Graeme -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]