Sign in to follow this  
ManaStone

[web] Is there something special about the character E in php ?

Recommended Posts

ManaStone    148
I am having a really weird problem with php. Right now I have a form where I can enter in records to my table where the primary key is a string of characters. I have a sortID variable which is an integer set equal to the converted string of the primary key. Whenever I use the ‘E’ in the key where it is something like 4E-4F or 5E-6J, the sortID will become 0 and when I try to echo the value of that key on page, it doesn’t display anything. Once the key value is entered into the table though, I can see it, but the sort ID is still 0 and the ordering is messed up. When I display the table, the query is sorted first by SortID and then by the primary key. Here is an example of what I get: SortID | Key 0 | 4E-4F 0 | 8E-8J 1 | 1A-1B 2 | 2 5 | 5D 7 | 7E – for some reason this works Here is part of my code for insertion.
//First get a query from a temp table in which I inserted the new records
$query="SELECT *
FROM $table_temp
ORDER BY LeadNum";

$result = @mysql_query($query,$connection)
or die("Couldn't execute query.");
	
while($row=mysql_fetch_array($result))
{
		$num=$row['LeadNum'];
		$key=FormatLeadNum($num);
		$sortID=$key+0;
		$date=$row['Date'];
		$agent=$row['Agent'];
		$witness=$row['Witness'];
		$summary=$row['Summary'];
		
	if($sortID==0)
	{
		echo "Key: $sordID , $key , $num <br>";
	}
	$query = "INSERT INTO $table_name 
	(SortID,LeadNum,Date,Agent,Witness,Summary)
	VALUES 
	(\"$sortID\",\"$key\",\"$date\",\"$agent\",\"$witness\",\"$summary\")
	";
	
	$result2 = @mysql_query($query,$connection);
	if($result2==false)
	{
		echo "Couldn't insert lead #$num<br>";
	}
}


Share this post


Link to post
Share on other sites
Frequency    442
if($sortID==0)
{
echo "Key: $sordID , $key , $num
";
^
}


I'm not sure if it's relevant to the problem but if that's the code I'd guess it would produce something unexpected.

Share this post


Link to post
Share on other sites
Sneftel    1788
"E" is used to indicate exponential notation, such as 1.3E-2 being used instead of 0.013. It looks like PHP is getting confused by the malformed exponential numbers. What do you mean by "an integer set equal to the converted string of the primary key"? Converted how?

Share this post


Link to post
Share on other sites
ManaStone    148
Quote:
Original post by Sneftel
"E" is used to indicate exponential notation, such as 1.3E-2 being used instead of 0.013. It looks like PHP is getting confused by the malformed exponential numbers. What do you mean by "an integer set equal to the converted string of the primary key"? Converted how?


Thanks. Basically, I'm referring to the line where I did this: $sortID=$key+0;

Share this post


Link to post
Share on other sites
Sneftel    1788
Yeah. What are you trying to do with that? If $sortID doesn't refer to a string representation of a number, you're going to get bad results. "34A"+0 should not be counted upon to evaluate to 34.

Share this post


Link to post
Share on other sites
ManaStone    148
What should I do to convert it to an integer properly? It appeared to work for them with the exception of the E-# ones. I basically want to cut off the parts after it gets to a character and then put it into an integer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this