Reply to Re: [PHP] Problems with strings being handled like numbers

Your name:

Reply:


Posted by Chris on 09/14/05 03:26

Are you sure you're getting the number as you need it from the query?

PHP won't (though I guess there could be a bug) automatically convert a
numerical string into it's numerical equivalent.

If the code you posted produces this problem, then the only possiblities
I see are that the mssql module is returning a number, or the database
query is returning that particular string.

Chris

J B wrote:

> I suspect I'm far from the first person to have this problem, but I can't
>seem to find the right search terms to locate the solution. Basically, I'm
>doing a database query and dumping the results into an array. Then, later,
>when I try to display the contents of the array, I run into problems. One of
>the database fields is a very long number, basically an 18-or-so-digit
>serial number. When I tell PHP to print the array variable that corresponds
>to that field, I get what looks like a floating point number in exponent
>notation. I need to display the entire number as it appears in the database.
>Here's the code that does the db lookup and putting the info into the array:
>
>----- cut here
>$con = mssql_connect($hostname, $username, $password) or die("Database
>failed to respond.");
>mssql_select_db($dbName, $con) or die("Table unavailable.");
>
>$query = "SELECT * FROM Voucher WHERE (Number LIKE '%" .
>$_POST['vouchernum'] . "');";
>
>$result = mssql_query($query, $con);
>$result_numrows = mssql_num_rows($result);
>
>$tmpvar = 0;
>$vouchers[] = '';
>for ($i = 0; $i < $result_numrows; ++$i) {
>$line = mssql_fetch_row($result);
>$vouchers[$tmpvar][0] = $line[0];
>$vouchers[$tmpvar][1] = $line[4];
>$vouchers[$tmpvar][2] = $line[5];
>$vouchers[$tmpvar][3] = $line[6];
>$vouchers[$tmpvar][4] = $line[13];
>$vouchers[$tmpvar][5] = $line[14];
>$vouchers[$tmpvar][6] = $line[15];
>$vouchers[$tmpvar][7] = $line[16];
>$tmpvar++;
>}
>mssql_close($con);
>
>echo("<pre>");
>print_r($vouchers);
>echo("</pre>");
>
>----- cut here
>
>Basically, $line[0] aka $vouchers[$tmpvar][0] is a really big number and
>it's being treated like a number when I need it to be treated like a string
>and just printed. I tried playing around with typecasting, but I couldn't
>get it to do anything different.
>Thanks in advance for any help, and if I need to provide more info feel free
>to let me know.
>
>
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация