PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Oct 24, 2020 9:33 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Wed Sep 03, 2014 6:14 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
I have this script that works on another site with no errors, like this:
Syntax: [ Download ] [ Hide ]
<?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:
Syntax: [ Download ] [ Hide ]
<?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=/'>";
        }
        ?>


Syntax: [ Download ] [ Hide ]
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
 

100s of times over... and then it shows the results, but NOT with a CSV export. It does it only on screen.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Sep 03, 2014 6:18 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
You're trying to reference the array keys as constants instead of strings. You need to use $row['firstname'] rather than $row[firstname]

_________________


Top
 Profile  
 
PostPosted: Wed Sep 03, 2014 6:24 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
Yeah that works - how the heck does it work on the other site then, without the '' in there? lol

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Sep 03, 2014 6:29 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
Because PHP. Treat string indices as strings and you won't ever go wrong.

_________________


Top
 Profile  
 
PostPosted: Wed Sep 03, 2014 7:07 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
Ok. Any further thoughts on this thread: viewtopic.php?f=68&t=140163
I'm stumped.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Sep 03, 2014 7:11 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
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.

_________________


Top
 Profile  
 
PostPosted: Wed Sep 03, 2014 7:14 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
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.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Sep 03, 2014 7:22 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada

_________________


Top
 Profile  
 
PostPosted: Wed Sep 03, 2014 7:27 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
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"??

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 27 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group