Page 2 of 4
Posted: Thu Feb 02, 2006 8:32 pm
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.
Posted: Thu Feb 02, 2006 8:36 pm
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
}
}
?>
Posted: Thu Feb 02, 2006 8:40 pm
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.
Posted: Thu Feb 02, 2006 8:42 pm
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>
Posted: Thu Feb 02, 2006 8:47 pm
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>';
?>
..........
Posted: Thu Feb 02, 2006 9:03 pm
by nickman013
Alright, I just needed help. I will play around with that jcart. thanks.
Posted: Thu Feb 02, 2006 9:11 pm
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
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>';
?>
Posted: Thu Feb 02, 2006 9:28 pm
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>'; ?>
Posted: Thu Feb 02, 2006 9:36 pm
by nickman013
Same error on the same line.
Posted: Thu Feb 02, 2006 9:38 pm
by John Cartwright
There is no error in the code I posted.
Posted: Thu Feb 02, 2006 9:40 pm
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
Posted: Thu Feb 02, 2006 9:44 pm
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?
Posted: Thu Feb 02, 2006 9:58 pm
by josh
mysql_connect(localhost,$username,$password);
Posted: Thu Feb 02, 2006 10:10 pm
by nickman013
Whats the difference? My site connect to the database through local host.
Posted: Thu Feb 02, 2006 10:12 pm
by josh
it should be 'localhost'