CSV Extract Tool - embedded query not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

CSV Extract Tool - embedded query not working

Post by simonmlewis »

This is looking in a DIARY table to find the raceID that is passed through, and then grabbing the UserIDs from it, and grabbing the email addresses.

Trouble is, it's only putting "email" into field A1 and then nothing else. Anyone know why?

Code: Select all

<?php
$cookietype = $_COOKIE['type'];
$id=$_request['id'];
if ($cookietype == "admin") {
include "dbconn.php";
$csv_output = '"email"';
$csv_output .= "\015\012";
$result = mysql_query("select * from diary WHERE raceid = '$id'");
while($row = mysql_fetch_object($result)) 
{

  $users = mysql_query("select * from admin WHERE id = '$row->userid'");
  while($user = mysql_fetch_array($users)) 
  {
    $csv_output .= '"'.$user[email].'"';
    $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=document_" . date("Ymd") .
".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=index.php?page=a_login&menu=a_admin'>";
	}
	?>
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply