Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

Mysql php stream

1 reply [Last post]

Hello all
I am having problems with my php stream. I am trying to get video from my mysql table and make them run from a stream www.mysite.com/video/stream_mysql.php?id=. But every time i type in a id like id=1 its just show the player and no video. Can you tell me if theres somethin wrong with my php code.

I have two tables in mysql songs and artist and can you also tell me how i can make this work for flv files.

the table include
id
id3_title
id3_artist
filename
path

here is my php code

<?php

// Generate an HTML page with a JW Player and an HTML playlist from a MySQL database

// for testing, call with: http://my.domain.com/path-to-file/JW Player MySQL.php?author=22
// for testing, call with: http://my.domain.com/path-to-file/JW Player MySQL.php?id=22,13,28,34

$author = (isset($_GET["author"])) ? strval($_GET["author"]) : "";
$id = (isset($_GET["id"])) ? strval($_GET["id"]) : "";

// cleanup ids, in case there are spaces
$id = preg_replace('/\s/', '', $id);

$id_array = split(',', $id);

// debug
// print_r($id_array);
// exit;
// debug

// connect to database
$db_connect = mysql_connect("localhost", "rawtvco1_nelson", "abbi.123");
$db_select = mysql_select_db("rawtvco1_nelson");

if ((!$db_connect) || (!$db_select))
{
echo "Can't connect to database<br />\n";
}

// by id
if($id[0] != '')
{
$count = 0;
foreach($id_array as $value)
{
$query = sprintf("SELECT id, id3_title, id3_artist, filename, path FROM songs WHERE id='%d'", mysql_real_escape_string($value));
$file = mysql_query($query) or die('Query failed: ' . mysql_error());
$row[$count] = mysql_fetch_assoc($file);

// get author
$row[$count]['auth'] = lookup_author($row[$count]['id3_artist']);
$count++;
}
// for the first file to load when the player is created
$first_id = $row[0]['id'];

// debug
// print_r($row);
// print "First ID: " . $first_id;
// exit;
// debug

}
// by artist
else if($author != '')
{
// first lookup author id number
$auth = lookup_author($author);

$query = sprintf("SELECT id, id3_title, id3_artist, filename, path FROM songs WHERE id3_artist='%d'", mysql_real_escape_string($author));

$file = mysql_query($query) or die('Query failed: ' . mysql_error());

// debug - get number of records
// $num_rows = mysql_num_rows($file);
// print "Rows: " . $num_rows . "\n<br />\n";

// for the first file to load when the player is created
$row = mysql_fetch_assoc($file);
$first_id = $row['id'];

// debug
// print_r($row);
// print "First ID: " . $row['id'];
// exit;
// debug

}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<title>JW Player - MP3 - MySQL</title>

<style type="text/css">
a:link
{
color: #3399FF;
font-size: 8pt;
font-family: Comic Sans MS;
}

a:visited
{
color: #000000;
font-size: 8pt;
font-family: Comic Sans MS;
}

a:active
{
color: #33FF66;
font-size: 8pt;
font-family: Comic Sans MS;
}

a:hover
{
color: #FF00FF;
font-size: 8pt;
font-family: Comic Sans MS;
}
</style>

<script type="text/javascript" src="swfobject.js"></script>

<script type='text/javascript'>
var result;
var SQLid = '1';
var SQLauthor = 'Author';
var SQLtitle = 'Title';
var SQLdescription = 'Description';

// Function to get the title, author, and description from the server
function getValues(id, request)
{
xmlhttp.open('GET', 'http://www.mysite.com/video/stream_mysql.php?id=' + id + '&request_type=' + request, true);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4)
{
if (xmlhttp.status == 200)
{
result = xmlhttp.responseText;
// debug
// rt = document.getElementById(request);
// rt.innerHTML = request + ': ' + result;
if(request == 'author')
{
SQLauthor = result;
}
if(request == 'title')
{
SQLid = id;
SQLtitle = result;
createPlayer(SQLid, SQLauthor, SQLtitle, SQLdescription);
}
}
else
{
alert("Status is " + xmlhttp.status);
}
}
}
xmlhttp.send(null);
}

// Get an XMLHttpRequest object in a portable way.
var xmlhttp

function newRequest()
{
xmlhttp = false;
// For Safari, Firefox, and other non-MS browsers
if (window.XMLHttpRequest)
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch (e)
{
xmlhttp = false;
}
}
else if (window.ActiveXObject)
{
// For Internet Explorer on Windows
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
xmlhttp = false;
}
}
}
}

function createPlayer(SQLid, SQLauthor, SQLtitle, SQLdescription)
{
var s1 = new SWFObject('mediaplayer.swf', 'single', '360', '403', '7');
s1.addVariable('width', '360');
s1.addVariable('height', '403');
s1.addVariable('displayheight', '360');
s1.addParam('allowfullscreen', 'true');
s1.addVariable('file', encodeURIComponent('stream_mysql.php?id=' + SQLid));
s1.addVariable('type', 'mp3');
s1.addVariable('author', SQLauthor);
s1.addVariable('title', SQLtitle);
s1.addVariable('description', SQLdescription);
s1.addVariable('image', 'images/' + SQLauthor + '.jpg');
s1.addVariable('overstretch', 'false'); // expands to fit h or v "false" -will stretch them to fit
s1.addVariable('showdigits', 'true');
s1.addVariable('autostart', 'true');
s1.addVariable('showicons', 'true');
s1.addVariable('usecaptions', 'true');
s1.addVariable('callback', 'clientname_video_stats.php');
s1.addVariable('captions', 'captions_Patty playlist.xml');
s1.addVariable('backcolor', '0xFFFFFF'); // face of buttons
s1.addVariable('frontcolor', '0x404040'); // button symbols & playlist text
s1.addVariable('lightcolor', '0x808080'); // highlighted playlist item
s1.addVariable('screencolor', '0x000000'); // screen background color
s1.write('player');
};

function loadPlayer(id)
{
SQLid = id;
SQLauthor = '';
getValues(SQLid, 'author');
loadTitle(SQLid);
loadfilename ='flv';
};

function loadTitle(id)
{
SQLid = id;
// wait until SQLauthor is received
if(SQLauthor == '')
{
setTimeout("loadTitle(SQLid)", 100);
}
else
{
getValues(SQLid, 'title');
}
};
</script>

</head>

<body onload="newRequest();loadPlayer(<?php echo $first_id; ?>);">

<div id="player">
<a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Plugin</a>
to see this gallery.
</div>

<table>
<tr>
<td>

<?php

if($id != '')
{
foreach($row as $value)
{

// debug
// print_r($value);
// exit;
// debug

echo "<a href='javascript:loadPlayer(" . $value['id'] . ");'>" . $value['auth'] . " - " . $value['id3_title'] . "</a>\n<br />\n";
}
}
else if($author != '')
{
// query again to reset the array, otherwise we miss the first file
$file = mysql_query($query) or die('Query failed: ' . mysql_error());

// write the HTML links
while ($row = mysql_fetch_assoc($file))
{

// debug
// echo $row['id' . "\n<br />\n"];
// echo $row['id3_title'] . "\n<br />\n";
// echo $row['id3_artist'] . "\n<br />\n";
// echo $row['filename'] . "\n<br />\n";
// echo $row['path'] . "\n<br />\n";
// debug

echo "<a href='javascript:loadPlayer(" . $row['id'] . ");'>" . $auth . " - " . $row['id3_title'] . "</a>\n<br />\n";
}
}

?>

</td>
</tr>
</table>

</body>

</html>

<?php

function lookup_author($id)
{
$query = sprintf("SELECT id, artist FROM artists WHERE id='%d'", mysql_real_escape_string($id));

$file = mysql_query($query) or die('Query failed: ' . mysql_error());

$row = mysql_fetch_array($file, MYSQL_ASSOC);

$author = $row['artist'];

return($author);
}

?>

hiiiiiiiiiiiii