0

I'm trying to get the first and last name values for ONE person in a database where the meet certain conditions of being a team leader and having a specific project id. Because of this, it will always be one row.

I have this

$leader_result = $wpdb->get_results("SELECT user_first_name, user_last_name FROM ".$wpdb->prefix."mro_attendees WHERE event_id = ".$project_id." AND user_role = 'team_leader' LIMIT 1");

But I'm not sure how to get the first and last names from they query. I tried setting up a while but when I did a test and echo'd the variables for the whiles I got nothing. What exactly am I doing wrong here? Is there something wrong with the WP query itself?

Tried with updates and still not getting information out of the echo.

$leader_result = $wpdb->get_results("SELECT user_first_name, user_last_name FROM ".$wpdb->prefix."mro_attendees WHERE event_id = ".$project_id." AND user_role = 'team_leader' LIMIT 0,1");
$leader_select = mysql_query($leader_result);
$row = mysql_fetch_row($leader_select);
$leader_first = $row[0];

If I echo $leader_first I get nothing as well.

1 Answer 1

0
$leader_result = $wpdb->get_results("SELECT user_first_name, user_last_name FROM ".$wpdb->prefix."mro_attendees WHERE event_id = ".$project_id." AND user_role = 'team_leader' LIMIT 0,1")

foreach($leader_result as $row=>$value) { echo $value->column_name; }

6
  • Please add an explanation to your answer: why could that solve the problem?
    – fuxia
    Commented Jun 5, 2014 at 22:35
  • there is something wrong in the query , in the limit section , limit is being set as 1 , whereas the limit takes 2 arguments , offset and limit, so setting limit 0,1 will fetch 1 row from the table .
    – Bhawin
    Commented Jun 5, 2014 at 22:40
  • So if I use mysql_query on on that result and fetch the row I should be able to get the results from $row[0]; and $row[1];? Commented Jun 5, 2014 at 22:50
  • Seems like that didn't do anything either. Commented Jun 5, 2014 at 22:52
  • why do you will use mysql_query in wordpress , there is a function $results=$wpdb->getresults(); which will give u object having all the results.
    – Bhawin
    Commented Jun 5, 2014 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.