mysql - PHP & JSON Show column data by user -
i'm in process of relaying data column called "followers_count", in table called "tbl_users". site has several users each own page. on pages person can click follow button , follow count displayed, using json. code works far except shows/updates data of "followers_count" first "userid" in table. question is, how alter code knows each user's page display followers_count?
in changes.php:
<?php require_once 'class.channel.php'; $user_change = new user(); $seqfollows = $user_change->runquery("select followers_count tbl_users"); $seqfollows->execute(); $row = $seqfollows->fetch(pdo::fetch_assoc); $follow_count = $row['followers_count']; header('content-type: application/json'); $array = array('followers_count'=>$follow_count); echo json_encode($array); ?>
in index.php?id= (the user page template):
<div> channel adds: <div id="follow_count" style="display:inline;"></div> </div> <script type="text/javascript"> var timer; timer = setinterval(function() { $(document).ready(function(){ $.getjson('changes.php', function(data) { $('#follow_count').html(data.followers_count); }); }); }, 1 * 1000); </script>
also in index.php?id=, code determines page i'm viewing:
$currentid = ( isset( $_get['id']) && !empty( $_get['id'] ) ) ? trim($_get['id']) : '' ; $stmt = $user_home->runquery("select * tbl_users userid=:uid"); $stmt->execute(array(":uid"=>$currentid)); $row = $stmt->fetch(pdo::fetch_assoc);
you need tell changes.php user id value is. need modify index.php file supply value. 1 option modify ajax call to:
$(document).ready(function(){ $.getjson('changes.php?id=<?php echo $_get["id"]; ?>', function(data) { $('#follow_count').html(data.followers_count); }); });
then changes.php file need value of $_get['id']
index.php.
wiki
Comments
Post a Comment