Hi Folks
I hope the details below will be seen as a stuctured attempt to ask my question in full with an example rather than a bloated attempt at getting a simple question answered. Wait, there are no simple questions, only simple answers. <g>
Here goes:
I have used MySQL for some time and am just getting my head around PHP.
I recently read a tutorial on mysql/php on webmonkey
(http://hotwired.lycos.com/webmonkey/99/21/index3a.html for the specific page if what I've written below isn't clear)
After doing the mysql query the results are printed out to the screen/web page similar to:
while ($myrow = mysql_fetch_array($result)) {
printf("<br>%s: %s %s - %s\n", $myrow["pos"], $myrow["first"], $myrow["last"], $myrow["age"]);
}
Where I ran into a problem was when I attempted instead to write to a file.
After opening the file I wanted to print out to I tried several different attempts to no avail.
I tried fputs($theFile, "<br>%s: %s %s - %s\n", $myrow["pos"], $myrow["first"], $myrow["last"], $myrow["age"])"
and other similar but kept getting string error messages.
I eventually came up with the following solution:
while ($myrow = mysql_fetch_array($result)) {
$mypos = $myrow["pos"]; $myfirst = $myrow["first"]; $mylast = $myrow["last"]; $myage = $myrow["age"];
fputs($theFile,"<tr><td>$mypos</td><td>$myfirst</td><td>$mylast</td><td>$myage</td></tr>\n");
}
This is okay if I am only grabbing four items but from some of my tables
the query might return 20 columns.
One person responded to me in another forum that this should be the solution I'm looking for:
write($theFile, sprintf("%s %s %s %s\n", $myrow['pos'], $myrow['first'], $myrow['last'], $myrow['age']))
but when I do that I get the following error:
Warning: Wrong parameter count for write() in /var/www/html/phptesting/php-mysql/rosters10.php4 on line 111
My solution above works but would be rather cumbersome, and I believe there
should be a more straightforward way but I can't figure it out.
Thanks for bearing with me. Any help would be appreciated.
Dave Lake
guelphdad@hotmail.com