473,322 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Mysql Retrieve data as numeric not string

PHP code
How can I retrieve elements of an array in numeric format?
Look at this code:
Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT price FROM $tbl_name"; 
  2. $result = mysql_query($query) 
  3. or die(mysql_error()); 
  4.  
  5.  
  6.  
  7. while($row = mysql_fetch_row($result)) {
  8.   //$rowNum++;
  9. $test[]=$row;
  10. }
Let's say the column price has three elements: 33, 47 and 65.
Please pay attention since the elements of column price are numbers I have to retrieve them as numbers.
Outside the while loop I need to to have the elements of $test array as:
Expand|Select|Wrap|Line Numbers
  1. $element1= 33;
  2. $element2= 47;
  3. $element3=65;
if I use gettype like;
echo gettype($element1);
it should NOT SAY "string" that's a NO NO
They should be numbers.
Can anyone help me with this? Please read the question and the code carefully before you answer.
Thanks
Sep 11 '07 #1
2 1431
pbmods
5,821 Expert 4TB
Heya, Zion.

MySQL fetches string values from the database. Nothing you can do about it.

But PHP is very good about being able to cast types on the fly, so even though these values are 'strings', you can still perform arithmetical operations on them.
Sep 11 '07 #2
debasisdas
8,127 Expert 4TB
Try use the available casting / convertion function.
Sep 11 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Agathe | last post by:
Bonjour, Je souhaite insérer dans une table MySQL des données provenant d'un fichier texte grâce à un script PHP. Mon fichier porte l'extension "txt" et les données sont séparées par des ";'. ...
1
by: Dave Posh | last post by:
I seem to be having a problem displaying time stored in mysql. The format stored in the database is 13:15:05. The database data type is time. I'm using asp vbscript and sql to retrieve the time...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
0
by: Gert | last post by:
Hi, I need to store a array() of byte to a mysql field. I created a field in mysql of type varbinary. But storing and retrieving gives problems. Please help. The strTemp = EnDeCrypt(txt,...
2
by: Frank | last post by:
Hello, I am attempting to retrieve a numeric type froma a table. I get an invalid cast exception when I use the following code in my data layer: //The problem definitley occurs in the...
1
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode I was...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
3
by: ist | last post by:
Hi, I am trying to get (and transfer over ASP.NET) some encrypted data from some MySQL fields. Since the data contains many unicode characters, I tried to get the data as a series of ASCII...
0
by: HSXWillH | last post by:
Someone here helped me in the past when I was trying to do this in Access, but now that I'm trying to learn MySQL, I have no idea how to do this. I have bulk table imports; one field (LongClass)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.