Jump to content

Recommended Posts

Hey guys this is my code. Basically what i want to happen is, i want the page to display with the last 10 results (which works) Then there is a button that when clicked should activate jQuery/AJAX and that should call display_full_results() which should update the #changeme div.

 

Firstly, it does not show errors. Ive no idea how to debug jQuery.

Secondly i don't know if you can call jQuery on a function on the same page.

Thirdly, i don't know if you can stick a div in the middle of a table like i have done or will that cause it to error.

 

I've no idea, any help would be appreciated.

 

<?php
session_start();
include $_SERVER['DOCUMENT_ROOT'] ."/includes/functions.php";
include $_SERVER['DOCUMENT_ROOT'] ."/includes/displays.php";


function display_recent_posts_by_user($userid){

  $res = mysql_query("SELECT * FROM b WHERE scookie = '$userid' ORDER BY ID DESC LIMIT 10") or die(mysql_error());
  while($row = mysql_fetch_array($res)){
  
          echo "<tr><td>".substr(stripslashes($row['message']),0,100) ."</td> <td>".how_long_ago($row['Lastpost'])."</td></tr>";
  
  
  }



}


function display_full_results($userid){

  $res = mysql_query("SELECT * FROM b WHERE scookie = '$userid' ORDER BY ID DESC ") or die(mysql_error());
  while($row = mysql_fetch_array($res)){
  
          echo "<tr><td>".substr(stripslashes($row['message']),0,100) ."</td> <td>".how_long_ago($row['Lastpost'])."</td></tr>";
  
  
  }



}


if($_SESSION['lv'] <4){


     add_notice("Unauthorised access attempt.");
     echo "<script>location.href = 'http://www.imgboard.co.uk'</script>";
     die();

}

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<meta name="robots" content="noarchive" />
<link rel="stylesheet" type="text/css" href="http://www.imgboard.co.uk/style/blue.css">


<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

<script type="text/javascript">

$("#button").click(   function()
      {        
            $.post("info.php",
                { fullresults: $("#scookie").val() },
                          function(data){ 
                                  $("#changeme").html(data);
                                  
                          }
              ) ;
      }
);
</script>


</head>
<body>
<div id = "wrapper">

<table cellspacing = '0'>
<th class = 'label'>
		Post
</th>
<th class = 'label'>
	When
</th>

<div id = "changeme">

<?PHP
if(isset($_GET['onuser'])){



$usid = protect($_GET['onuser']);
display_recent_posts_by_user($usid);
echo "<tr class = 'nohighlight'><td><input type = 'button' value = 'View all posts by this user.'  id= 'button'></td><td><input type = 'hidden'  id = 'scookie' value = '$usid'</td></tr>";
}


else if (isset($_POST['fullresults'])){

    $uid = protect($_POST['fullresults']);
    display_full_results($uid);


}

?>

</div>
</table>






</body>
</html>





Link to comment
https://forums.phpfreaks.com/topic/225260-ajax-calling-php-function-on-same-page/
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.