Can I do a mysql_query in eval()?
The community builder I am using requires php blocks to be parsed through eval(). Can I use the my开发者_高级运维sql_query in eval? If not how can I call info from the database in this eval()?
Here's my code so far:
$iProId = $this->oProfileGen->_iProfileID;
$sCat = mysql_query("SELECT genres from Profiles WHERE ID = ". $iProId);
print_r($sCat);
This gives me:
Resource id #167If that code gave you that result when eval'd then yes, you can use mysql_query in eval and the rest of your question boils down to how you would have to use that result set.
In that case I would suggest something like:
$iProId = $this->oProfileGen->_iProfileID;
$sCat = mysql_query("SELECT genres from Profiles WHERE ID = ". $iProId);
while($row = mysql_fetch_assoc($sCat)) {
print_r($row);
}
To loop over all rows in the resultset. If you want to know more the PHP website has all the goods on how to use mysql_* functions.
Have a look at mysql_fetch_array
(and the other mysql_fetch_*
functions) for how to get your data from the resource.
Using a query in eval() sounds strange to me, but you code is working right. mysql_query
returns a mysql resource. Then you need to you mysql_fetch_array
, mysql_fetch_row
, or mysql_fetch_assoc
to read it like:
$iProId = $this->oProfileGen->_iProfileID;
$result = mysql_query("SELECT genres from Profiles WHERE ID = ". $iProId);
$sCat = mysql_fetch_assoc($result);
print_r($sCat);
精彩评论