I have this line of code
$crop_id = $myValue; //myvalue is a value passed on by ajaxlink
echo $crop_id;
$crop = Crop::model()->find('crop_id = :keyword', array(
':keyword' => $crop_id
));
$crop_name = $crop->crop_name;
It would output an error trying to get non property.
But if i tried this, it would work
$crop_id = 30; //changed myvalue which was equated to 30
echo $crop_id;
$crop = Crop::model()->find('crop_id = :keyword', array(
':keyword' => $crop_id
));
$crop_name = $crop->crop_name;
What’s wrong with my passed value?
Where is the code where you populate $myValue?
If youre ajax is POST you have to use this:
if (isset($_POST["myValue"]))
$myValue=$_POST["myValue"];
Otherwise if youre ajax is GET use $_GET instead of $_POST.
if youre not sure try both
After these two lines:
$crop_id = $myValue; //myvalue is a value passed on by ajaxlink
echo 'Current crop: '.$crop_id;
die(); //add this line to stop script execution so you could see the printed out value
When you echo $crop_id the first time, what do you get? the correct id?
Casting to int may help
$myValue=(int)$_POST["myValue"];