Page 1 of 1

I can't get more than one result from this code.

Posted: Mon Sep 27, 2004 6:54 pm
by VJD215
This code works fine when only one of the columns in mysql has been set with a value and the name and filename process correctly. I'm having problems when both values have been set I only get the first one's name and filename to be popped into the array. The result from the query is has follows: Lit1 =1 and Lit 2 =1, but only Lit1 is executed. What I'm I doing wrong?

Code: Select all

functionName{
  while ($row = mysql_fetch_array($result))
 {


             if($row['LIT1'] != NULL)
             {
             $name = "1.pdf";

	     $fileName 	= "../pdf/1.pdf";

             $updat= "update master set LIT1SENT='1' where UF13='$email'" ;
             $rs = mysql_query($updat, $web) 
             or die('Could not query:' .mysql_error());
             }
            else
            if($row['LIT2'] != NULL)
            {
             $name= "2.pdf";
             $fileName 	= "../pdf/2.pdf";

             $updat= "update master set LIT2SENT='1' where UF13='$email'" ;
             $rs = mysql_query($updat, $web) 
             or die('Could not query:' .mysql_error()); 
               
            }
            There are a number of others..........


            $docData = Array();
            $aDoc['name'] = $name;
            $aDoc['data'] = $data;
            $docData[]	= $aDoc; // store file data in list of all files (appends to array) 



            }

	    return $docData;
}

Posted: Mon Sep 27, 2004 7:15 pm
by Joe
Your else/if statement appears to be layout wrong. Mabey this could be the problem?.

Posted: Mon Sep 27, 2004 7:34 pm
by John Cartwright
Joe wrote:Your else/if statement appears to be layout wrong. Mabey this could be the problem?.
What's wrong with it ???

elseif

Posted: Tue Sep 28, 2004 3:00 am
by phpScott
try elseif() instead of else
if

other wise you need to
else{
if()
}

Let me try again

Posted: Tue Sep 28, 2004 6:57 am
by VJD215
EDIT patrikG:
Lesson #1: learn how to use

Code: Select all

around code snippets.[/b][/color]

I have removed the else statement and I get the last document in the array, but not the first one. So the problem is , I think I'm overwriting the array and only the last value is in. I’m not sure how to fix it.

Code: Select all

<?php
functionName{
           while ($row = mysql_fetch_array($result)) {
            if($row['LIT1'] != NULL) 
            {
             $name= "ABC.pdf";
	     $fileName 	= "../pdf/ABC.pdf";

             $updat= "update master set LIT1SENT='1' where UF13='$email'" ;
             $rs = mysql_query($updat, $web) 
             or die('Could not query:' .mysql_error()); 
             }
             if($row['LIT2'] != NULL)
            {
             $name	= "DEF.pdf";
             $fileName = "../pdf/DEF.pdf";

             $updat= "update master set LIT2SENT='1' where UF13='$email'" ;
             $rs = mysql_query($updat, $web) 
             or die('Could not query:' .mysql_error()); 
               
            }
  
	    $file = fopen("$fileName",'rb');
            $data = fread($file, filesize($fileName));
            fclose($file);

            $docData = Array();
            $aDoc['name'] = $name;		  
            $aDoc['data'] = $data;		  
            $docData[]	= $aDoc;   

            }
	    return $docData;
}

?>
Look how beautiful it looks now. Stunning. Simply stunning. Simply more proof that php brings colour to your life