Page 1 of 1

CSV Export - why the undefineds??

Posted: Wed Sep 03, 2014 6:14 am
by simonmlewis
I have this script that works on another site with no errors, like this:

Code: Select all

<?php

$cookietype = isset($_COOKIE['type']) ? $_COOKIE['type'] : null;

$todaydate = date('Y-m-d');
$catid = isset($_REQUEST['catid']) ? $_REQUEST['catid'] : null;
if ($cookietype == "admin") {

include "dbconn.php";
$csv_output = '"Product ID","Product","Romancode","Category"';
$csv_output .= "\015\012";

$result = mysql_query("SELECT id, title, romancode, catname FROM products WHERE rcstock = 'out of stock' AND catid = '$catid'");
while($row = mysql_fetch_array($result)) 
{      
  $csv_output .= '"'.$row[id].'","'.$row[title].'","'.$row[romancode].'","'.$row[catname].'"';
    $csv_output .= "\015\012";
}
  //You cannot have the breaks in the same feed as the content. 
  header("Content-type: application/vnd.ms-excel");
  header("Content-disposition: csv; filename=SoldOutProducts_" . date("d-m-Y") .".csv");
  print $csv_output;
  exit;
       	mysql_close($sqlconn);
  echo "Extract in progress - close page when completed.";
	}

	else 
	{
	echo "<meta http-equiv='Refresh' content='0 ;URL=/'>";
	}
	?>
But this version, looking on a different DB, where all fields do have data, is erroring:

Code: Select all

<?php

$cookietype = isset($_COOKIE['type']) ? $_COOKIE['type'] : null;

if ($cookietype == "admin") {

include "dbconn.php";
$csv_output = '"Firstname","Lastname","Email","Password"';
$csv_output .= "\015\012";

$result = mysql_query("SELECT firstname, lastname, email, password, `type` FROM admin WHERE `type` <> 'admin'");
while($row = mysql_fetch_array($result)) 
{      
  $csv_output .= '"'.$row[firstname].'","'.$row[lastname].'","'.$row[email].'","'.$row[password].'","'.$row[type].'"';
    $csv_output .= "\015\012";
}
  //You cannot have the breaks in the same feed as the content. 
  header("Content-type: application/vnd.ms-excel");
  header("Content-disposition: csv; filename=SoldOutProducts_" . date("d-m-Y") .".csv");
  print $csv_output;
  exit;
       	mysql_close($sqlconn);
  echo "Extract in progress - close page when completed.";
	}

	else 
	{
	echo "<meta http-equiv='Refresh' content='0 ;URL=/'>";
	}
	?>
[text]Notice: Use of undefined constant firstname - assumed 'firstname' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14

Notice: Use of undefined constant lastname - assumed 'lastname' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14

Notice: Use of undefined constant email - assumed 'email' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14

Notice: Use of undefined constant password - assumed 'password' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14

Notice: Use of undefined constant type - assumed 'type' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14
[/text]
100s of times over... and then it shows the results, but NOT with a CSV export. It does it only on screen.

Re: CSV Export - why the undefineds??

Posted: Wed Sep 03, 2014 6:18 am
by Celauran
You're trying to reference the array keys as constants instead of strings. You need to use $row['firstname'] rather than $row[firstname]

Re: CSV Export - why the undefineds??

Posted: Wed Sep 03, 2014 6:24 am
by simonmlewis
Yeah that works - how the heck does it work on the other site then, without the '' in there? lol

Re: CSV Export - why the undefineds??

Posted: Wed Sep 03, 2014 6:29 am
by Celauran
Because PHP. Treat string indices as strings and you won't ever go wrong.

Re: CSV Export - why the undefineds??

Posted: Wed Sep 03, 2014 7:07 am
by simonmlewis
Ok. Any further thoughts on this thread: viewtopic.php?f=68&t=140163
I'm stumped.

Re: CSV Export - why the undefineds??

Posted: Wed Sep 03, 2014 7:11 am
by Celauran
You want to do 'responsive' without resizing or changing the flow. You're trying to fit 850px of content into 768px of viewport. It's not going to work.

Re: CSV Export - why the undefineds??

Posted: Wed Sep 03, 2014 7:14 am
by simonmlewis
It does work. If I set the Viewport to 1024, it fits into the ipad in portrait just fine, but then it forces iPhone to use the same thing.
Surely I don't have to set a CSS @media for lots of different sizes?

I want the main site to be displayed on all but -768px wide screens. If it's 768, it then shows the smaller version.

Re: CSV Export - why the undefineds??

Posted: Wed Sep 03, 2014 7:22 am
by Celauran
simonmlewis wrote:If I set the Viewport to 1024, it fits into the ipad in portrait just fine, but then it forces iPhone to use the same thing.
That's a peculiar definition of 'working'.
simonmlewis wrote:Surely I don't have to set a CSS @media for lots of different sizes?
That is, in fact, how breakpoints work.

Re: CSV Export - why the undefineds??

Posted: Wed Sep 03, 2014 7:27 am
by simonmlewis
Viewport, as I understand it, "fits to screen" whatever is on the screen to that set width.
If you set the width to width=device-width, should it not fit it to screen no matter what is there?

So in theory, why can I not say "if it is less than 768px, use @media for small screen, if over 768px, use the normal one, and use Viewport to "fit to screen"??