Dave Lake wrote:
> 
> Hi Folks
> 
> I have used MySQL for some time and am just getting my head around PHP. I
> looked across a number of PHP sites for some input on this but failing to
> find an answer thought I would ask some MySQL users (surely many of you are
> using PHP right? ;-) ) for help.
> 
> 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"])"
> 

Your PHP looks suspiciously like C... :)  fputs in PHP doesn't do the %
substitutions like printf.

Try modifying the line to look like this and see if this works:  (I'm
assuming you're actually opening the file for a write...)

fputs($theFile, "<br>$myrow[pos]: $myrow[first] $myrow[last] -
$myrow[age]\n"); 

> 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.
> 
> Wonder if you can explain two things for me?
> 
> The %s in the printf statements above seem to be a placeholder associated
> with the $myrow["pos"] for example. Can you use this in an fputs statement?
> 
> How would I go about printing my mysql query out to a file rather than the
> screen?
> 
> 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 in advance.
> 
> Dave Lake
> [EMAIL PROTECTED]
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to