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

Started by
8 comments, last by konForce 18 years, 1 month ago
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>";
	}
}


-----------------------------Download my real time 3D RPG.
Advertisement
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.
It only takes one mistake to wake up dead the next morning.
Well, that helped the error code display print out the sort, but it is still messed up.
-----------------------------Download my real time 3D RPG.
"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?
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;
-----------------------------Download my real time 3D RPG.
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.
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.
-----------------------------Download my real time 3D RPG.
To get only the initial integer portion, I would probably use preg_grep, for instance with the /^\d+/ regexp.
Thx, I'll take a look at that method later tonight.
-----------------------------Download my real time 3D RPG.
$i = intval($string);

This topic is closed to new replies.

Advertisement