Making a Video Player.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

I have a video page.

It has links to play other videos. For example.

Code: Select all

<a href="/play.php?id=2">Play Video 2!</a>
<a href="/play.php?id=6">Play Video 6!</a>
<a href="/play.php?id=9">Play Video 9!</a>
If they pick the first link, it will select the video with the ID 2 out of the DB and play it. In play.php.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Code: Select all

<?php
	$query = "select `Id`, `Name` from `vidoes`"; //just blind query for demo purpose
	if (is_resource($result = mysql_query($query)) === TRUE){
		while($row = mysql_fetch_row($result)){
?>
			<a href = 'http://www.example.com/play.php?id=<?php echo $row[0]; ?>'>
				<?php echo $row[1]; ?>
			</a>
<?php	
		}
	}
?>
Last edited by raghavan20 on Thu Feb 02, 2006 8:46 pm, edited 1 time in total.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

I dont think you mean, what I mean.

If users go to http://www.example.com/play.php?id=4

It will go to play.php and it will play the filename for id 4.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

for that to work, you should have a location field in the DB which holds the locations of the media files
examples:
Location
/movies/a/armageddon.mpeg
/movies/j/jasongoestohell.mpeg
/movies/o/oceaneleven.mpeg
or

http://yourhost.com/movies/g/gonein60seconds.mpeg

now inside a tag you have to put this

Code: Select all

for absolute URL
<a href = '<?php echo $row['Location']; ?>'>
<?php echo $row['name']; ?>
</a>

for relative path..
I assume the movies directory is of the same level of the script running directory
<a href = '../<?php echo $row['Location']; ?>'>
<?php echo $row['name']; ?>
</a>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

raghaven I don't think you understand what he is asking..

OP: I've basically told you, and given some of the code, that you will need... were not here to do your homework

Code: Select all

<?php

$clause = '';
if (!empty($_GET['id'])) {
   $clause  = 'WHERE '; 
   $clause .=  (is_numeric($_GET['id']) 
      ? '`id` ';
      : '`fileName` '
   );
   $clause .= '= \''. mysql_real_escape_string($_GET['id']) .'\' LIMIT 1'; 
}
   
$sql = 'SELECT `fileName` FROM `videos` '. $clause; 

//now mysql_query($sql) ... 
//mysql_fetch_assoc() ...

echo '<EMBED SRC=\'path\to\'.$row['fileName'].'\' AUTOSTART=true></EMBED>';

?>

..........
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Alright, I just needed help. I will play around with that jcart. thanks.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/muot/public_html/newsite/videos/play.php on line 3
Line 3

Code: Select all

$clause = '';
play.php

Code: Select all

<?
include("/home/muot/public_html/newsite/videos/connectv.php");
$clause = ''; 
if (!empty($_GET['id'])) { 
$clause  = 'WHERE ';  
$clause .=  (is_numeric($_GET['id'])  
? '`id` '; 
: '`fileName` ' 
); 
$clause .= '= \''. mysql_real_escape_string($_GET['id']) .'\' LIMIT 1';  
} 
$sql = 'SELECT `Filename` FROM `videos` '. $clause;  
echo '<EMBED SRC=\'path\to\'.$row['Filename'].'' AUTOSTART=true></EMBED>'; 
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

oopsie

Code: Select all

<?php
$clause = '';
if (!empty($_GET['id'])) {
   $clause  = 'WHERE '; 
   $clause .=  (is_numeric($_GET['id']) 
      ? '`id` '
      : '`fileName` '
   );
   $clause .= '= \''. mysql_real_escape_string($_GET['id']) .'\' LIMIT 1'; 
}
   
$sql = 'SELECT `fileName` FROM `videos` '. $clause; 

//now mysql_query($sql) ... 
//mysql_fetch_assoc() ...

echo '<EMBED SRC="path/to/'.$row['fileName'].'" AUTOSTART=true></EMBED>'; ?>
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Same error on the same line.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

There is no error in the code I posted.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

I dont know why I am getting the error.

EDIT: I know why, i am including a connect file. It is getting the error from that, not from your code. Thanks
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Ignore that.

This is play.php

Code: Select all

<?php
$username= "muot_video";
$password= "password";
$database= "muot_videos";
mysql_connect(localhost,$username,$password);
$clause = '';
if (!empty($_GET['ID'])) { 
$clause  = 'WHERE ';  
   $clause .=  (is_numeric($_GET['ID'])  
      ? '`ID` ' 
      : '`Fileame` ' 
   ); 
   $clause .= '= \''. mysql_real_escape_string($_GET['ID']) .'\' LIMIT 1';  
} 
    
$sql = 'SELECT `Filename` FROM `videos` '. $clause;  

//now mysql_query($sql) ...  
//mysql_fetch_assoc() ... 

echo '<EMBED SRC="path/to/'.$row['Filename'].'" AUTOSTART=true></EMBED>'; ?>
The error I am getting from that page is
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/muot/public_html/newsite/videos/play.php on line 6
Line 6
$clause = '';
Is it because there is multiple clause strings?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

mysql_connect(localhost,$username,$password);
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Whats the difference? My site connect to the database through local host.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

it should be 'localhost'
Post Reply