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

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
VJD215
Forum Newbie
Posts: 2
Joined: Mon Sep 27, 2004 6:37 pm

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

Post 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;
}
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Your else/if statement appears to be layout wrong. Mabey this could be the problem?.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 ???
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

elseif

Post by phpScott »

try elseif() instead of else
if

other wise you need to
else{
if()
}
VJD215
Forum Newbie
Posts: 2
Joined: Mon Sep 27, 2004 6:37 pm

Let me try again

Post 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
Post Reply