Re: Logic problem
| From: | Red Wingate | Date: | Tue, 20 Apr 2004 17:02:20 +0000 |
| Subject: | Re: Logic problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-184006@lists.php.net to get a copy of this message | ||
As foreach is a language-construct you cannot concat it
to a string.
try something like:
$temp = '.....';
foreach ( $array AS $key )
$temp .= '....'.$key.'....';
$temp .= '....';
instead
--red
[...]
> Hi All,
>
> I am having a logic problem. (insert jokes here) I am trying to create a
> function that will allow me to pass any number of fields and tables into a
> blanket query.
>
> I am getting an error; Unexpected foreach. I have tried placing the loop
> in several different places and am getting the same error.
>
> What should I be doing differently?
>
> Here's my code;
>
> function myselect($array1, $array2){
> $i = 0;
> $n = 0;
> $query = "SELECT".foreach($array1 as $flds){
> $flds[$i];
> }.
> "FROM".foreach($array2 as $tbls){
> $tbls[$n];
> }.;
> $result = mssql_query($query);
> print "<table width=\"100%\" border=\"1\">
> <tr>";
> $j = 0;
> while($row = mssql_fetch_array($result)){
> $fields = $row[flds[$j]];
> print "<td>".$fields."</td></tr>";
> }
> }
>
>
> alex
[...]