mysql-num-rows

MySQL - Return number of rows matching query data?

淺唱寂寞╮ 提交于 2020-01-06 06:53:18
问题 I have a query as follows: SELECT 1 FROM shop_inventory a JOIN shop_items b ON b.id=a.iid AND b.szbid=3362169 AND b.cid=a.cid WHERE a.cid=1 GROUP BY a.bought The only thing I need to do with this data is work out the number of rows returned (which I could do with mysqli -> num_rows; . However, I would like to know if there is a method to return the number of rows that match the query, without having to run num_rows ? For example, the query should return one row, with one result, number_of

Mysqli Prepared Stmt returns 0 num_rows

↘锁芯ラ 提交于 2019-12-30 11:32:12
问题 Help. I am getting 0 num_rows but if i execute the query in the console i am getting results. I m kinda new to prepared stmts. Here is my code Database connection class: class DbConnection { const HOST = "localhost"; const USR = "root"; const PWD = ""; const DB = "club_db"; } Login class: class UsrLogin extends DbConnection { private $conn; /*db connector*/ /*login vars*/ private $usr; private $pwd; /*ctrl var*/ public $AccessGranted = false; function __construct($username,$password){ /

Warning: mysql_num_rows() expects parameter 1 to be resource boolean given [duplicate]

你离开我真会死。 提交于 2019-12-26 03:54:50
问题 This question already has answers here : mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or result (32 answers) Closed 5 years ago . I've just changed a site over to a new server, and now I'm getting an error with this code: <?php $result = mysql_query("SELECT * FROM trends "); $num_rows = mysql_num_rows($result); echo "<strong>" . $num_rows . "</strong>"; ?> The error is: Warning: mysql_num_rows() expects parameter 1 to be

mysql left join returns unexpected amount of rows

感情迁移 提交于 2019-12-24 10:49:37
问题 I have 2 tables where tableA has 41 rows and tableB has 3 rows I am trying to get the total rows of these 2 tables via a query using left join but i get way more rows(123) than expected(44) query: SELECT COUNT(*) FROM tableA as u LEFT JOIN tableB as d ON u.uid=d.uid WHERE u.uid=912391178669 AND u.deleted = 0 AND d.deleted=0 tables schema: tableA id | uid | deleted tableB id | uid | deleted 回答1: I have run the following query It is working correctly.. U can check it out. SELECT ( SELECT count(

PHP MySQLi num_rows Always Returns 0

落爺英雄遲暮 提交于 2019-12-22 06:56:46
问题 I have built a class which leverages the abilities of PHP's built-in MySQLi class, and it is intended to simplify database interaction. However, using an OOP approach, I am having a difficult time with the num_rows instance variable returning the correct number of rows after a query is run. Take a look at a snapshot of my class... class Database { //Connect to the database, all goes well ... //Run a basic query on the database public function query($query) { //Run a query on the database an

i can't make num rows inside while looping

独自空忆成欢 提交于 2019-12-20 07:12:47
问题 i have tow tables first table : For products Second Table : For Categories i want to show in browser like this category1 (20) category2 (5) category3 (3) $select_sub_cat = mysql_query("SELECT * FROM sub_cat WHERE ct_id='".$row_main['id']."' "); while($row_sub = mysql_fetch_array($select_sub_cat)) { $select_num_sub = mysql_query("SELECT * FROM market WHERE sub_cat='".$row_sub['id']."' "); $row_num_sub = mysql_num_rows($select_num_sub); $smarty->assign('numb',$row_num_sub); $sub_cats[] = $row

$result->num_rows always returns 0

烈酒焚心 提交于 2019-12-20 05:36:11
问题 after reading tons of threads, tutorials and whatever - I feel like posting here and hope that someone can help me. I tried out every advice I could get, but it's still not working. Here is my code : $prep_stmt = "SELECT id, DATE_FORMAT(added,'%d.%M'), title FROM offers ORDER BY added DESC LIMIT ?, ?;"; $stmt = $mysqli->prepare($prep_stmt); $stmt->bind_param ('ii',$lowlimit, $page); $stmt->execute(); $stmt->bind_result($id, $added, $title); while ($stmt->fetch()) { ... # some random output

num_rows: get_result vs store_result

纵然是瞬间 提交于 2019-12-20 04:28:19
问题 The following code returns 0, even though there are 5 entries in the table categories with cat = 1 . $sql = "SELECT name FROM categories WHERE cat = ?"; $stmt = $db->prepare($sql); $cat = 1; $stmt->bind_param("i", $cat); $stmt->execute(); $stmt->get_result(); echo $stmt->num_rows; However, when I change $stmt->get_result(); to $stmt->store_result(); the output is 5 . Why does get_result() not work here? I found for instance on this answer: https://stackoverflow.com/a/8722329/2311074 that get

Proper way to ask if mysql_num_rows in PHP

自闭症网瘾萝莉.ら 提交于 2019-12-12 08:16:20
问题 Because mysql_num_rows returns false if there are no rows returned, would it be best to do: $query = mysql_query("SELECT id FROM table WHERE something = 'this'"); $result = mysql_num_rows($query); if ($result) { } Or should I do: if ($result >= 1) { } 回答1: The proper one $result = mysql_query("SELECT id FROM table WHERE something = 'this'"); if (mysql_num_rows($result)){ //there are results } however, you could do this easier, without checking $result = mysql_query("SELECT id FROM table WHERE

Repeat Result for num rows in php [duplicate]

寵の児 提交于 2019-12-12 04:14:40
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: i can’t make num rows inside while looping i try allot of to make num rows in while looping to get number of rows for another tables $select_sub_cat = mysql_query("SELECT * FROM sub_cat WHERE ct_id='".$row_main['id']."' LIMIT 8 "); while($row_sub = mysql_fetch_array($select_sub_cat)) { $select_num_sub = mysql_query("SELECT * FROM market WHERE sub_cat='".$row_sub['id']."' "); while($row_num_sub = mysql_fetch