Trying to fetch all rows filtered by id and returning them as array(mysql,php) -


i'm sending username database filter rows of data associated using ajax i'm getting empty response back.

 $.ajax({         type: 'post',         url: 'fetch_followed_users.php',         data: {             user : username,          },         datatype: 'json',         cache: false,         success: function(follows) {                     var jarrayallfollows=[];                  jarrayallfollows = follows;          },  }); 

and fetch_followed_users.php:

<?php     session_start();     require 'database.php';        $sql6 =  $conn->prepare("select * followedusers user = :user");        $sql6->bindparam(':user', $_post['user']);        $sql6->execute();       $results=array();       $results = $sql6->fetchall(pdo::fetch_column)        echo json_encode($results);  ?> 

i'd appreciate help. know simple thing do, can't right.

just make simpler, count in php , send response.

basic idea:

in php value , send count:

<?php  session_start();  require 'database.php';  $sql6 =  $conn->prepare("select count(*) total followedusers user = :user");  $sql6->bindparam(':user', $_post['user']);  $sql6->execute(); $count = $sql6->fetchcolumn();  echo json_encode(array('count' => $count));  ?> 

then in js success block, access response:

success: function(response) {     console.log(response.count);     // count }, 

note: don't mix mysqli pdo, pick 1 , use through out code.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -