- Code: Select all
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf ("User: %s Product: %s", $row[1], $row[2]);
print "<br>";
}
TIA
Moderators: macek, egami, gesf
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf ("User: %s Product: %s", $row[1], $row[2]);
print "<br>";
}


<?
$mailcontents = '';
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
// adds the contents of each row to the string $mailcontents
$mailcontents .= 'User: ' . $row[1] . ' Product: ' . $row[2] . "\n";
}
mail('recipient@mail.com', 'You\'ve Got Mail', $mailcontents);
?>
swirlee wrote:
- Code: Select all
<?
$mailcontents = '';
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
// adds the contents of each row to the string $mailcontents
$mailcontents .= 'User: ' . $row[1] . ' Product: ' . $row[2] . "\n";
}
mail('recipient@mail.com', 'You\'ve Got Mail', $mailcontents);
?>
Also, you're making one of the cardinal mistakes of PHP with your usage of printf(). Instead of using printf(), you should just be using string parsing or concatenation. For reference, check out the Top 21 PHP Programming Mistakes - Part I.

frogrocker wrote:Nope, this doesnt work... it says
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/neo/public_html/studio/new/basket/check.php on line 25
frogrocker wrote:Also, you're making one of the cardinal mistakes of PHP with your usage of printf(). Instead of using printf(), you should just be using string parsing or concatenation. For reference, check out the Top 21 PHP Programming Mistakes - Part I.
Please explain...


frogrocker wrote:1. What's with all the dots?
2. How does $mailcontents seem to have more than one value..
<?
$a = 'united';
$b = 'states';
echo $a . $b; // This will print "unitedstates"
$c = $a . $b;
echo $c; // This will also print "unitedstates"
$a .= $b // This appends the contents of $b to the end of $a
// The above is essentially a shortcut for $a = $a . $b;
echo $a; // This will also print "unitedstates"
?><?
$a = "this is\nthree\nseparate lines";
echo $a;
/* The output will look like this:
----------
this is
three
separate lines
----------
Using the concatenation operator as I demonstrated
above, you can also rewrite the above in a slightly more
readable manner, and it is a good idea to do so:
*/
$b = "this is\n" .
"three\n" .
"separate lines";
/* Make note of the dots at the end of each line (except the
last). The variables $a and $b now have identical contents
(you can test this using "if($a === $b) ...").
*/
?><?
$a = "this is<br />\n" .
"three<br />\n" .
"separate lines";
?>


Users browsing this forum: No registered users and 1 guest