Jump to content

Ajax instant notification help


dk4210

Recommended Posts

Hello Guys,

I am looking for some help in showing an instant update without reloading

 

Here is my code currently. It basically a query to the database to find out if the table has been updated. I would like to create a new page and past all this code on it, then add an ajax call to grab the vaues and instantly update the notification instead of reloading...

 

 

Page 1 (with ajax call) ---------------------------- Page2 (This code). I would like it to constantly look for changes..

 

I need some help getting started.. Please advise..

<?php
	$testvar="1";
	echo "<span class=\"welcometxt\">Welcome: ";

    if ($_SESSION['fname'] == "") {
    	echo "Guest </span></div>";
    }else{
    	
    	// Grab the session id(member-id)
    	$m_id = $_SESSION['id'];
    	
    	// find out how many messages there are total with the status of 1
        $result = mysql_query("SELECT * FROM notifications WHERE member_id=$m_id AND status=1");      
         $num_rows = mysql_num_rows($result); 
         
         //Find out how many there are with the status of 1 and if the message has been read
          $resultcount = mysql_query("SELECT * FROM notifications WHERE member_id=$m_id AND status=1 AND m_read=1");       $num_rows2 = mysql_num_rows($resultcount); 
          
         
         
         
          
          
        
    	// if there are no rows There should not be a link on the flag
        if ($num_rows == '0') {
      	echo $_SESSION['fname']." ".$_SESSION ['lname']." <a href=\"#\" title=\"You have $num_rows2 Messages waiting in que\" id=\"message-tip\">";
        echo"<img src=\"/images/flag_off.jpg\" border=\"0\"></a></span></span></div>";
        
        // If the status is 1 and the message has been read
        }elseif ($num_rows > 0 && $num_rows2 =='0') {
      	echo $_SESSION['fname']." ".$_SESSION ['lname']." <a href=\"".$_SESSION['site_url']."/index.php?content=messages\" title=\"You have no new Messages waiting\" id=\"message-tip\">";
        echo"<img src=\"/images/flag_off.jpg\" border=\"0\"></a></span></span></div>";
        
        // If the status is 1 and the message has been not been read        
        }else if ($num_rows2 > 0){
        echo $_SESSION['fname']." ".$_SESSION ['lname']." <a href=\"".$_SESSION['site_url']."/index.php?content=messages\" title=\"You have $num_rows2 NEW messages waiting!\" id=\"message-tip\">";	
    	echo"<img src=\"/images/flag_on.jpg\" border=\"0\"></a></span></span></div>";
    	}else{
    		// Notify admin if there is a problem with this
    		$t_error = 24;
    		 notify_Admin($t_error,$m_id,$ip);
    		
    	}
    }
    	
  
        
    ?> 
Link to comment
Share on other sites

  • 3 months later...

Pls i need your help.i have a pxroject that am working on..i dont know if u can help me with the one time password.thus so that if a student tried to access his/her result,he needs to enter a pin and his/her id number...and he can only use the pin 5 times..here is my script..am not that mfamiliar with php..thank u..

 

and again,i dont know if its possible that i will just give out password to different student inform of a pin.so that any student can log in with any pin from the database..and automatically recognises the students id with pin together..like an e pin..thanks

 

and also the tables to create in my sql db...

include('admin/connection.php');
  include(
'sanitise.php');
  
$student_id sanitise($_POST['student_id']);
  
$password sanitise($_POST['password']);
  
  
$qry mysql_query("SELECT * FROM register_staff WHERE student_id = '$student_id' AND password = '$password'");
  
$count mysql_num_rows($qry);
  if(
$count==1)
 

 {
    
session_start();
    
$_SESSION['student_id'] = $student_id;
    
header('Location: student/index.php');
 }
 else
 {
    echo 
"Invalid ID number or Username";
 }
 
 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.