[英]SQL not Selecting all rows
I am trying to go through this entire table and echo out all of the emails 我正在尝试浏览整个表格并回显所有电子邮件
Here is my query 这是我的查询
SELECT
meta_value
FROMwp_usermeta
WHEREmeta_key
='user_email' 从wp_usermeta
选择meta_value
wp_usermeta
meta_key
='user_email'
Here is a picture of when I execute it in Phpmyadmin 这是我在Phpmyadmin中执行该命令时的图片
And here is the output when I run my php script 这是我运行php脚本时的输出
array(8) {
[0]=>
string(3) "781"
["umeta_id"]=>
string(3) "781"
[1]=>
string(2) "36"
["user_id"]=>
string(2) "36"
[2]=>
string(10) "user_email"
["meta_key"]=>
string(10) "user_email"
[3]=>
string(22) "ndroyal@eagleray.co.il"
["meta_value"]=>
string(22) "ndroyal@eagleray.co.il"
}
You can clearly see there is way more than 8 rows, I can't figure this out any input would be greatly appreciated! 您可以清楚地看到有超过8行的方式,我想不出任何输入将不胜感激!
$data = $db->fetch_array("SELECT * FROM `wp_usermeta` WHERE `meta_key`='user_email'");
var_dump($data);
DB Class: 数据库类:
<?php
class DB {
function __construct() {
global $dbase;
$this->mysqli = new mysqli($dbase['host'], $dbase['user'], $dbase['pass'], $dbase['name']);
if($this->mysql->connect_error) {
die('Unable to Connect to Database');
}
}
function query($i) {
return $this->mysqli->query($i);
}
function fetch_array($i) {
if(!is_object($i)) {
// create $i as an object!
$i = $this->query($i);
}
return $i->fetch_array();
}
function num($i) {
if(!is_object($i)) {
// create $i as an object!
$i = $this->query($i);
}
return $i->num_rows;
}
}
?>
$db->fetch_array
only returns the first row of the result. $db->fetch_array
仅返回结果的第一行。 You have to use a different method to loop through all selected rows, though you'll have to figure out which method that is on your own since we don't know your database class (of which $db is an instance of). 您必须使用不同的方法来遍历所有选定的行,但是由于我们不知道您的数据库类($ db是其实例),因此您必须自己找出哪种方法。
edit: The following code should work: 编辑:以下代码应该工作:
$result = $db->query(your query);
while ($row = $result->fetch_array()) {
// do something with $row
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.