Why is id={$myrowid} not working?

Status
Not open for further replies.

jmdc

Member
Hello,

I am doing a php validation in a radio button, with this code:

$db = JFactory::getDbo();

$myrowid = '{rowid}';

$myQuery = 'SELECT id2 FROM devedorestotais4 WHERE id={$myrowid}';
$db->setQuery($myQuery);
$dt = $db->loadResult();

if($dt == '20' ){
return true;
}
else{
return false;
}

and i have this table "devedorestotais4":
id id2
1 21
2 20
3 00
4 00
5 00
6 21

When I try to edit the id=2, the php validation above doesn?t work (it always shows me this message: "1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '}' at line 1 SQL=SELECT id2 FROM devedorestotais4 WHERE id={$myrowid}"), but if I change WHERE id={$myrowid} by WHERE id=2, it works.

Could give some idea for this php validation?

Thank you.
 
I would say try:

$myQuery = 'SELECT id2 FROM devedorestotais4 WHERE id=$myrowid';
or
$myQuery = 'SELECT id2 FROM devedorestotais4 WHERE id='.$myrowid;

The "{}" is the markup only for Fabrik-Placeholder....


Regards
 
Last edited:
Hi,

With your first query, i have this message:
1054 Unknown column '$myrowid' in 'where clause' SQL=SELECT id2 FROM devedorestotais4 WHERE id=$myrowid

And the 2nd query is OKKKKKKKKKKKKKKKK....;)

Thank you!!!
 
Glad I could help :). The "." in the query simply is php concatenation operator:

http://php.net/manual/en/language.operators.string.php

Somtimes it's a bit tricky to concatenate vars in the query-String depending on if the var is at the end of the string (like in your case) or rigth in the middle and also if you need some quotes in the string itself.

Always do debug with:

echo "<pre>";print_r($MyVar);exit;

To have an idea what is happening and why...

Regards
 
Status
Not open for further replies.
Back
Top