php how to put results of FOREACH into a variable?
I have the following (a bit sloppy)code:
Code (php)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
$query = "SELECT uid2 FROM friend WHERE uid1=me()";
$results = $facebook->api(array( 'method' => 'fql.query', 'query' => $query));
foreach ($results as $key=>$value) { // we need 2 foreach cause we have arrays within an array, or put another way, an array of arrays.
foreach ($value as $key2=>$value2) {
echo $value2;
echo ',';
}
}
echo $me['id'];
$results = $facebook->api(array( 'method' => 'fql.query', 'query' => $query));
foreach ($results as $key=>$value) { // we need 2 foreach cause we have arrays within an array, or put another way, an array of arrays.
foreach ($value as $key2=>$value2) {
echo $value2;
echo ',';
}
}
echo $me['id'];
This results in: 622366942,640611878,658477005,1069795465
Just like this topic author, I want to use this in a variable to use in a sql select. How to do that?
The SELECT will look something like:
Thanks,
ps I've echoed the , into it to get the result of $value2 separated by comma's. Is there a better way to do this and how? Also at the end I've added $me['id']; this is correct, it ads my own ID in the result
Kun je je vraag niet gewoon even in het Nederlands stellen aub? En kun je iets duidelijker uitleggen wat nu precies je vraag is. Je echoot nu getallen en daar moet iets mee gebeuren?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$rare_waarde = '';
$query = "SELECT uid2 FROM friend WHERE uid1=me()";
$results = $facebook->api(array( 'method' => 'fql.query', 'query' => $query));
foreach ($results as $key=>$value) { // we need 2 foreach cause we have arrays within an array, or put another way, an array of arrays.
foreach ($value as $key2=>$value2) {
$rare_waarde .= $value2;
$rare_waarde .= ',';
}
}
$rare_waarde .= $me['id'];
$query = "SELECT " . $rare_waarde . " FROM etcetc";
?>
$rare_waarde = '';
$query = "SELECT uid2 FROM friend WHERE uid1=me()";
$results = $facebook->api(array( 'method' => 'fql.query', 'query' => $query));
foreach ($results as $key=>$value) { // we need 2 foreach cause we have arrays within an array, or put another way, an array of arrays.
foreach ($value as $key2=>$value2) {
$rare_waarde .= $value2;
$rare_waarde .= ',';
}
}
$rare_waarde .= $me['id'];
$query = "SELECT " . $rare_waarde . " FROM etcetc";
?>
Bedoel je zoiets? Ipv echo'en de stukjes alsmaar toevoegen aan een string, die dan uiteindelijk de hele waarde bevat?
(ipv een foreach lus kan je ook eens kijken naar implode)
Gewijzigd op 06/01/2011 00:24:46 door Jelmer -
Code (php)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
$variable = "";
$query = "SELECT uid2 FROM friend WHERE uid1=me()";
$results = $facebook->api(array( 'method' => 'fql.query', 'query' => $query));
foreach ($results as $key=>$value) { // we need 2 foreach cause we have arrays within an array, or put another way, an array of arrays.
foreach ($value as $key2=>$value2) {
$variable .= $value2.",";
}
}
$variable .= $me['id'];
$query = "SELECT uid2 FROM friend WHERE uid1=me()";
$results = $facebook->api(array( 'method' => 'fql.query', 'query' => $query));
foreach ($results as $key=>$value) { // we need 2 foreach cause we have arrays within an array, or put another way, an array of arrays.
foreach ($value as $key2=>$value2) {
$variable .= $value2.",";
}
}
$variable .= $me['id'];
Thanks!