Reputation: 301
I have code like this
<?php
global $DB;
$useridQry='';
$login_id = $_SESSION['USER']->id;
if( $_SESSION['idnumber'] == 3 )
{
}
elseif( $_SESSION['idnumber'] == 2 )
{
$records=$DB->get_records_sql("select * from {user} where
maildigest=$login_id");
print_r($records);
if(empty($records) && count($records){
{
$userIds='';
foreach($records as $row)
{
$userIds="'".$row->id."'";
}
//$useridQry = " and st.userid IN ($userIds)";
}
}
else
{
$useridQry = " and st.userid = $login_id";
}
so what happened is if is there any records it will show in table
print_r($records);
when I use print,
But if is there no data it showing empty array like this Array ( )
so when it showing empty array also it showing data in my tables..i don't want to show data if it is empty array..
can anyone help me how to do that,
thanks in advance..
Upvotes: 1
Views: 315
Reputation: 12375
Look at this snippet: https://3v4l.org/CjTuv
$x = [];
print_r($x);
if (count($x)) {
echo 'yes';
}
print_r()
will always display output. It's usually just for debugging. If you don't want Array( ) displaying, either remove the print_r
or move it inside your if statement.
Upvotes: 3
Reputation: 158
Try this:
if(!empty($records) && count($records) > 0){ ...
instead of:
if(count($records)){
Upvotes: -1
Reputation: 1
How about checking, if the array is empty?
if (empty($playerlist)) {
// list is empty.
}
Upvotes: -1