• 0

Echo swf file from mysql database


Question

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?

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Change 

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

to

echo "swfobject.embedSWF(" . $path . ", " . $id . ", " . $width . ", " . $height . ", " . $version . ")";
Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0

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. :)

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0

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 ;)

Link to comment
Share on other sites

This topic is now closed to further replies.