PDA

View Full Version : Need Your help with query_read


madzat
01-02-2016, 10:49 PM
Hey there, plz i need your help with sql so here my problem i have field7 and i made page for Normal user and super user so all super user is group 13 to read the group im using
$db->query_read("SELECT username FROM ". TABLE_PREFIX ."user WHERE usergroupid = 13"); and is working well so my problem now i want to make page for super user using the field7 when i try read $db->query_read("SELECT username, field7 FROM ". TABLE_PREFIX ."user LEFT JOIN mo_userfield ON(mo_user.userid=mo_userfield.userid)"); i get all member list so i want just group 13 if add $db->query_read("SELECT username, field7 FROM ". TABLE_PREFIX ."user LEFT JOIN mo_userfield ON(mo_user.userid=mo_userfield.userid && usergroupid=13)"); is not working any help plz

Thx

Dave
01-02-2016, 11:24 PM
SELECT user.username, user.field7 FROM ". TABLE_PREFIX ."user LEFT JOIN mo_userfield ON(mo_user.userid=mo_userfield.userid) WHERE user.usergroupid = 13

madzat
01-03-2016, 01:18 AM
thx for your fast replay and is working and plz if any chance to add 2 group in the same time like that for exemple ??
in_array($bbuserinfo['usergroupid'], array(13, 12))


SELECT user.username, user.field7 FROM ". TABLE_PREFIX ."user LEFT JOIN mo_userfield ON(mo_user.userid=mo_userfield.userid) WHERE in_array($bbuserinfo['usergroupid'], array(13, 12))
:)
thx again

Dave
01-03-2016, 01:47 PM
You can't use PHP like that in SQL queries.

SELECT user.username, user.field7 FROM ". TABLE_PREFIX ."user LEFT JOIN mo_userfield ON(mo_user.userid=mo_userfield.userid) WHERE user.usergroupid IN(13,12)

madzat
01-03-2016, 02:42 PM
thx man for your help

--------------- Added 1451870478 at 1451870478 ---------------

Hi all i still have smal problem with sql is here i made new table spmembers and have spusername im using like that and is not working to add all list to sql
$spmember = $db->query_read("SELECT username, field7 FROM ". TABLE_PREFIX ."user LEFT JOIN mo_userfield ON(mo_user.userid=mo_userfield.userid) WHERE usergroupid IN(12,13)");

$i=0;
while ($array2 = $db->fetch_array($spmember))
{
// Do something with the current row here
if($i==0)
{
$res_html.= "<tr><td width='50%' style='color:#e37616;'>".$array2['field7']."</td></tr>";
$i++;
}
else
{

spmember = $db->query_write("INSERT INTO " . TABLE_PREFIX . "spmembers (spusername) VALUES field7");
$res_html.= "<tr><td width='50%' style='color:#e37616;'>".$array2['field7']."</td></tr>";

}

}
i want to add field7 to sql i tested with array not not working and i dont know haw to fix plz any help thx

spmember = $db->query_write("INSERT INTO " . TABLE_PREFIX . "spmembers (spusername) VALUES field7");

Elite_360_
01-04-2016, 02:03 AM
$db->query_write("INSERT INTO " . TABLE_PREFIX . "spmembers
(spusername)
VALUES
('" . $db->escape_string($array2['field7']) . "')
");