Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

\"

Status
Not open for further replies.

matrixindicator

IS-IT--Management
Sep 6, 2007
418
BE
I compose an emaillist, quotes are required. I am struggling to put quotes around every email address. Syntax problem.

Code:
<?php 
while($data = postgressql_fetch_array($result)) 
        { 
        $to = ($nrto <> $count_rows ? $data['Eemail']",": $data['Eemail']); 
        $nrto = $nrto + 1;            
        $to = $to + $data['Eemail']; //of $to++; 
        echo $to; 
    }                
?>

thanks in advance
 
Hi

String Operators ?
PHP:
[b]while[/b] [teal]([/teal][navy]$data[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]postgressql_fetch_array[/color][teal]([/teal][navy]$result[/navy][teal]))[/teal] [teal]{[/teal]
  [navy]$to[/navy] [teal]=[/teal] [teal]([/teal][navy]$nrto[/navy] [teal]<>[/teal] [navy]$count_rows[/navy] [teal]?[/teal] [navy]$data[/navy][teal][[/teal][green][i]'Eemail'[/i][/green][teal]][highlight][red].[/red][/highlight][/teal][green][i]","[/i][/green][teal]:[/teal] [navy]$data[/navy][teal][[/teal][green][i]'Eemail'[/i][/green][teal]]);[/teal]
  [navy]$nrto[/navy] [teal]=[/teal] [navy]$nrto[/navy] [teal]+[/teal] [purple]1[/purple][teal];[/teal]            
  [navy]$to[/navy] [teal]=[/teal] [navy]$to[/navy] [teal][highlight][red].[/red][/highlight][/teal] [navy]$data[/navy][teal][[/teal][green][i]'Eemail'[/i][/green][teal]];[/teal] [gray]//of $to++;[/gray]
  [b]echo[/b] [navy]$to[/navy][teal];[/teal]
[teal]}[/teal]

Feherke.
 
Hi

Oops, I only corrected the syntax errors. Personally I would rewrite that code like this :
PHP:
[navy]$to[/navy][teal]=[/teal][green][i]''[/i][/green][teal];[/teal]
[b]while[/b] [teal]([/teal][navy]$data[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]postgressql_fetch_array[/color][teal]([/teal][navy]$result[/navy][teal]))[/teal]
  [navy]$to[/navy][teal].=([/teal][navy]$to[/navy][teal]?[/teal][green][i]','[/i][/green][teal]:[/teal][green][i]''[/i][/green][teal]).[/teal][green][i]'"'[/i][/green][teal].[/teal][navy]$data[/navy][teal][[/teal][green][i]'Eemail'[/i][/green][teal]].[/teal][green][i]'"'[/i][/green][teal];[/teal]
No idea about the circumstances, but I would also think at doing all that in the database query :
Code:
[b]select[/b] rtrim[teal]([/teal]sum[teal]([/teal][green][i]'"'[/i][/green][teal]||[/teal]Eemail[teal]||[/teal][green][i]'",'[/i][/green][teal]),[/teal][green][i]','[/i][/green][teal])[/teal] [b]as[/b] emaillist [b]from[/b] thetable[teal];[/teal]
( See thread699-1476072 for the implementation of [tt]sum()[/tt] aggregate function with [tt]text[/tt] parameter. )

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top