Re: [PHP] PHP or Mysql or Combination

2003-03-24 Thread Chris Hayes
At 15:50 24-3-03, you wrote:

I'm currently stuck in a project where I need to pull info from a
database and sort it by order of 2 seperate fields and creates a text
report of the results. No problems there but
now what the boss is wanting to do is break it up into slices of 8 records
per file and save each file individually so you get issue3page1.txt is the
first 8 results from the query and issue3page2.txt would be result 9-16 of
the query. Anything results less than 8 for the final recordset would
consitute 1 page as well.
Here's what Im using now.


well i would rebuild this structure in your code:

if ($row = mysql_fetch_array($result)) {
do {

}
while($row = mysql_fetch_array($result));
}
 to:

$recordcounter=1;
while($row = mysql_fetch_array($result));
{$recordcounter++;
  if (($recordcounter%8)==0) { fclose($fp);
$filename='issue3page'.(1+intval($recordcounter/8)) 
.'.txt';
$fp=fopen($filepath.'/'.$filename,'w+');//or 
whatever you had working
}
 
 }

this is NOT tested so try to understand what i want to do:

if (!($recordcounter%8)): whenever $recordcounter is dividible by 8, 
$recordcounter%8 is 0, because there are no "remains".

intval($recordcounter/8): 1 when $recordcounter=8

  

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] PHP or Mysql or Combination

2003-03-24 Thread ed

I'm currently stuck in a project where I need to pull info from a
database and sort it by order of 2 seperate fields and creates a text
report of the results. No problems there but
now what the boss is wanting to do is break it up into slices of 8 records
per file and save each file individually so you get issue3page1.txt is the
first 8 results from the query and issue3page2.txt would be result 9-16 of
the query. Anything results less than 8 for the final recordset would
consitute 1 page as well.

Here's what Im using now.
--
mysql_connect ($host, $user, $pass);

mysql_select_db ($database);

$result = mysql_query ("SELECT * FROM listings,agents WHERE listings.agent
= agents.name ORDER by area, price DESC");

if ($row = mysql_fetch_array($result)) {

do {

$agent = $row['agent'];

if ($row['banner'] != "No Banner") {

fputs($fp, $row['banner']);

}

fputs($fp, $nl);
fputs($fp, $sp);
fputs($fp, $sp);
fputs($fp, $ar);
fputs($fp, $sp);
fputs($fp, $row['area']);
fputs($fp, $sp);
fputs($fp, $dol);
fputs($fp, number_format($row['price'], ","));
fputs($fp, $sp);
fputs($fp, $sp);
fputs($fp, $nl);
fputs($fp, $row['copy']);
fputs($fp, $nl);

$agent_name = $row['name'];

fputs($fp, $agent_name);
fputs($fp, $nl);

$line1 = $row['line1'];
$line2 = $row['line2'];
$line3 = $row['line3'];
$line4 = $row['line4'];

fputs($fp, $line1);
fputs($fp, $nl);
fputs($fp, $line2);
fputs($fp, $nl);
fputs($fp, $line3);
fputs($fp, $nl);
fputs($fp, $line4);
fputs($fp, $nl);
fputs($fp, $nl);

}

while($row = mysql_fetch_array($result));

}

fclose($fp);

mysql_close();

echo "Done Creating Sorted Listing Report";
--

How would I go about creating files of 8 records each in individual
files?

Thanks,

Ed
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php