954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

get specific data from the specific table

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 ??

trektrak
Junior Poster in Training
52 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

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.

kevindougans
Junior Poster
129 posts since Oct 2007
Reputation Points: 13
Solved Threads: 7
 

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"

trektrak
Junior Poster in Training
52 posts since Oct 2011
Reputation Points: 10
Solved Threads: 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/>';
}
kevindougans
Junior Poster
129 posts since Oct 2007
Reputation Points: 13
Solved Threads: 7
 

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

<?php
preg_match('/^\d+$/', $price[1]);
?>
IIM
Junior Poster
165 posts since Jun 2011
Reputation Points: 46
Solved Threads: 37
 

You can also try

$var = '122.34343The';
$float_value_of_var = floatval($var);
echo $float_value_of_var; // 122.34343
kevindougans
Junior Poster
129 posts since Oct 2007
Reputation Points: 13
Solved Threads: 7
 

The following regex would also match 45.67 and -45

/-?[0-9]+(\.[0-9]+)?/
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

tq guys... I'll give a try later..

trektrak
Junior Poster in Training
52 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: