Solved

Problem with 2 inclusions reacting differntly.

Posted on 2016-08-12
12
39 Views
Last Modified: 2016-08-15
I have a page that uses a variable called $P_Format to include various print formats.  Following is the code for this page:

if ($_SESSION['Last_Page'] == 'Space_Display.php' || 'Space_Edit.php')
      {
            $Data =  $_SESSION['Data'];
            $Building_Id = substr($Data,0,12);
            $Space_Id = substr($Data,12,4);
            $work = "SEQ = '$Building_Id' AND
                     STOREKEY = '$Space_Id'";
      }
$Survey_Data = $conn->query($SqlString1);
if (!$Survey_Data)
{
      echo "Query returned nothing <br>";
      echo "Str = $SqlString1 <br>";
}
            $page = "0";
            if ($_SESSION['P_Format'] == "1")
                  {
                  include 'One_Line_No_Contact_PDF_inc.php';
                  }
            if ($_SESSION['P_Format'] == "2")
                  {
                  include 'One_Line_Contact_PDF_inc.php';

The above code can' be the problem.
"'One_Line_No_Contact_PDF_inc.php" gives me an error:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, object given in /home/langsyst/public_html/Lansco/One_Line_No_Contact_PDF_inc.php on line 164

"One_Line_Contact_PDF_inc". works.  

I've attached the files.
Street_Print.php
0
Comment
Question by:breeze351
  • 5
  • 3
  • 2
  • +1
12 Comments
 

Author Comment

by:breeze351
ID: 41754420
My bad, I didn't include the 2 inclusions.  It's "One_line_no_contact" that the error comes from.
One_Line_Contact_inc.php
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 41754422
The first line is a mistake.  You need to break it into two separate comparisons.
if (($_SESSION['Last_Page'] == 'Space_Display.php') || ($_SESSION['Last_Page'] == 'Space_Edit.php'))

Open in new window

0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 41754424
Are you using 'Mysql' or 'Mysqli'?
1
 

Author Comment

by:breeze351
ID: 41754427
I just check, it didn't upload the other inclusion. Disregard "one_line_contact_inc.php"  The problem is with the pdf inclusions.
One_Line_Contact_PDF_inc.php
One_Line_No_Contact_PDF_inc.php
0
 

Author Comment

by:breeze351
ID: 41754431
Both,  I didn't get around to changing the inclusions yet but it does work for the "1 line w/ contact" inclusion.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 41754454
If you are using both 'Mysql' and 'Mysqli', you should know that they do Not work together.  A connection made with one does not work with the other.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41754480
MySQL and MySQLi  can co-exist in the same PHP script, so long as there are separate connection objects (resources) and the rest of the code uses the connection that is appropriate to its individual context.  This should be considered a temporary, short-term fix, used only to allow brief periods of testing during the transition from MySQL to MySQLi.  In other words, it should not exist for more than a few hours during a conversion and debugging cycle!
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
Warning: mysql_fetch_assoc() expects parameter 1 to be resource
This almost always means the query failed.  The article shows how to test for query success or failure, and visualize any error messages.
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 41754892
Try changing:
while ($ROW = Mysql_fetch_assoc($Survey_Data, MYSQL_BOTH))

Open in new window


to:
while ( $ROW = $Survey_Data->fetch_assoc() )

Open in new window

0
 

Author Comment

by:breeze351
ID: 41754946
I changed the code on "One_Line_No_Contact_PDF_inc.php" to read as follows:

while ( $ROW = $Survey_Data->fetch_assoc() )
//while ($ROW = Mysql_fetch_assoc($Survey_Data, MYSQL_BOTH))
{

I get the error:

FPDF error: Some data has already been output, can't send PDF file (output started at /home/langsyst/public_html/Lansco/One_Line_No_Contact_PDF_inc.php:14)

But the code is the same?
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41754958
This expert suggested creating a Gigs project.
Is this the script in question?
<?php
// **************************************************************
// * Three_Line_Diaplsy_incphp                                  *
// * Inclusion to display 3 line listing format                 *
// **************************************************************
// * Version 4.0                                                *
// **************************************************************
// * Modifications:                                             *
// * By     Date       Description                              *
// * GJJD = 09/01/15 - Modify to use MySqli                     *
// **************************************************************
?>

<?php
ob_start();
require('fpdf.php');
$pdf = new FPDF('L', 'mm', 'Letter');
$pdf->SetFont('Times','',10);
$lcount = 0;
$Page_No = "1";
$Line_Count = "6";

            $pdf->AddPage();
            $pdf->SetX(10);
            $work = "Page: ".$Page_No;
            $pdf->Cell(15, 15,$work, 0, 0, "L");
            $pdf->Cell(0, 15,'L A N S C O',0,0,'C');    
            $today = date("F j, Y, g:i a"); 
            $pdf->SetX(265);     
            $pdf->Cell(10, 15, $today, 0, 4, "R");
            
            
// Survey Header Variables
if ($_SESSION['Menu_No'] == 4)
{
    // Store Sizes
    //$total_count = $_SESSION['Total_Count'];
    $Min_Store = $_SESSION['Min_Store'];
    $Max_Store = $_SESSION['Max_Store'];
    $Min_Total = $_SESSION['Min_Total'];
    $Max_Total = $_SESSION['Max_Total'];
    $Min_Basement = $_SESSION['Min_Basement'];
    $Max_Basement = $_SESSION['Max_Basement'];
    $Min_Second = $_SESSION['Min_Second'];
    $Max_Second = $_SESSION['Max_Second'];
    $Min_Third = $_SESSION['Min_Third'];
    $Max_Third = $_SESSION['Max_Third'];

    // Rentals
    $Min_PSF = $_SESSION['Min_PSF'];
    $Max_PSF = $_SESSION['Max_PSF'];
    $Min_Monthly = $_SESSION['Min_Monthly'];
    $Max_Monthly = $_SESSION['Max_Monthly'];
    $Min_Annual = $_SESSION['Min_Annual'];
    $Max_Annual = $_SESSION['Max_Annual'];

    // Grid Location
    $North_Grid = $_SESSION['North'];
    $South_Grid = $_SESSION['South'];
    $East_Grid = $_SESSION['East'];
    $West_Grid = $_SESSION['West'];

    $work = $_SESSION['North_Grid_Name'];
    $pdf->SetX(10);
    $pdf->Cell(20, 5, 'North Grid', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "L");
        
    $work = $Min_Store;
    $pdf->SetX(60);
    $pdf->Cell(20, 5, 'Min. Store', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "R");
            
    $work = $Max_Store;
    $pdf->SetX(100);
    $pdf->Cell(30, 5, 'Max. Store', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "R");
            
    $work = $Min_PSF;
    $pdf->SetX(160);
    $pdf->Cell(20, 5, 'Min. $PSF', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "R");
            
    $work = $Max_PSF;
    $pdf->SetX(200);
    $pdf->Cell(30, 5, 'Max. $PSF', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 1, "R");
                        
    $work = $_SESSION['South_Grid_Name'];
    $pdf->SetX(10);
    $pdf->Cell(20, 5, 'South Grid', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "L");
            
    $work = $Min_Basement;
    $pdf->SetX(60);
    $pdf->Cell(20, 5, 'Min. Basement', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "R");
            
    $work = $Max_Basement;
    $pdf->SetX(100);
    $pdf->Cell(30, 5, 'Max. Basement', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "R");
            
    $work = $Min_Monthly;
    $pdf->SetX(160);
    $pdf->Cell(20, 5, 'Min. $Monthly', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "R");
            
    $work = $Max_Monthly;
    $pdf->SetX(200);
    $pdf->Cell(30, 5, 'Max. $Monthly', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 1, "R");
            
    $work = $_SESSION['East_Grid_Name'];
    $pdf->SetX(10);
    $pdf->Cell(20, 5, 'East Grid', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "L");
            
    $work = $Min_Total;
    $pdf->SetX(60);
    $pdf->Cell(20, 5, 'Min. Total', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "R");
            
    $work = $Max_Total;
    $pdf->SetX(100);
    $pdf->Cell(30, 5, 'Max. Total', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "R");
            
    $work = $Min_Annual;
    $pdf->SetX(160);
    $pdf->Cell(20, 5, 'Min. $Annual', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 0, "R");
            
    $work = $Max_Annual;
    $pdf->SetX(200);
    $pdf->Cell(30, 5, 'Max. $Annual', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 1, "R");
            
    $work = $_SESSION['West_Grid_Name'];
    $pdf->SetX(10);
    $pdf->Cell(20, 5, 'West Grid', 0, 0, "L");
    $pdf->Cell(20, 5, $work, 0, 1, "L");
}           
            
$pdf->SetX(10);
$pdf->Cell(60,5,'Address', 1, 0, "L");      
$pdf->SetX(70);
$pdf->Cell(70,5,'Crossing Streets', 1, 0, "L");
$pdf->SetX(140);
$pdf->Cell(20,5,'Ground', 1, 0, "R");
$pdf->SetX(160);
$pdf->Cell(20,5,'Basement', 1, 0, "R");
$pdf->SetX(180);
$pdf->Cell(20,5,'Mezzanine', 1, 0, "R");        
$pdf->SetX(200);
$pdf->Cell(20,5,'Total', 1, 0, "R");        
$pdf->SetX(220);
$pdf->Cell(25,5,'Asking Rental', 1, 0, "R");
$pdf->SetX(245);
$pdf->Cell(15,5,'Listed', 1, 0, "L");       
$pdf->SetX(260);
$pdf->Cell(15,5,'Updated', 1, 1, "L");      
$Page_No++;

while ($ROW = Mysql_fetch_assoc($Survey_Data, MYSQL_BOTH))
    {
        if ($_SESSION['Last_Page'] == "Space_Edit.php")
        {
            // Footage
            $ROW['STORE'] = $_POST['Store'];
            $ROW['BASEMENT'] = $_POST['Basement'];
            $ROW['MEZZANINE'] = $_POST['Mezzanine'];
            $ROW['SECOND'] = $_POST['Second'];
            $ROW['OTHER'] = $_POST['Other'];            
            $ROW['TOTAL'] = $_POST['Total'];
            
            // Sizes
            $ROW['FRONTAGE'] = $_POST['Frontage'];
            $ROW['CEILING'] = $_POST['Ceiling'];
            $ROW['DEPTH'] = $_POST['Depth'];
            
            // Rentals
            $ROW['RENT'] = $_POST['$PSF'];
            $ROW['MONTHLY'] = $_POST['Month'];
            $ROW['ANNUAL'] = $_POST['Annual'];
            
            // Possesion, Terms And Remarks
            $ROW['POSSESSION'] = $_POST['Possession'];
            $ROW['TERM'] = $_POST['Term'];
            $ROW['REMARK1'] = $_POST['Remark1'];
            $ROW['REMARK2'] = $_POST['Remark2'];
            $ROW['REMARK3'] = $_POST['Remark3'];
            $ROW['REMARK4'] = $_POST['Remark4'];
            $ROW['REMARK5'] = $_POST['Remark5'];
            $ROW['REMARK6'] = $_POST['Remark6'];
            
        }
        if ($Line_Count > "18")
        {
            $Line_Count = "3";
            $pdf->AddPage();
            $pdf->SetX(10);
            $work = "Page: ".$Page_No;
            $pdf->Cell(10, 5,$work, 0, 0, "L");
            $pdf->Cell(0, 15,'L A N S C O',0,0,'C');
            $today = date("F j, Y, g:i a"); 
            $pdf->SetX(265);     
            $pdf->Cell(10, 15, $today, 0, 4, "R");
            $pdf->SetX(10);
            $pdf->Cell(60,5,'Address', 1, 0, "L");      
            $pdf->SetX(70);
            $pdf->Cell(70,5,'Crossing Streets', 1, 0, "L");
            $pdf->SetX(140);
            $pdf->Cell(20,5,'Ground', 1, 0, "R");
            $pdf->SetX(160);
            $pdf->Cell(20,5,'Basement', 1, 0, "R");
            $pdf->SetX(180);
            $pdf->Cell(20,5,'Mezzanine', 1, 0, "R");        
            $pdf->SetX(200);
            $pdf->Cell(20,5,'Total', 1, 0, "R");        
            $pdf->SetX(220);
            $pdf->Cell(25,5,'Asking Rental', 1, 0, "R");
            $pdf->SetX(245);
            $pdf->Cell(15,5,'Listed', 1, 0, "L");       
            $pdf->SetX(260);
            $pdf->Cell(15,5,'Updated', 1, 1, "L");      
            $Page_No++;
        }

        $work = number_format("$ROW[ANNUAL]");
        $Annual = $work;
                    
        $work = number_format("$ROW[STORE]");
        $Ground = $work;
        
        $work = number_format("$ROW[BASEMENT]");
        $Basement = $work;
        
        $work = number_format("$ROW[MEZZANINE]");
        $Mezzanine = $work;
        
        $work = number_format("$ROW[TOTAL]");
        $Total = $work;
                    
        $Company = $ROW['COMPANY'];
        $Person = $ROW['FNAME'];
        

        $date = str_split("$ROW[LISTING_DA]",2);
        $Listed = $date[2]."/".$date[3]."/".$date[1];
        $date = str_split("$ROW[UPDATE_DAT]",2);
        $Updated = $date[2]."/".$date[3]."/".$date[1];
                
        $pdf->Cell(5,5,'', 0,0,' R');
//      $pdf->SetX(0);
//      $pdf->Cell(0,5,$Line_Count,0,0,'L');
        $pdf->SetX(10);
        $pdf->Cell(80,10,$ROW['ADDRESS'], 0,0,'L');
        $pdf->SetX(70);
        $pdf->Cell(80,10,$ROW['CRST'], 0,0,'L');
        $pdf->SetX(150);
        $pdf->Cell(10,10,$Ground, 0,0,'R');
        $pdf->SetX(170);
        $pdf->Cell(10,10,$Basement, 0,0,'R');
        $pdf->SetX(190);
        $pdf->Cell(10,10,$Mezzanine, 0,0,'R');
        $pdf->SetX(210);
        $pdf->Cell(10,10,$Total, 0,0,'R');
        $pdf->SetX(230);
        $pdf->Cell(10,10,$Annual, 0,0,'R');
        
        
        $pdf->SetX(245);
        $pdf->Cell(10,10, $Listed, 0,0,'L');

        $pdf->SetX(260);
        $pdf->Cell(10,10,$Updated, 0,1,'L');
        $Line_Count++;
        $lcount++;

    }

$pdf->Output();
ob_end_flush();
?>

Open in new window

If so, you will notice that PHP stops after a block of comments and starts again after a blank line.  That blank line, around line 13, is browser output.  Because ob_start() did not come before the blank line, output buffering did not catch the blank line.

Line 10 says it has been modified to use MySQLi, but look at line 164.  That's MySQL, not MySQLi.  And $Survey_Data is undefined.  It sort of looks like an abandoned project.  You might consider posting this question over in E-E Gigs to see if someone could give you some hands-on help to get it working.
0
 

Author Closing Comment

by:breeze351
ID: 41756938
Got it
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Creating and Managing Databases with phpMyAdmin in cPanel.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now