Jump to content
#StayAtHome ×

narutofan

Members
  • Content Count

    64
  • Joined

  • Last visited

Community Reputation

0 Neutral

About narutofan

  • Rank
    Regular Member
  1. thanks @Barand and others who helped me to make it work. it now works now flawlessley.
  2. @Barand so, i should pass arrays is what you suggest sir ?.
  3. @Barandno need to apologise ,everybody make mistakes. i have tweaked the query & code to prevent repeated values from populating the timeline for some silly mistake that i made its not working and i couldn't figure it out. here is the code: function totalprocedures($conn, $v, $update_id1, $gp_id1) { foreach ($update_id1 as $v1) { $unique_up = array_unique($v1); $implode1 = implode(",", $unique_up); } foreach ($gp_id1 as $j => $v2) { $unique_gp = array_unique($v2); $implode2 = implode(",", $unique_gp); } foreach ($v as $i) { $implode_v = "'" . implode("','", $v) . "'"; } //return print_r($implode_v);echo '<implode1:-> ';print_r($implode1);echo 'implode2:-';print_r($implode2); $imp1 = implode(',', array_fill(1, count($v), '?')); $imp2 = implode(',', array_fill(1, count($v), '?')); $imp_u = implode(',', array_fill(1, count($v1), '?')); $imp_g = implode(',', array_fill(1, count($v2), '?')); $sqlArray = array( array( "query" => "select * FROM updates where `author` in({$imp1}) and update_id not in ({$imp_u}) order by time desc limit 1 ", "bindvalue" => $implode_v, "stopvalue" => $implode1 ), array( "query" => "select * FROM group_posts where `author_gp` in({$imp2}) and gp_id not in({$imp_g}) order by pdate desc limit 1", "bindvalue" => $implode_v, "stopvalue" => $implode2 ) ); do { try { $stmt = $conn->prepare($sqlArray[0]["query"]); $stmt1 = $conn->prepare($sqlArray[1]["query"]); $stmt->execute([$sqlArray[0]['bindvalue'], $sqlArray[0]['stopvalue']]); $rows = $stmt->fetchAll(); $stmt1->execute([$sqlArray[0]['bindvalue'], $sqlArray[0]['stopvalue']]); $rows1 = $stmt1->fetchAll(); return print_r($sqlArray); return print_r([$rows, $rows1]); } catch (Exception $exc) { echo $exc->getMessage(); } } while ($stmt->nextRowset() && $stmt1->nextRowset()); } The $sqlArray prints like this: Array ( [0] => Array ( [query] => select * FROM updates where `author` in(?,?,?,?) and update_id not in (?,?,?,?,?) order by time desc limit 1 [bindvalue] => 'wolverine','aboutthecreator','jayson','shan2batman' [stopvalue] => 302,396,307,386, ) [1] => Array ( [query] => select * FROM group_posts where `author_gp` in(?,?,?,?) and gp_id not in(?,?,?) order by pdate desc limit 1 [bindvalue] => 'wolverine','aboutthecreator','jayson','shan2batman' [stopvalue] => 104,91, ) And i get an empty array like this if i run the function: Array ( [0] => Array ( ) [1] => Array ( ) )
  4. finally i got the output to separate both the tables results: sample output: Array ( [0] => Array ( [0] => Array ( [update_id] => 396 [0] => 396 [update_body] => <div>Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum. Morbi ac felis.</div> <div>&nbsp;</div> <div>Etiam sit amet orci eget eros faucibus tincidunt. Pellentesque commodo eros a enim.</div> <div>&nbsp;</div> <div>Cras ultricies mi eu turpis hendrerit fringilla. Cras id dui.<a class="btn btn-link" href="hash_sys.php?tag=bart"> !bart </a></div> [1] => <div>Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum. Morbi ac felis.</div> <div>&nbsp;</div> <div>Etiam sit amet orci eget eros faucibus tincidunt. Pellentesque commodo eros a enim.</div> <div>&nbsp;</div> <div>Cras ultricies mi eu turpis hendrerit fringilla. Cras id dui.<a class="btn btn-link" href="hash_sys.php?tag=bart"> !bart </a></div> [url] => [2] => [time] => 2019-12-23 13:20:47 [3] => 2019-12-23 13:20:47 [host] => [4] => [vote_up] => 0 [5] => 0 [vote_down] => 0 [6] => 0 [title] => 1```--- [7] => 1```--- [user_id_u] => 142 [8] => 142 [account_name] => aboutthecreator [9] => aboutthecreator [author] => aboutthecreator [10] => aboutthecreator [type] => a [11] => a [data] => [12] => ) ) [1] => Array ( [0] => Array ( [gp_id] => 104 [0] => 104 [pid] => 0 [1] => 0 [gname] => MEP news [2] => MEP news [author_gp] => aboutthecreator [3] => aboutthecreator [type] => 0 [4] => 0 [title] => 3 Etiam feugiat lorem non metusIn consectetuer turpis ut velit [5] => 3 Etiam feugiat lorem non metusIn consectetuer turpis ut velit [data] => <div>Etiam iaculis nunc ac metus. !qwerty bPraesent egestas tristique nibh.</div><div><br></div><div>Fusce ac felis sit amet ligula pharetra condimentum. Integer ante arcu, !bart accumsan a, consectetuer eget, posuere ut, mauris.</div><div><br></div><div>Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Sed in libero ut nibh placerat accumsan.</div><div><br></div><div>Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Sed a libero.</div> [6] => <div>Etiam iaculis nunc ac metus. !qwerty bPraesent egestas tristique nibh.</div><div><br></div><div>Fusce ac felis sit amet ligula pharetra condimentum. Integer ante arcu, !bart accumsan a, consectetuer eget, posuere ut, mauris.</div><div><br></div><div>Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Sed in libero ut nibh placerat accumsan.</div><div><br></div><div>Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Sed a libero.</div> [pdate] => 2019-12-19 22:29:42 [7] => 2019-12-19 22:29:42 [vote_up] => 0 [8] => 0 [vote_down] => 0 [9] => 0 [group_id] => 25 [10] => 25 [author_id] => 142 [11] => 142 ) ) ) code that i tried is to separate the queries in a array and call it inside a function and returned the results in an array like this, Hope it might help someone in the future: function totalprocedures($conn,$v) { try { $sqlArray= array( array( "query"=> "select * FROM updates where `author` =? order by time desc limit 1 ", "bindvalue"=> array($v) ), array( "query"=>"select * FROM group_posts where `author_gp` =? order by pdate desc limit 1", "bindvalue"=>array($v) ) ); do { $stmt=$conn->prepare($sqlArray[0]["query"]); $stmt->execute($sqlArray[0]['bindvalue']); $rows=$stmt->fetchAll(); } while($stmt->nextRowset()); do { $stmt1=$conn->prepare($sqlArray[1]["query"]); $stmt1->execute($sqlArray[1]['bindvalue']); $rows1=$stmt1->fetchAll(); return array($rows,$rows1); }while($stmt1->nextRowset()); } catch (Exception $exc) { echo $exc->getMessage(); } } @Barand and @all thanks for your help , pl forgive me if i looked ignorant
  5. then how come these ppl can run multiple normal queries and get results pl check this stackoverflow page for my confusion and advice on the same as a gut feeling i know that there is a way out there to produce both the tables result.
  6. following @Barand advice i wrote a new function to test in but now the new problem is it brings only updates table result and not group_posts result. here is the new function: function totalprocedures($conn,$friend) { try{ $sql= "select * FROM updates where `author` ='".$friend."' order by time desc limit 1 ;"; $sql.="select * FROM group_posts where `author_gp` ='".$friend."' order by pdate desc limit 1"; $stmt=$conn->query($sql); // $row=$stmt->nextRowset(); //$rows= $row->fetchAll(PDO::FETCH_BOTH); while($rows=$stmt->fetch()){ return $rows; } } catch (PDOException $e) { echo $e->getMessage(); } }; i get the following result: array(26) { ["update_id"]=> string(3) "302" [0]=> string(3) "302" ["update_body"]=> string(36) "Just type and press the post button." [1]=> string(36) "Just type and press the post button." ["url"]=> string(0) "" [2]=> string(0) "" ["time"]=> string(19) "2016-12-05 07:21:04" [3]=> string(19) "2016-12-05 07:21:04" ["host"]=> string(0) "" [4]=> string(0) "" ["vote_up"]=> string(1) "1" [5]=> string(1) "1" ["vote_down"]=> string(1) "0" [6]=> string(1) "0" ["title"]=> string(22) "You know how it works." [7]=> string(22) "You know how it works." ["user_id_u"]=> string(3) "173" [8]=> string(3) "173" ["account_name"]=> string(9) "wolverine" [9]=> string(9) "wolverine" ["author"]=> string(9) "wolverine" [10]=> string(9) "wolverine" ["type"]=> string(1) "a" [11]=> string(1) "a" ["data"]=> string(0) "" [12]=> string(0) "" } (still don't know what he meant by normal queries)
  7. since i'm still learning i just didn't want to sound stupid of asking the question how??? i'm sorry if i made you uneasy. so was my approach right when it comes to stored procedure. how can i use two normal queries when ajax keeps on producing repeated values bcoz of loops in php while executing the script. its the reason i tried my hand in joins(but will reopen that thread once i finish with this stored procedure) result total failure becoz of poor design(dont know how to correct it). these are the reasons why i might look ignorant sir @Barand as an elder i respec t you the most in this community thats why i'm pestering you don't get me wrong.
  8. so, @Barand basically i need to create more out parameters is what i understand from your examples and call them through the procedure like this: begin select id1, name1 INTO @a1, @b1 FROM location1 LIMIT 1; //not limit it to 5 select id2, name2 into @a2,@b2 FROM location2 limit 1; //not limit it to 5 end // then call it like: call timeline('shan2batman','aboutthecreator',@a1,@b1,@a2,@b2); is that correct sir. as one of the eldest members you shouldn't be making fun when ppl are learning. ☹️
  9. i will try to fix them but the pressing problem at hand is executing the stored procedure. As it helps me to learn by the way sir @Barand
  10. @Barandbecause its easier and my tables have some problems for joined queries. plus i can get the values in two arrays which helps me a lot to separate them.
  11. @Barandi want to retrieve the values of both the select statements and print it in my timeline thats the objective.
  12. After changing the query to this i get the following error code: SQLSTATE[21000]: Cardinality violation: 1222 The used SELECT statements have a different number of columns sql query that was changed: select update_id as up1,account_name as acc,user_id_u as uid,author as auth,time,title as tit1,update_body as u_body INTO updates FROM updates as up where author in (friend,session_id) order by time desc limit 5 ; select gp_id as gid,author_gp as auth2,type as ty2,title as tit2,data as dat2,pdate,author_id as authid INTO group_posts FROM group_posts as gp where author_gp in (friend,session_id) order by pdate desc limit 5 ;
  13. @Barand can you help me with this. can you point where i'm going wrong.
  14. after referring to this stackoverflow page i changed the code to: public function totalProcedures($friend_name, $session_id) { /* * query to fetch stored procedure */ try { //executing the stored procedure $sql_sp = "CALL timeline (:friend,:session)" ; $stmt_sp = $this->_db->prepare($sql_sp); $stmt_sp->bindValue(":friend",$friend_name); $stmt_sp->bindValue(":session",$session_id); $stmt_sp->execute(); $row=$stmt_sp->nextRowset(); do { try { $rows = $row->fetchAll(PDO::FETCH_ASSOC); if ($rows) { return $rows; } else { echo die().'no data try rows'; } } catch (PDOException $exc) { echo $exc->getMessage(); } } while ($row->nextRowset()); } catch (PDOException $ei) { echo $ei->getMessage(); } } still not able to get results now even updates results is not coming up.
×
×
  • 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.