Toon posts:

[PHP] resultaat query in 1 string

Pagina: 1
Acties:

Verwijderd

Topicstarter
ik lees een dbase met het volgende :

[php]
$result = mysql_query("SELECT * FROM tbl");
for($i=0;$i < mysql_numrows($result);$i++){
$mds += "". mysql_result($result,$i,'naam')."<br>";
}

echo"$mds";
[/[php]

Bij een print/echo van de query zet ie het op het scherm onderelkaar.. nu wil ik dat de $mds waarde het gehele resultaat bevat uit de query. Is hier een oplossing voor?

Verwijderd

Zoek maar eens in de manual wat de concatenation operator voor strings is in php.... hint: het is niet '+'

edit:

hmm ik zie dat je het al weet.. je doet het goed en fout in 1 regel code:
$mds += "". mysql_result($result,$i,'naam')."<br>";

Verwijderd

Topicstarter
ik heb nu dit:

[php]
$result = mysql_query("SELECT * FROM tbl");
for($i=0;$i < mysql_numrows($result);$i++){
$mds .= "". mysql_result($result,$i,'naam')."<br>";
}

echo"$mds";
[/[php]

het is inderdaad niet de + teken :)


uit php net: (voor de mede-noobz)

String Operators
There are two string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side. Please read Assignment Operators for more information.


$a = "Hello ";
$b = $a . "World!"; // now $b contains "Hello World!"

$a = "Hello ";
$a .= "World!"; // now $a contains "Hello World!"


ref link: http://www.php.net/manual...language.operators.string