php - get meta value by using meta key from mysql

纵然是瞬间 提交于 2019-12-14 03:18:55

问题


I have a query like SELECT * FROM membermetas WHERE memberId =15

Table image :

and my php code is

$memberMetaQuery = "select * from membermetas where memberId='$id'";
$getMemberMeta = mysql_query($memberMetaQuery);
$memberMetaRow = mysql_fetch_array($getMemberMeta);

when i use "echo $memberMetaRow['memberMeta']" without while loop, it turns the last row.

For example:
i would like to use only the row "eposta" and its value "mail@mymail.com"
is there any selector for this?

I think that, maybe i can use like $memberMetaRow['memberMeta']['eposta'] but it's not working as you know :)

How can i get this meta value without using mysql query?
is this possible with a php selector?


回答1:


if you are ready to mention eposta manually like

$memberMetaRow['memberMeta']['eposta']

THEN its better to append query to

$memberMetaQuery = "select * from membermetas where memberId='$id' and memberMeta='eposta'";

Infact this can be use useful a function like

function call_data($id,$name){
 $memberMetaQuery = "select * from membermetas where memberId='$id' and memberMeta='$name'";
 $getMemberMeta = mysql_query($memberMetaQuery);
 $memberMetaRow = mysql_fetch_array($getMemberMeta);
 return($memberMetaRow);
}

THEN you can call

$data = call_data(15,'eposta');


来源:https://stackoverflow.com/questions/21326557/php-get-meta-value-by-using-meta-key-from-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!