0

I would love to know, if it's possible to get a specific data from a specific mysql table..

Let say on the table itself has a Varchar ... mixed of words and floats..

and then ... I want to pull only the float from the table using php...

can it be done ??

4
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by trektrak
0

Can you give an example of your table and the data that is in it, and an example of the output you require ?

0

if you are looking to pull a float out of a var char field that has for example text wrapped around it (i.e. "Temp: 26.2 Degrees") then I would suggest using preg_match or something alike to do a regular expression to extract it. I'm sure there is other ways too.

0

yeah ... something like that ... it's a long var char...

something like... "hello, my name is jack.. my height is 5.5 feet"

let say .. I just want to pull only "5.5"

0
$fullstring = "hello, my name is jack.. my height is 5.5 feet";
preg_match_all('/[0-9].[0-9]/', $fullstring, $matches);
$count = count($matches[0]);
# this will tell you how many times "x.x" was found in string
echo $count; 

# this will print out each "x.x" it found
for ($i = 0 ; $i < $count ; $i++ ) 
{
echo $matches[0][$i];
echo '<br/>';
}
0

Use pattern matching for it....Use can see how to do this from the examples in this link

<?php
preg_match('/^\d+$/', $price[1]);
?>

Edited by IIM: n/a

0

You can also try

$var = '122.34343The';
$float_value_of_var = floatval($var);
echo $float_value_of_var; // 122.34343
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.