Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

php - How would I get values from 2 rows into one

I need to access data from 2 different rows returned in the same array

Here is a picture enter image description here

I need to access first_name and last_name

Here is my script

<?php
ini_set('display_errors', 1);

include_once('db.php'); // database class
$dbase['host'] = 'asdf';
$dbase['user'] = 'asdf';
$dbase['pass'] = 'asdf';
$dbase['name'] = 'asdf';
$db = new DB($dbase);

// SELECT `meta_value` FROM `wp_usermeta` WHERE `meta_key`='password'

$result = $db->query("SELECT * FROM `wp_usermeta` WHERE `meta_key`='user_email'");
while ($row = $result->fetch_array()) {
    echo $row['meta_value'];
}
?>

Any help on this issue would be appreciated greatly!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this query..

SELECT 
wp1.meta_value AS first_name, 
wp2.meta_value AS last_name
FROM 
wp_usermeta wp1
INNER JOIN
wp_usermeta wp2
ON ( wp1.user_id = wp2.user_id )
WHERE 1
AND wp1.meta_key = "first_name"
AND wp2.meta_key = "last_name";
GROUP BY wp1.user_id;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...