Assistance with object data within an echo


#1

Good Afternoon All,

I have got the code below to load a pdf document using the object tag which i am hoping to use to display a pdf document. If i set like i have done below the code to statically load a document it works successfully and displays the document perfectly.

<object data="pdfs/Double Pent Store.pdf#toolbar=1" type="application/pdf" width="100%" height="700px"></object>

However when i try and use this in an echo within a php statement (below)

if (mysqli_num_rows($result) > 0 ) {
    while($row = mysqli_fetch_assoc($result)) {
    	echo "<object data='pdfs/" .$row["menu_name"]. ".pdf#toolbar=1' type='application/pdf' width='100%' height='700px'></object>";
    	} 
} else {
    echo "Please select a product from the product menu";
}

This code doesn’t display anything at all.

I have tried using a basic echo (echo "Document = pdfs/" .$row["menu_name"]. ".pdf#toolbar=1";) to check that the $row[menu_name] is getting the data from the database correctly and this is all working and displays Document = pdfs/Double Pent Store.pdf#toolbar=1.

Is someone able to assist with this as to where i am going wrong.

Thanks in advanced

Luke


#2

In your code you are missing a closing quote on the height property


#3

Hi Wava,

Thanks for your reply.

I have fixed that now however its still not working or showing the object even with the ’ added closing the height property. I have modified the code above showing what I have now got.

Thanks in advanced

Luke


#4

Well, I think you are unsure how to do this. A PDF file is not an object, it is a file. You just display the file where needed. Inserting an object does not make it an OOP item. Therefore, there is no echo’ing of it! But, if you wish to use it as an object, here is sample code that displays a PDF. You can use styling on the DIV if needed. This is not customized to your code, just a sample from online:

<div>
    <object data="test.pdf" type="application/pdf" width="300" height="200">
        alt : <a href="test.pdf">test.pdf</a>
    </object>
</div>

If you are attempting to “embed” the PDF file into your webpage, You need to alter the code and replace the object with the embed code:

<embed src="files/Brochure.pdf" type="application/pdf" width="100%" height="600px" />