Reputation: 95
I have a working MySql select with an inner join:
$estateSettings = getEstateOptionsArray();
foreach($estateSettings as $s) {
$i = url_title($s, "", true);
$data = $wpdb->get_col("
SELECT meta.meta_value
FROM $wpdb->postmeta meta
INNER JOIN wp_posts ON meta.post_id = wp_posts.id
WHERE meta.meta_key = '{$i}' AND wp_posts.post_type = 'estate'
");
$returnData = $s." : ";
foreach($data as $v) {
$returnData .= $v.", ";
}
}
It's ok, $v contains the values, but the problem is if I simply echo
it out it only shows the last result value. If I echo
it like this:
echo $returnData .= $v.", ";
it shows the names and all result values.
How can I echo
the results without the returnData and to show all values?
I'm stuck again. I managed to get only the values, but it repeats them
$ingatlanSettings = getIngatlanOptionsArray();
foreach($ingatlanSettings as $s) {
$i = url_title($s, "", true);
$data = $wpdb->get_col("
SELECT meta.meta_value
FROM $wpdb->postmeta meta
INNER JOIN wp_posts ON meta.post_id = wp_posts.id
WHERE meta.meta_key = '{$i}' AND wp_posts.post_type = 'ingatlan'
");
$returnData = $s." : ";
foreach($data as $v) {
$returnData .= $v.", ";
$result[] = $v;
}
$res = $element.implode($result);
echo $res;
}
Upvotes: 2
Views: 178
Reputation: 95
thank you everybody for the help, i was able to do ot
$returnData = $s." : ";
$resdata = array_unique($data);
foreach($resdata as $v) {
$returnData .= $v.", ";
echo $result[] = $v;
really big thanks to everybody
Upvotes: 0
Reputation: 5313
its ok and all, $v contains the values, but the problem is if is simply echo it out it only shows the last result value, if i echo it like this echo $returnData .= $v.", "; it shows the names and all result values.
Here's where you're losing me. When you echo out the result, are you doing this:
echo $returnData .= $v.", ";
Or are you echo'ing:
echo $returnData;
Doing the latter would return the full string that you've prepared with all values.
I'm trying to understand the nature of your question, though. Are you trying to format $returnData
in a specific way, but then return the raw data?
Upvotes: 0
Reputation: 1480
A great way to see what an array contains is this simple script:
<?php
echo "<pre>"; print_r($YourArray); echo "</pre>";
?>
Knowhing what is actually in your array can help solve a lot of issues.
Upvotes: 0
Reputation: 2499
$returnData .= $s." : ";
foreach($data as $key=>$value) {
$returnData .= $value.", ";
}
Upvotes: 1