Page 1 of 1

Oh No, Help!!!!

Posted: Sat Nov 20, 2010 7:05 am
by jbyrne2007
Hello,

I am hoping someone who is lovely can help me!

The results this code displays I need exporting to a txt file (for apache purposes).

I am new to php so please don't judge my long winded code :(

Any help is appreciated:

Here is the code:

Code: Select all

<?php 
session_start();
require_once('admin/conn.php'); ?>

RewriteEngine on
<?php
$sqmc='select * from maincat_tb order by org asc';
$resm=mysql_query($sqmc);
if(!$resm)
{
die("Craig's broke it");
}
while($rwsm=mysql_fetch_array($resm))
{
	
$lowcasename = $rwsm['cat_name'];
$space = array("-");
$dash   = array(" ");
$newphrase = str_replace($space, $dash, $lowcasename);

$space = array("/");
$dash   = array(" ");
$newphrase = str_replace($space, $dash, $newphrase);

$lowcasename = ucwords(strtolower($newphrase));	
$space = array(" ");
$dash   = array("-");
$newphrase = str_replace($space, $dash, $lowcasename);

$sqmp='select * from product_tb where ctid="'.$rwsm['catid'].'" order by prodid asc';	
$resmp=mysql_query($sqmp);
$number=mysql_num_rows($resmp);
$rwmp=mysql_fetch_array($resmp);

	$lowcasename2 = $rwmp['prod_name'];
	$lowcasename2 = ucwords(strtolower($lowcasename2));
	$space1 = array(" ");
	$dash1   = array("-");
	$lowcasename2 = str_replace($space1, $dash1, $lowcasename2);

?>


  <br>RewriteRule    ^<?php echo $newphrase;?>/([<?php echo $rwsm['catid'];?>]+)/<?php echo $lowcasename2; ?>/([<?php echo $rwmp['prodid'];?>]+)/?$    products.php?catid=$1&prodid=$2    [NC,L]

  <?php
  if($number>1)
  {
	  $sqmp='select * from product_tb where ctid="'.$rwsm['catid'].'" AND prodid!="'.$rwmp['prodid'].'" order by prodid asc';	
	$resmp=mysql_query($sqmp);
	$rwmp=mysql_fetch_array($resmp);
	
	$lowcasename2 = $rwmp['prod_name'];
	$lowcasename2 = ucwords(strtolower($lowcasename2));
	$space1 = array(" ");
	$dash1   = array("-");
	$lowcasename2 = str_replace($space1, $dash1, $lowcasename2);
	  ?>
  <br>RewriteRule    ^<?php echo $newphrase;?>/([<?php echo $rwsm['catid'];?>]+)/<?php echo $lowcasename2; ?>/([<?php echo $rwmp['prodid'];?>]+)/?$    products.php?catid=$1&prodid=$2    [NC,L]
	
	<?php
  }
	?>
<?php
}
?>

<?php 
session_start();
require_once('admin/conn.php'); ?>

<?php
$sqmc='select * from item_tb order by itemid asc';
$resm=mysql_query($sqmc);
if(!$resm)
{
die("Craig's broke it");
}
while($rwsm=mysql_fetch_array($resm))
{
	
$lowcasename = $rwsm['item_name'];
$space = array("-");
$dash   = array(" ");
$newphrase = str_replace($space, $dash, $lowcasename);

$space = array("/");
$dash   = array(" ");
$newphrase = str_replace($space, $dash, $newphrase);

$lowcasename = ucwords(strtolower($newphrase));	
$space = array(" ");
$dash   = array("-");
$newphrase = str_replace($space, $dash, $lowcasename);

$sqmc1='select * from maincat_tb where catid="'.$rwsm['cid'].'"';	
$resm1=mysql_query($sqmc1);
$rwsm1=mysql_fetch_array($resm1);

	$lowcasename2 = $rwsm1['cat_name'];
$space = array("-");
$dash   = array(" ");
$newphrase2 = str_replace($space, $dash, $lowcasename2);

$space = array("/");
$dash   = array(" ");
$newphrase2 = str_replace($space, $dash, $newphrase2);

$lowcasename2 = ucwords(strtolower($newphrase2));	
$space = array(" ");
$dash   = array("-");
$newphrase2 = str_replace($space, $dash, $lowcasename2);

$sqmc2='select * from product_tb where prodid="'.$rwsm['pdid'].'"';	
$resm2=mysql_query($sqmc2);
$rwsm2=mysql_fetch_array($resm2);

	$lowcasename3 = $rwsm2['prod_name'];
	$lowcasename3 = ucwords(strtolower($lowcasename3));
	$space1 = array(" ");
	$dash1   = array("-");
	$lowcasename3 = str_replace($space1, $dash1, $lowcasename3);

?>


    <br>RewriteRule    ^<?php echo $newphrase2;?>/([<?php echo $rwsm['cid'];?>]+)/<?php echo $lowcasename3; ?>/([<?php echo $rwsm['pdid'];?>]+)/<?php echo $newphrase; ?>/([<?php echo $rwsm['itemid'];?>]+)/?$ prod_detail.php?catid=$1&prodid=$2&itemid=$3    [NC,L]

 
<?php
}
?>


Re: Oh No, Help!!!!

Posted: Sat Nov 20, 2010 7:45 am
by Neilos
Do you need to save the file or just use the contents of said file?

I ask because I know that you can use headers to simulate files, for example;

Code: Select all

header("Content-Type: text/plain");
I don't know how to save it but I'm sure that it wouldn't be hard to figure out if that is what you need.

Is this the kind of thing you require?

You didn't get what you had hoped for though because I'm charming not lovely. :D

Sorry to have disappointed you

Re: Oh No, Help!!!!

Posted: Sat Nov 20, 2010 2:36 pm
by spedula
Didn't really feel like reading through all the code that you have there... But here, is the script to write to new files or overwrite if it exists.

You can rewrite it as a function, that way the filename can be dynamic.

Code: Select all


$pathtofile = 'full/path/to/file/';
$newFile = $pathtofile."yourfilename.txt";
$fh = fopen($newFile, 'w') or die("can't open file");
$data = ' what ever data you want written to the file goes here ';
fwrite($fh, $data);
fclose($fh);


Re: Oh No, Help!!!!

Posted: Sun Nov 21, 2010 5:02 pm
by Jonah Bron
OP wrote:Oh No, Help!!!!
Forum Rules wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.