Jump to content



Photo

Echo swf file from mysql database

php flash mysql swf

  • Please log in to reply
7 replies to this topic

#1 0nyX

0nyX

    Posting from Apple //c

  • Joined: 07-April 09
  • Location: C:\Users\OnyX

Posted 23 September 2013 - 13:58

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?




#2 +Harrison H.

Harrison H.

    Neowinian

  • Tech Issues Solved: 2
  • Joined: 21-August 04
  • Location: Florida
  • OS: Windows 8.1
  • Phone: Nokia Lumia 1520

Posted 23 September 2013 - 14:02

Change 

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

to

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


#3 the better twin

the better twin

    Neowinian Senior

  • Tech Issues Solved: 2
  • Joined: 26-January 10
  • OS: Win 8
  • Phone: Nokia Lumia

Posted 23 September 2013 - 14:06

Shouldnt it be mysql_fetch_assoc not array?



#4 OP 0nyX

0nyX

    Posting from Apple //c

  • Joined: 07-April 09
  • Location: C:\Users\OnyX

Posted 23 September 2013 - 14:11

Hey guys. Thanks for the immediate replies.

 

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



#5 +Harrison H.

Harrison H.

    Neowinian

  • Tech Issues Solved: 2
  • Joined: 21-August 04
  • Location: Florida
  • OS: Windows 8.1
  • Phone: Nokia Lumia 1520

Posted 23 September 2013 - 14:19

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.



#6 OP 0nyX

0nyX

    Posting from Apple //c

  • Joined: 07-April 09
  • Location: C:\Users\OnyX

Posted 23 September 2013 - 14:23

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



#7 the better twin

the better twin

    Neowinian Senior

  • Tech Issues Solved: 2
  • Joined: 26-January 10
  • OS: Win 8
  • Phone: Nokia Lumia

Posted 23 September 2013 - 14:27

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.



#8 +Seahorsepip

Seahorsepip

    http://seapip.com

  • Tech Issues Solved: 16
  • Joined: 23-January 11
  • Location: Netherlands
  • OS: Windows 8.1 Pro
  • Phone: Nexus 5

Posted 23 September 2013 - 20:22

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





Click here to login or here to register to remove this ad, it's free!