show more option is not working with php and mysql - php

i am trying to add limit each time when button is clicked but is not working
my html code is
<div class="media stream load-more">
<a href="<?php echo $_SERVER['PHP_SELF']; ?>" method ='post' name = 'showmore'>
<i class="icon-refresh shaded"></i>
show more...
</a>
</div>
php code is
$showvalue = 2;
if(isset($_POST['showmore'])) {
$showvalue += 1;
}
$feeds = $db->getfeeds($showvalue);
mysql function
public function getfeeds($showvalue){
$stmt = $this->con->prepare("SELECT id,image,title,status,profilepic,created_at,url FROM news ORDER BY id DESC LIMIT $showvalue");
$stmt->bind_param("s",$showvalue);
$stmt->execute();
$result = $stmt->get_result();
$nrow = array();
while ($r = $result->fetch_assoc()) {
$nrow[] = $r;
}
$frow['news'] = $nrow;
$json = str_replace("\\/", "/",json_encode($frow));
return $json;
}

Related

Trying to implement telegram api into this script New messages

how to implement this api telegram line into New messages? so it check and see if new messages, and then make the api call so i get a new message notification on my telegram bot
hope there is someone that know how to put this in : would be very usefull. i have tried but failed many attemps
this line:
$url = "https://api.telegram.org/bot6547564:AAGP6DH754460526544HCsvwTlfoGNJPaQ/sendMessage?chat_id=#841rhe67&text=Ny Besked på - Svar: https://fake.com/index.php?page=admin&p=sdeg";
file_get_contents($url);
into this
<?php
header('Content-Type: application/json');
require_once('../assets/includes/core.php');
function getFakeUsersChat($tab) {
global $mysqli,$sm;
$return = array();
$time_now = time()-300;
$timestamp = time();
$dw = date( "w", $timestamp);
if($tab == 'New'){
$query = $mysqli->query("SELECT DISTINCT s_id,r_id FROM chat where fake = 1 and online_day = '".$dw."' and seen = 0 order by id DESC");
} else {
$query = $mysqli->query("SELECT DISTINCT s_id,r_id FROM chat where fake = 1 and online_day = '".$dw."' order by id DESC");
}
$return['empty'] = false;
if ($query->num_rows > 0) {
while($value = $query->fetch_object()){
$senderName = getData('users','name','WHERE id ='.$value->s_id);
$fakeName = getData('users','name','WHERE id ='.$value->r_id);
$fakeId = $value->r_id;
$senderId = $value->s_id;
$fakePhoto = profilePhoto($value->r_id);
$senderStatus = userStatus($senderId);
$senderStatusIcon = 'avatar-online';
if($senderStatus == 'n'){
$senderStatusIcon = 'avatar-offline';
}
$chatId = getData('chat','id','WHERE s_id = '.$value->s_id.' AND r_id = '.$value->r_id.' ORDER BY id DESC LIMIT 1');
$searchName = strtolower($senderName);
$conv = $senderId.$fakeId;
$newMessagesFilter = 'WHERE r_id = '.$fakeId.' AND s_id = '.$senderId.' AND seen = 0';
$newMessagesCount = selectC('chat',$newMessagesFilter);
$return['conv'][] = $conv;
$return[$conv]['chatId'] = $chatId;
$newMessageLabel = '<span class="badge badge-pill badge-success" data-new-message="'.$chatId.'" style="margin-right:10px;font-size: 10px">NEW</span>';
if($tab == 'All'){
if($newMessagesCount == 0){
$newMessageLabel = '';
}
}
$return[$conv]['data'] = '<div class="list-group-item d-flex align-items-start border-right-3 border-right-primary bg-light rightSectionChatUser" data-conv="'.$conv.'" data-chatid="'.$chatId.'"
data-uid="'.$fakeId.'" data-search-bind="'.$searchName.'"
data-cid="'.$senderId.'" data-name="'.$fakeName.'" data-id="'.$fakeId.'" onclick="viewChat(this)" data-photo="'.profilePhoto($fakeId).'"
onmouseover="hoverFriendList(this,1)" onmouseout="hoverFriendList(this,2)" style="cursor: pointer;">
<div class="mr-3 d-flex flex-column align-items-center">
<div class="avatar avatar-md '.$senderStatusIcon.'" style="margin-bottom:5px" data-toggle="tooltip" data-placement="top" title="" data-original-title="'.$fakeName.'">
<img src="'.profilePhoto($senderId).'" alt="Avatar" class="avatar-img rounded-circle">
</div>
<div class="avatar avatar-md avatar-online" data-toggle="tooltip" data-placement="top" title="" data-original-title="'.$senderName.'">
<img src="'.profilePhoto($fakeId).'" alt="Avatar" class="avatar-img rounded-circle">
</div>
</div>
<div class="flex">
<p class="m-0">
<span class="d-flex align-items-center mb-1">
From: '.$senderName.'
<small class="ml-auto text-muted" style="font-size: 10px">
'.$newMessageLabel.'
'.getLastMessageMobileTime($fakeId,$senderId).'</small>
</span>
<span class="d-flex align-items-end">
<span class="flex mr-3">
<strong class="text-body mb-1">To: '.$fakeName.'</strong><br>
<small class="text-muted" style="margin-top:15px;max-height: 3rem; overflow: hidden; position: relative; display: inline-block;background: #fff;border-radius: 5px;padding: 5px 10px 5px 10px">
'.getLastMessageMobile($fakeId,$senderId).'
</small>
</span>
<a href="javascript:;" class="d-flex align-items-center mb-1">
<small class="text-muted mr-1">'.$newMessagesCount.'</small>
<i class="material-icons icon-16pt text-muted">chat</i>
</a>
</span>
</p>
</div>
</div>';
}
} else {
$return['empty'] = true;
}
return json_encode($return);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
switch ($_POST['action']) {
case 'load':
$uid = secureEncode($_POST['user']);
getUserInfo($uid,3);
$mysqli->query("UPDATE chat set seen = 1 where s_id = '".$sm['chat']['id']."' and r_id = '".$sm['user']['id']."'");
$arr =array();
$arr['id']=$sm['chat']['id'];
$arr['name']=$sm['chat']['name'];
$arr['chat'] = getChat($sm['user']['id'],$sm['chat']['id']);
echo json_encode($arr);
break;
case 'send':
global $mysqli;
if (strpos($_POST['message'], '<img') !== false) {
$message = mysqli_real_escape_string($mysqli, $_POST['message']);
} else {
$message = secureEncode($_POST['message']);
}
$r_id = secureEncode($_POST['r_id']);
$mobile = secureEncode($_POST['mobile']);
$time = time();
if(isset($_POST['fast'])){
$fast = secureEncode($_POST['fast']);
if($fast){
$date = date('m/d/Y', time());
$mysqli->query("INSERT INTO users_chat (uid,date,count,last_chat) VALUES ('".$sm['user']['id']."','".$date."',1,'".$time."') ON DUPLICATE KEY UPDATE count=count+1");
}
}
getUserInfo($r_id,1);
$fake = $sm['profile']['fake'];
$online_day = $sm['profile']['online_day'];
$data['message'] = $sm['lang'][658]['text'];
$data['chatHeaderRight']='<div class="js-message-block" id="you">
<div class="message">
<div class="brick brick--xsm brick--hover">
<div class="brick-img profile-photo" data-src="'.$sm['user']['profile_photo'].'"></div>
</div>
<div class="message__txt">
<span class="lgrey message__time" style="margin-right: 15px;">'.date("H:i", time()).'</span>
<div class="message__name lgrey">'.$sm['user']['first_name'].'</div>
<p class="montserrat chat-text">'.$message.'</p>
</div>
</div>
</div>
';
$data['time'] = date("H:i", time());
$event = 'chat'.$r_id.$sm['user']['id'];
$noti= 'notification'.$r_id;
$data['id'] = $sm['user']['id'];
$data['type'] = 1;
$data['icon'] = $sm['user']['profile_photo'];
$data['name'] = $sm['user']['first_name'];
$data['photo'] = 0;
$data['action'] = 'message';
$sm['push']->trigger($sm['plugins']['pusher']['key'], $event, $data);
$mysqli->query("INSERT INTO chat (s_id,r_id,time,message,fake,online_day) VALUES ('".$sm['user']['id']."','".$r_id."','".$time."','".$message."','".$fake."','".$online_day."')");
$arr = array();
$data['notification_chat'] = false;
$results = $mysqli->query("SELECT DISTINCT s_id FROM chat WHERE r_id = '".$r_id."' AND seen = 0 AND notification = 0 order by id desc");
if($results->num_rows > 0){
$data['notification_chat'] = getUserFriends($r_id);
$data['unread'] = checkUnreadMessages($r_id);
}
$sm['push']->trigger($sm['plugins']['pusher']['key'], $noti, $data);
if($fake == 0){
$sm['profile_notifications'] = userNotifications($sm['profile']['id']);
if($sm['profile']['last_access']+300 <= time() && $sm['profile_notifications']['message'] == 1){
chatMailNotification($r_id,$message);
}
}
$arr['message'] = cleanMessage($message);
if($mobile == 1){
$arr['chat'] = getLastChatMobile($sm['user']['id'],$r_id);
} else {
$arr['chat'] = getLastChat($sm['user']['id'],$r_id);
}
//activity content
if($sm['plugins']['logActivity']['enabled'] == 'Yes'){
$ac = array();
$ac['u1']['id'] = $sm['user']['id'];
$ac['u2']['id'] = $sm['profile']['id'];
$ac['u1']['name'] = $sm['user']['first_name'];
$ac['u2']['name'] = $sm['profile']['first_name'];
$ac['u1']['photo'] = $sm['user']['profile_photo'];
$ac['u2']['photo'] = $sm['profile']['profile_photo'];
$ac['message'] = $arr['message'];
$adminPush= 'adminActivity';
$pushData['message'] = $ac;
$ac = json_encode($ac);
$title = $sm['user']['first_name'].' sent a message to '.$sm['profile']['first_name'];
activity('message',$ac,$title);
$sm['push']->trigger($sm['plugins']['pusher']['key'], $adminPush, $pushData);
}
break;
case 'send_fake':
$message = secureEncode($_POST['mensaje']);
$r_id = secureEncode($_POST['uid2']);
$s_id = secureEncode($_POST['uid1']);
$mobile = secureEncode($_POST['mobile']);
$time = time();
getUserInfo($r_id,1);
$fake = $sm['profile']['fake'];
getUserInfo($s_id,6);
$data['message'] = cleanMessage($message);
if($mobile == 1){
$data['chat'] = getLastChatMobile($sm['search']['id'],$r_id);
} else {
$data['chatHeaderRight']='<div class="js-message-block" id="you">
<div class="message">
<div class="brick brick--xsm brick--hover">
<div class="brick-img profile-photo" data-src="'.$sm['search']['profile_photo'].'"></div>
</div>
<div class="message__txt">
<span class="lgrey message__time" style="margin-right: 15px;">'.date("H:i", $spotl->time).'</span>
<div class="message__name lgrey">'.$sm['search']['first_name'].'</div>
<p class="montserrat chat-text">'.cleanMessage($message).'</p>
</div>
</div>
</div>
';
}
$data['time'] = date("H:i", time());
$event = 'chat'.$r_id.$sm['search']['id'];
$noti= 'notification'.$r_id;
$data['id'] = $sm['search']['id'];
$data['type'] = 1;
$data['icon'] = $sm['search']['profile_photo'];
$data['name'] = $sm['search']['first_name'];
$data['photo'] = 0;
$mysqli->query("INSERT INTO chat (s_id,r_id,time,message,fake) VALUES ('".$s_id."','".$r_id."','".$time."','".$message."','".$fake."')");
$arr = array();
$data['notification_chat'] = false;
$results = $mysqli->query("SELECT DISTINCT s_id FROM chat WHERE r_id = '".$r_id."' AND seen = 0 AND notification = 0 order by id desc");
if($results->num_rows > 0){
$data['notification_chat'] = getUserFriends($r_id);
$data['unread'] = checkUnreadMessages($r_id);
}
$sm['push']->trigger(siteConfig('pusher_key'), $event, $data);
$sm['push']->trigger(siteConfig('pusher_key'), $noti, $data);
if($fake == 0){
$sm['profile_notifications'] = userNotifications($sm['profile']['id']);
if($sm['profile']['last_access']+300 >= time() && $sm['profile_notifications']['message'] == 1){
chatMailNotification($r_id,$message);
}
}
$arr['message'] = cleanMessage($message);
if($mobile == 1){
$arr['chat'] = getLastChatMobile($s_id,$r_id);
} else {
$arr['chat'] = getLastChat($s_id,$r_id);
}
echo json_encode($arr);
break;
case 'fake_list':
$tab = secureEncode($_POST['tab']);
echo getFakeUsersChat($tab);
break;
case 'load_fake':
$u1 = secureEncode($_POST['u1']);
$u2 = secureEncode($_POST['u2']);
//Secure info
$u1 = secureEncode($u1);
$u2 = secureEncode($u2);
//Get all chats
$chatt = $mysqli->query("SELECT * FROM chat where s_id = '".$u1."' and r_id = '".$u2."' OR r_id = '".$u1."' and s_id = '".$u2."' order by id asc");
//Update chat to seen
$mysqli->query("UPDATE chat set seen = 1 where s_id = '".$u2."' and r_id = '".$u1."'");
if ($chatt->num_rows > 0) {
while($chat= $chatt->fetch_object()){
//Get profile photo
$mensaje = $chat->message;
//Check if current user is the sender
if($chat->s_id == $u1){
if($chat->seen == 1){
echo'
<li class="me">
<div class="image">
<img src="'.profilePhoto($chat->s_id).'"/>
</div>
<p> '.$mensaje.' </p>
</li>
';
} else {
echo'
<li class="me">
<div class="image">
<img src="'.profilePhoto($chat->s_id).'"/>
</div>
<p> '.$mensaje.' </p>
</li>
';
}
} else {
echo'
<li class="you">
<div class="image">
<img src="'.profilePhoto($chat->s_id).'"/>
</div>
<p> '.$mensaje.' </p>
</li>
';
}
}
}
break;
case 'current_fake':
//GET POST INFO
$u1 = secureEncode($_POST['u1']);
$u2 = secureEncode($_POST['u2']);
//GET NEW MESSAGES
$results = $mysqli->query("SELECT * FROM chat WHERE r_id = '".$u1."' AND s_id = '".$u2."' AND seen = 0 order by id asc");
//CHECK IF CURRENT USER HAS NEW MESSAGE
if($results->num_rows > 0){
while ($obj = $results->fetch_object()){
//UPDATE MESSAGE AS SEEN
$mysqli->query("UPDATE chat SET seen = 1 where r_id = '".$u1."' and s_id = '".$u2."'");
//SHOW NEW MESSAGES
echo'
<li class="you">
<div class="image">
<img src="'.profilePhoto($obj->s_id).'"/>
</div>
<p> '.$obj->message.' </p>
</li>
';
}
}
break;
case 'access':
$time = time();
$access = secureEncode($_POST['access']);
$r_id = secureEncode($_POST['r_id']);
if($access == 1) {
$mysqli->query("INSERT INTO chat (s_id,r_id,time,message) VALUES
('".$sm['user']['id']."','".$r_id."','".$time."','".$sm['lang'][189]['text']."')");
$mysqli->query("UPDATE chat SET access = 2 WHERE s_id = '".$r_id."' AND r_id = '".$sm['user']['id']."' AND access = 1");
$mysqli->query("INSERT INTO blocked_photos (u1,u2) VALUES ('".$r_id."','".$sm['user']['id']."')");
} else {
$mysqli->query("INSERT INTO chat (s_id,r_id,time,message) VALUES
('".$sm['user']['id']."','".$r_id."','".$time."','".$sm['lang'][190]['text']."')");
$mysqli->query("UPDATE chat SET access = 2 WHERE s_id = '".$r_id."' AND r_id = '".$sm['user']['id']."' AND access = 1");
}
break;
case 'current':
$uid = secureEncode($_POST['uid']);
$mob = secureEncode($_POST['mobile']);
getUserInfo($uid,3);
$arr = array();
$arr['result'] = 0;
$results = $mysqli->query("SELECT s_id,id,photo FROM chat WHERE r_id = '".$sm['user']['id']."' AND s_id = '".$uid."' AND seen = 0 order by id asc");
if($results->num_rows > 0){
$re = $results->fetch_object();
$arr['result'] = 1;
$arr['photo'] = $re->photo;
if($mob == 1){
$arr['chat'] = getLastChatMobile2($sm['user']['id'],$uid);
} else {
$arr['chat'] = getLastMessage($sm['user']['id'],$uid);
}
$arr['message'] = cleanMessageById($re->id);
$mysqli->query("UPDATE chat set seen = 1 where r_id = '".$sm['user']['id']."' and s_id = '".$uid."'");
}
echo json_encode($arr);
break;
case 'read':
$id = secureEncode($_POST['id']);
$mysqli->query("UPDATE chat set seen = 1, notification = 1 where r_id = '".$sm['user']['id']."' and s_id = '".$id."'");
break;
case 'notification':
$user = secureEncode($_POST['user']);
$time = time();
$arr = array();
if($user == 0){
$results = $mysqli->query("SELECT DISTINCT s_id FROM chat WHERE r_id = '".$sm['user']['id']."' AND seen = 0 AND notification = 0 order by id desc");
} else {
$results = $mysqli->query("SELECT DISTINCT s_id FROM chat WHERE r_id = '".$sm['user']['id']."' AND s_id <> '".$user."' AND seen = 0 AND notification = 0 order by id desc");
}
if($results->num_rows > 0){
while($use = $results->fetch_object()){
$arr[] = $use->s_id;
}
$mysqli->query("UPDATE chat set notification = 1 where r_id = '".$sm['user']['id']."'");
}
echo json_encode($arr);
break;
case 'new':
echo getUserFriends($sm['user']['id']);
break;
case 'today':
$uid = secureEncode($sm['user']['id']);
$time = time();
$date = date('m/d/Y', time());
$mysqli->query("INSERT INTO users_chat (uid,date,count,last_chat) VALUES ('".$uid."','".$date."',1,'".$time."') ON DUPLICATE KEY UPDATE count=count+1");
break;
case 'chat_limit':
$uid = secureEncode($sm['user']['id']);
$date = date('m/d/Y', time());
$mysqli->query("DELETE FROM users_chat WHERE uid = '".$uid."' AND date = '".$date."'");
break;
}
}
//CLOSE DB CONNECTION
$mysqli->close();

Php view photo by id

Hi i have an address book I added the possibility of add a photo.
This is the function for view Name,Surname,Email and telephone
// Display users
public function display(){
$temp_arr = array();
$res = $this->db->run("SELECT * FROM users ORDER by cognome,nome ");
$count=$this->db->rowCount();
while($row = $this->db->fetchArray()) {
$temp_arr[] =$row;
}
return $temp_arr;
}
<?php
$data = $user->display();
$i = 0;
foreach( $data as $eachrecord ) {
$i++;
?>
my idea was to do so how do i implement it?
$sql = "SELECT name FROM upload where id=$id";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
$image = $row['name'];
$image_src = "uploads/".$image;
<td><img src='<?php echo $image_src; ?>' ></td>
to take id use this function
// get id upload
public function getid(){
$db = new mysqli("localhost","root","", "rubrica");
if ($db-> connect_errno) {
exit();
}
$nome = $this->unome;
$cognome = $this->ucognome;
$email = $this->uemail;
$telefono = $this->utel;
$query = $db->query("SELECT id FROM users WHERE nome='$nome' and cognome='$cognome' and email='$email' and telefono='$telefono'");
$id = $query->fetch_assoc()['id'];
$db->close();
return $id;
}
thank you in advance who will help me!

i am getting infinite results when i use fetch(PDO::FETCH_ASSOC)

I have this function in a class named ManageNews:
function getLatestNews($limit){
$query = $this->link->query("SELECT * FROM news ORDER BY date DESC LIMIT $limit");
$count = $query->rowCount();
if ($count !== 0){
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
return $row;
}
}
}
When i try to get the info the news posts from the database i get them as an array, i tried doing fetchAll(PDO::FETCH_ASSOC) but it puts them in multidimensional arrays so i can't get them all using $row[0]['column name']; because they aren't all [0] the rest are [1] [2] [3] etc... so here is how i am doing it:
$news = new ManageNews();
$row = $news->getLatestNews('5');
$article_id = $row['article_id'];
$user_id = $row['user_id'];
$title = $row['title'];
$content = $row['content'];
$date = $row['date'];
print_r($row);
$user = new ManageUsers();
$row2 = $user->getUserById($user_id);
if($row2 !== 1){
$user_name = $row2['username'];
$title2 = str_replace(" ","-",$title);
echo '<div class="row">
<div class="col-lg-12"><h3 class="para"><a class="para" href="http://news.red-sec.net/article/'.$article_id.'/'.$title2.'">'.$title.'</a></h3>
<p class="para">Written by: '.$user_name.'</p>
</div>
</div>';
}
I am doing print_r($row); to see the array. when it works it just prints the newest one infinite times... i have no idea why it is doing that any help appreciated
this is what it looks like now:
http://prntscr.com/dz2b02
Personally I'd use a Generator (just to keep the basic function similar to the way you've already written it)
function getLatestNews($limit){
$query = $this->link->query("SELECT * FROM news ORDER BY date DESC LIMIT $limit");
$count = $query->rowCount();
if ($count !== 0){
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
yield $row;
}
}
}
I fixed it by doing
while($row = fetchAll(PDO::FETCH_ASSOC)){
return $row;
}
And in the file i did :
foreach($row as $r){do what i need to do}

PHP dynamic previous/next links

I have a table called "product".
I'm displaying all the data from PHP product view page by using the id parameter.
With my code:
if(isset($_GET['id'])) {
$id = $_GET['id'];
}
$query = "SELECT * FROM product WHERE id = $id ";
$select_product = $db->query($query);
while($row = $db->fetch_object($select_product)) {
$status = $row->status;
if($status == 'published') {
$title = $row->title;
echo $title;
}
}
I can pull all the data I need. In this example I can echo the title.
But how do I display a dynamic next page link? That goes same for previous link.
When I try with this code:
$query = "SELECT id FROM product";
$select_ids = $db->query($query);
while($row = $db->fetch_object($select_ids)) {
$ids = $row->id;
echo $ids;
}
I can see all the pages from that table. In my case they are 20,21,22...28
Next, I've tried like this:
$query = "SELECT id from product";
$select_ids = $db->query($query);
if($select_ids->num_rows > 0) {
$next = $id + 1;
echo 'Next';
} else {
}
With this code, my "next" link successfully goes to the next page. But, when it finishes with the result, in this case when I'm on page 28, the next dynamic link goes to empty page (29). Also this is not a good approach, because if some page, let's say 25 is deleted, the next link won't skip that page.
How can I improve that dynamic "next" link?
So first of all, you need two queries one for getting the data to display and another for counting the number of rows, also we'll need some additional variables.
Here comes the code:
$page = 1;
if(isset($_GET['page'])) {
$page = $_GET['page'];
}
$numberOfResultsPerPage = 10;
$offset = $numberOfResultsPerPage * ($page - 1)
$count = $db->query("SELECT COUNT(id) as num FROM product");
while($row = $db->fetch_object($count)) {
$numberOfRows = $row->num;
}
$query = "SELECT id FROM product LIMIT ". $offset.", ".$numberOfResultsPerPage;
$select_ids = $db->query($query);
while($row = $db->fetch_object($select_ids)) {
$ids = $row->id;
echo $ids;
}
if($page > 1) {
echo 'Prev';
}
if($page < ceil($numberOfRows / $numberOfResultsPerPage)) {
echo 'Next';
}
UPDATE:
In case you need to just find the next and previous product of the product this is the solution. It is not good if you'll have lots of products but in case the number of products is under 1000 there should not be any problems:
if(isset($_GET['id'])) {
$id = $_GET['id'];
}
$query = "SELECT id from product";
$select_ids = $db->query($query);
$ids = array();
$i = 0;
while($row = $db->fetch_object($select_ids)) {
$ids[$i] = $row->id;
if($row->id == $id) {
$index = $i;
}
$i++;
}
if(isset($ids[$index-1])) {
echo 'Prev';
}
if(isset($ids[$index+1])) {
echo 'Next';
}

Check if MySQL result is empty

I want to check if a MySQL result is empty and echo an error message.
This is my my current SQL-Script:
<?php
$sql = new rex_sql;
$sql->debugsql = 0; //Ausgabe Query
$sql->setQuery("SELECT * FROM $db_downloads WHERE gruppe = $gruppe_teilnehmer ORDER BY id DESC limit 4");
for($i=0;$i<$sql->getRows();$i++)
{
$id = $sql->getValue("id");
$dateiname = $sql->getValue("dateiname");
$dateigroesse = $sql->getValue("dateigroesse");
$dateipfad = $sql->getValue("dateipfad");
$dateidatum = date("d.m.Y",strtotime($sql->getValue("dateidatum")));
$dateizeit = date("H.i",strtotime($sql->getValue("dateidatum")));
$download_teilnehmer = $sql->getValue("teilnehmer");
$datei_projektnummer = $sql->getValue("projektnummer");
$projektseite = $sql->getValue("projektseite");
$ausgabe .= '<li><i class="fa fa-file-o"></i>'.$dateiname.'<ul><li><i class="fa fa-calendar"></i>'.$dateidatum.' | '.$dateizeit.'</li><li><i class="fa fa-circle"></i>'.$datei_projektnummer.'</li></ul></li>';
if(empty($ausgabe)) {
echo ("Error! No result!");
}
$sql->next();
}
?>
But there is no error message. I think the if-argument is wrong positioned.
Put it outside the loop:
<?php
$ausgabe = "";
$sql = new rex_sql;
$sql->debugsql = 0; //Ausgabe Query
$sql->setQuery("SELECT * FROM $db_downloads WHERE gruppe = $gruppe_teilnehmer ORDER BY id DESC limit 4");
for($i=0;$i<$sql->getRows();$i++)
{
$id = $sql->getValue("id");
$dateiname = $sql->getValue("dateiname");
$dateigroesse = $sql->getValue("dateigroesse");
$dateipfad = $sql->getValue("dateipfad");
$dateidatum = date("d.m.Y",strtotime($sql->getValue("dateidatum")));
$dateizeit = date("H.i",strtotime($sql->getValue("dateidatum")));
$download_teilnehmer = $sql->getValue("teilnehmer");
$datei_projektnummer = $sql->getValue("projektnummer");
$projektseite = $sql->getValue("projektseite");
$ausgabe .= '<li><i class="fa fa-file-o"></i>'.$dateiname.'<ul><li><i class="fa fa-calendar"></i>'.$dateidatum.' | '.$dateizeit.'</li><li><i class="fa fa-circle"></i>'.$datei_projektnummer.'</li></ul></li>';
$sql->next();
}
if(empty($ausgabe)) {
echo ("Error! No result!");
}
?>
Use php count function
if(!count($sql->getRows())) {
echo 'No data found';
}

Categories