Sign in to follow this  

Echo swf file from mysql database

Recommended Posts

0nyX    259

Hi.

 

I am having trouble embedding a swf file from a database on a php page. I know how to embed a swf file using just php with the help of swfobject.js but I am having trouble being able to actually show the file from a db. I am not storing the actual file on the database but the path to the flash file (eg games/flashgame1.swf)

 

I am properly connected to the db so there is no problem there. The table is called games and has two columns for now:     id | path

 

 

Here is my code:

  
 

<?php

 
require_once('config.php');
if (!session_id()) session_start();
?>

<!DOCTYPE html>
<html>
<head>
 
<meta content="text/html; charset=UTF-8" http-equiv="content-type"> <meta name="author" content="Onyx"> 
<link rel="stylesheet" type="text/css" href="<?php echo HTTP_STYLE;?>layout.css" /> 
<link href="<?php echo HTTP_IMAGES;?>favicon.ico"rel="icon" type="image/x-icon" />

</head>

<body>
<div id="wrapper2">   
<div id="container">

<?php $result = mysql_query("SELECT * FROM games");
while($row = mysql_fetch_array($result))  {               

$path = $row['1'];    
$id = $row['0'];    
$width = "546";    
$height = "431";    
$version = "9.0.0";          

}

echo "<script type=text/javascript src=swfobject.js></script>";
echo "<script type=text/javascript>";
echo "swfobject.embedSWF('$path','$id', '$width', '$height', '$version')";
echo "</script>"; ?>
 
</div>
</div>

</body>
</html>

Any ideas what i am doing wrong?

Share this post


Link to post
Share on other sites
Harrison H.    70

Change 

echo "swfobject.embedSWF('$path','$id', '$width', '$height', '$version')";

to

echo "swfobject.embedSWF(" . $path . ", " . $id . ", " . $width . ", " . $height . ", " . $version . ")";

Share this post


Link to post
Share on other sites
the better twin    361

Shouldnt it be mysql_fetch_assoc not array?

Share this post


Link to post
Share on other sites
0nyX    259

Hey guys. Thanks for the immediate replies.

 

I tried bot suggestions but unfortunately the swf file still doesn't show up.

Share this post


Link to post
Share on other sites
Harrison H.    70

This

$path = $row['1'];    
$id = $row['0']; 

To

$path = $row['path'];    
$id = $row['id'];

With the previous 2 changes.

 

Not related to the issue, but I would switch to using PDO instead of MySQL_*. Those functions are deprecated and insecure.

Share this post


Link to post
Share on other sites
0nyX    259

Thanks nesl247.I tried the change you are suggesting as well but unfortunately no swf appears.

 

Just to be sure I created another column called image, storing paths to images and I can properly echo the image so I am connected to the DB and I have double checked the paths stored to the DB for the swf files are indeed correct.

 

I have no idea wth is going on.

 

 

* I know about the PDO.I am currently just trying to make things work and I will change later. :)

Share this post


Link to post
Share on other sites
the better twin    361

Thanks nesl247.I tried the change you are suggesting as well but unfortunately no swf appears.

 

Just to be sure I created another column called image storing paths to images and I can properly echo the image so I am connected to the DB and I have double checked the paths stored to the DB for the swf files are indeed correct.

 

I have no idea wth is going on.

 

 

* I know about the PDO.I am currently just trying to make things work and I will change later. :)

Sounds like something is wrong with your swf helper then.

Oh just noticed you need quotes around your source file location too:

echo "<script src='swfobject.js'></script>";

OR
echo '<script src="swfobject.js"></script>';

And you dont need a script type in HTML5, it assumes its javascript.

Share this post


Link to post
Share on other sites
Seahorsepip    541

Sounds like something is wrong with your swf helper then.

Oh just noticed you need quotes around your source file location too:

echo "<script src='swfobject.js'></script>";

OR
echo '<script src="swfobject.js"></script>';

And you dont need a script type in HTML5, it assumes its javascript.

echo "<script src=\"swfobject.js\"></script>";

Using \" is better in my opinion in a lot of cases, most people even don't know about this :p

And quotes really aren't that necessary with simple filenames without spaces but yeah it's better to always use them ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.