I'm having a bit of a problem with exchanging a value from javascript to php.
For some reason if I compare the javascirpt value with one created in php it doesn't match i.e the javascripts returns 1 (string type) but if if run a strcmp() on it with a php string var that also returns 1 it doesn't give me a return value of 0. Does any one know why.
Here's the code I use
javascript
var myphotoid = parseInt(getPhotoID_fromURL());
function getPhotoID_fromURL()
{
var url = document.location.href;
if (url.match('#') && url.split('#')[1].match('photoid='))
{
url = url.split('#')[1];
if (url.match('&'))
{
url = url.split('&')[0];
}
return url.split('=')[1];
}
}
php
$myphotoid = "<script language='javascript'>document.write(myphotoid);</script>";
$arrayphotos = (array) $photos;
foreach( $arrayphotos as $fieldName => $fieldValue )
{
$id = $fieldValue->id;
print strcmp($id, $myphotoid);
print "<br />";
if($id == $myphotoid)
print "going to add img tag here";
else
print $id . " not = to " . $myphotoid . "<br />";
}
Please help have lost almost a whole day of work because of this
P.S
The getPhotoID_fromURL() javascript function gets a #value from a query string eg. index.php?albumid=4#photoid=3
$photos is a std object class and I don't know how else to access the different value other than to cast it to an array

New Topic/Question
Reply




MultiQuote




|