Quote from: Everett at May 05, 2010, 04:05 PM
I think you should simplify your code a bit... I’m not exactly sure what I’m looking at here. Can you isolate your queries at least and tell us what values you’re getting?
Hi Everett,
Thanks for your reply. I will try to explain my code :
Line 1-4:
It get the _POST value for submit, and if it’s for edit, it will get the value of ’shop’ from table ’result’ where id is the _POST value for editing the specific row of result table ($id):
In normal PHP, I made it like this :
if(isset($_REQUEST['submit']) && $_POST['edit'] > 0) {
$id = (int)($_POST['edit']);
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$current_shop = mysql_query("SELECT shop from 'result' WHERE id=$id");
$samegrp = '0'; // init
I tried in Modx :
if(isset($_REQUEST['submit']) && $_POST['edit'] > 0) {
$id = intval($_POST['edit']);
$current_shop = $modx->db->getValue($modx->db->select('shop', $modx->getFullTableName('result'), "id=$id"));
$samegrp = '0'; // init
Line 5 :
I don’t know to make it in Modx, but in normal PHP , it’s something like this :
$theid = $_SESSION['mgrInternalKey'];
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$result = mysql_query("SELECT mgn.* from 'modx_membergroup_names' mgn, 'modx_member_groups' mg WHERE mg.user_group = mgn.id AND mg.member = $theid");
I tried to do like this in Modx (is this right ?):
$sumshop = $modx->db->select("mgn.*" , "{$modx->getFullTableName('membergroup_names')} mgn, {$modx->getFullTableName('member_groups')} mg", "mg.user_group = mgn.id AND mg.member='" . $_SESSION['mgrInternalKey'] . "'");
Line 6 -15:
In normal PHP :
if (mysql_num_rows($result) > 1) {
while($row = mysql_fetch_array( $result )) {
if ($row['name'] == $current_shop) {
$samegrp = '1';
}
}
} // end if
else {
$samegrp = '1';
}
I tried in Modx :
if ($modx->db->getRecordCount($sumshop) > 1) {
// belongs to some shop
while ($myshp = $modx->db->getRow($sumshop)) {
if ($myshp['name'] == $current_shop) {
$samegrp = '1';
}
}
}
else { // just belongs to 1 shop
$samegrp = '1';
}
Then, in PHP :
if ($samegrp !== '1') {
die('You have no permission to edit this shop');
}
$insert['shop'] = $current_shop;
etc ... etc ....
I tried in Modx :
if ($samegrp !== '1') {
die('{"success":"0", "message":"You have no permission to edit this shop..."}');
}
$insert['shop'] = $current_shop;
etc ... etc ...
The result : $samegrp is ALWAYS ’0’ , and I always got the error message ’You have no permission to edit this shop ....’ , I check in Mysql database, this user is belongs to some groups, included the current group, so $samegrp must be ’1’.
What is wrong with my modx code ? Can we use more then 1 modx query in the same line, like :
$modx->db->select( ... {$modx->getFullTableName(’membergroup_names’)} .... {$modx->getFullTableName(’member_groups’)} ..... ?? => here I use
{} , not
() for the
{$modx->getFullTableName ...
} inside the main $modx->db->select query.
Can we use
$modx->db->getRecordCount($sumshop) in modx instead of
’mysql_num_rows’
And
$modx->db->getRow($sumshop) instead of
’mysql_fetch_array’ ?
Thanks
- jack -