Jump to content

Recommended Posts

You can but why?

 

You need to also use mysql_fetch_assoc() or a similar function to get data.

 

The actual resources are no good to store because they die when your connection closes (on page end usually)

 

I want to store the data into a, say a text file...

Like first run the query,

and then use the while loop:

while ($r = mysql_fetch_array($b)){

display data;

      }

and then make a copy of this whole data (ex: while loop's data).

fwrite($fp, All the while loop data)...

is this possible?

Link to comment
https://forums.phpfreaks.com/topic/147350-php-question/#findComment-773445
Share on other sites

$result = mysql_query($query) or die(mysql_error()); // run query
$array = array(); // setup array
while($row = mysql_fetch_assoc($result)) {
    $array[] = $row['col1'].' '.$row['col2']; // set whatever variables you are calling, you can also output here while you are at it
}
$storeInFile = implode('"\n", $array); // implode array to a single string
fwrite($fp,$storeInFile); // write to file

 

Something like that?

 

edit: missing a variable, oops :P

Link to comment
https://forums.phpfreaks.com/topic/147350-php-question/#findComment-773452
Share on other sites

$result = mysql_query($query) or die(mysql_error()); // run query
$array = array(); // setup array
while($row = mysql_fetch_assoc($result)) {
    $array[] = $row['col1'].' '.$row['col2']; // set whatever variables you are calling, you can also output here while you are at it
}
$storeInFile = implode('"\n", $array); // implode array to a single string
fwrite($fp,$storeInFile); // write to file

 

Something like that?

 

edit: missing a variable, oops :P

 

thanks, but i found another way that worked, i did something like this:

<?php
$results = mysql_query($query) or die($er);
$c = "";
while ($r = mysql_fetch_assoc($results)){
$c .= 'Data1';
$c .= 'Data2';
$c .= 'ETC';
         }
$data = $c;
$f = fopen($fp, 'w+');
fwrite ($f, $data);
fclose ($f);
?>

 

@cooldude,

Well i am trying to do something, hard to explain, i hope it works....

Link to comment
https://forums.phpfreaks.com/topic/147350-php-question/#findComment-773522
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.