Re: problem with array
| From: | Minuk Choi | Date: | Tue, 19 Oct 2004 18:03:48 +0000 |
| Subject: | Re: problem with array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-199814@lists.php.net to get a copy of this message | ||
You say you have a database with many CHAR(60) fields?
Have you considered changing those to VARCHAR(60)?
This isn't PHP and is probably inappropriate solution(since it is not PHP related), but I believe a CHAR(60) defines the field as a fixed length character string, meaning no matter what you want to store, it is 60 lengths.
VARCHAR(60) is a variable length(still fixed, since you have a maximum) length field type.
My SQL datatypes may be rusty, but try converting a small portion of your db to VARCHAR(60) and try pulling data off those fields. Let me know how it turns out.
-Minuk
----- Original Message ----- From: "Dale Hersowitz" <dhersh@hershonline.com>
To: "'Minuk Choi'" <Choi.Minuk@verizon.net>
Sent: Tuesday, October 19, 2004 12:38 AM
Subject: RE: [PHP] problem with array
Minuk, After much searching and asking, I found the answer to my problem. It turns out that after re-attaching my db and re-formatting the server, the db has been slightly adjusted. Let me explain. Many of my fields are set to char with a width of 60. As a result, when I extract data from the db, it has extra chars or blank spaces attached to it. I am finding myself to have to use the trim function everywhere. If you have a fix to this problem it would be greatly appreciated. Thx. Dale Hersh Corporation 2250 E. Imperial Hwy., 2nd Fl. El Segundo, CA 90245 USA Phone: (310) 563-2155 Fax: (310) 563-2101 E-mail: dhersh@hershonline.com Web Site: www.hershonline.com E-Mail Disclaimer NOTE: This e-mail message and all attachments thereto ("this message") contain confidential information intended for a specific addressee and purpose. If you are not the addressee (a) you may not disclose, copy, distribute or take any action based on the contents hereof; (b) kindly inform the sender immediately and destroy all copies thereof. Any copying, publication or disclosure of this message, or part thereof, in any form whatsoever, without the sender's express written consent,is prohibited. No opinion expressed or implied by the sender necessarily constitutes the opinion of Hersh Corporation. This message does not constitute a guarantee or proof of the facts mentioned therein. Hersh Corporation accepts no responsibility or liability in respect of (a) any opinion or guarantee of fact, whether express or implied; or (b) any action or failure to act as a result of any information contained in this message, unless such information or opinion has been confirmed in writing by an authorized Hersh Corporation partner or employee. -----Original Message----- From: Minuk Choi [mailto:Choi.Minuk@verizon.net] Sent: Friday, October 15, 2004 5:16 PM To: Dale Hersowitz Subject: Re: [PHP] problem with array Hmm... okay, Now, is the output you gave me the last row? That is, that's the row you have errors? According to the output, it should work, since $row['selectedCol'] exists and $row['selectedCol'] = "col0" and $row['col0'] exists. How about this approach, tell me what it is you are trying to accomplish from the block of code. In particular, explain to me whatis supposed to prove. --your code--$selectedCol=$row["selectedCol"]; echo $selectedCol; $selectedColName=$row[$selectCol]; //<--- PLEASE NOTE THIS SPECIFIC----- Original Message ----- From: "Dale Hersowitz" <dhersh@hershonline.com> To: "'Minuk Choi'" <Choi.Minuk@verizon.net> Sent: Friday, October 15, 2004 1:29 PM Subject: RE: [PHP] problem with array$query="SELECT * FROM customizeViewClients WHERE employeeNum = $employeeNum"; $results=mssql_query($query, $connection) or die("Couldn't execute query"); $numRows=mssql_num_rows($results); if($numRows>0) {$row=mssql_fetch_array($results);}$selectedCol=$row["selectedCol"]; echo $selectedCol; $selectedColName=$row[$selectCol]; //<--- PLEASE NOTE THIS SPECIFICMinuk, I add that line of code and here is what came out:selectedCol : col0 Array( [0] => 1 [employeeNum] => 1 [1] => clientName [col0] => clientName [2] => city [col1] => city [3] => telephoneNum [col2] => telephoneNum [4] => telephoneNum2 [col3] => telephoneNum2 [5] => cp1FirstName [col4] => cp1FirstName [6] => 1 [col0Active] => 1 [7] => 1 [col1Active] => 1 [8] => 1 [col2Active] => 1 [9] => 1 [col3Active] => 1 [10] => 1 [col4Active] => 1 [11] => col0 [selectedCol] => col0 [12] => ASC [selectionType] => ASC ) Thx. Dale -----Original Message----- From: Minuk Choi [mailto:Choi.Minuk@verizon.net] Sent: Thursday, October 14, 2004 9:04 PM To: Dale Hersowitz Subject: Re: [PHP] problem with array $row['selectedCol'] returns 'clientName'??? let me guess, $row should have a column named 'clientName'? try this and tell me the output.print_r('<PRE>selectedCol : '.$selectedCol.'<BR>'); print_r($row); print_r('</PRE>'); and tell me what you get on the screen(it should be a dump of all the columns stored in $row array ----- Original Message ----- From: "Dale Hersowitz" <dhersh@hershonline.com> To: "'Minuk Choi'" <Choi.Minuk@verizon.net> Sent: Thursday, October 14, 2004 10:51 PM Subject: RE: [PHP] problem with array$query="SELECT * FROM customizeViewClients WHERE employeeNum = $employeeNum"; $results=mssql_query($query, $connection) or die("Couldn't execute query"); $numRows=mssql_num_rows($results); if($numRows>0) {$row=mssql_fetch_array($results);}$selectedCol=$row["selectedCol"];echo $selectedCol spits out 'clientName' thx. Dale -----Original Message----- From: Minuk Choi [mailto:Choi.Minuk@verizon.net] Sent: Thursday, October 14, 2004 7:28 PM To: Dale Hersowitz Cc: PHP Subject: Re: [PHP] problem with arrayPlease give me the output, what do you get from "echo $selectedCol;"? If I had to guess, it looks like you're confusing key and value of an associatative array. if $row["selectedCol"] = 12; $row["12"] does NOT equal "SelectedCol". In fact, even if you used mysql_fetch_array, you will not be able to do a reverse lookup like that. Suppose you have the following : $row['a'] = 1; $row['b'] = 2; $row['c'] = 1; You can see that your approach is incorrect because what would $row[1] return? If this is NOT your question, please post your output(errors and all). ----- Original Message ----- From: "Dale Hersowitz" <dale_news@hershonline.com> To: <php-general@lists.php.net> Sent: Thursday, October 14, 2004 9:58 PM Subject: [PHP] problem with array$selectedCol=$row["selectedCol"]; echo $selectedCol; $selectedColName=$row[$selectCol]; //<--- PLEASE NOTE THISSPECIFIC ROWHi guys, Recently, I had to reformat one of the web servers and now I have encountered an unusual problem. I am not sure whether this is an issue which can be fixed in the .ini file or whether its specific to the version of php I am using. Here is the problem: $query="SELECT * FROM customizeViewClients WHERE employeeNum = $employeeNum"; $results=mssql_query($query, $connection) or die("Couldn't execute query"); $numRows=mssql_num_rows($results); if($numRows>0) {$row=mssql_fetch_array($results);}$selectedCol=$row["selectedCol"]; echo $selectedCol; $selectedColName=$row[$selectCol]; //<--- PLEASE NOTE THISSPECIFIC ROW For some reason, on the last row, I am not unable to reference a particular index in the array using a php variable. This has been working for almost 12 months and now the coding is breaking all over the place. I don't have an answer. Any feedback would be greatly appreciated. Thx. Dale -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php