Make query from database into a jw player link

Hi i have a simple database query that fetch the data from the database i want to make one of the row like first name into a jwplayer link so when click on first name linked plays the video

this my php code


<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("droptest", $con);

$sql="SELECT * FROM user WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";


while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td> " . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['Age'] . "</td>";
  echo "<td>" . $row['Hometown'] . "</td>";
  echo "<td>" . $row['Job'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

this the jwplayer link

<a href="#" onClick="jwplayer().load('videos/film.mp4')"><a/>

i tried like this

  echo "<td> "<a href="#" onClick="jwplayer().load(' . $row['FirstName'] .')"><a/>"</td>";

but get error

What’s the error?

Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in C:\xampp\htdocs\4film\4film\droptest\getuser1.php on line 30
this line
Code:

  echo "<td>" <a href='#' onClick='jwplayer().load(' . $row['FirstName'] .')'><a/> "</td>";

this without the link works fine but i want the link
Code:

  echo "<td> " . $row['FirstName'] . "</td>";

You’re not formatting your string correctly.

echo "<td><a href='#' onClick='jwplayer().load('" . $row['FirstName'] ."')'><a/></td>";

Everything that isn’t PHP code needs to be in a string. Then, you need know which set of quotes you are using and which characters need to be escaped.

PHP: Strings - Manual

like that it removes the error but it doesnt retrieve the row just shows the row blank

   echo "<td><a href='#' onClick='jwplayer().load('" . $row['FirstName'] ."')'><a/></td>";

Where’s the rest of your code for generating the link?

Where is $row[‘FirstName’] defined?

this my whole query from database


<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("droptest", $con);

$sql="SELECT * FROM user WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";


while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
echo "<td> <a href=\\"#\\" onClick=\\"jwplayer().load('" . $row['FirstName'] . "')\\"><a/></td>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['Age'] . "</td>";
  echo "<td>" . $row['Hometown'] . "</td>";
  echo "<td>" . $row['Job'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

ok this what i am trying to do

the jwplayer is usually called tru the onclick
like this
Code:

<a href="#" onClick="jwplayer().load({'file': 'video1_SD.mp4', 'hd.file': 'video2.mp4'})">

so i tried video1_SD replaced with . $row[‘FirstName’] .
instead to put the file name directly it will come from the database thats why i tried the pick up the first row just to test it

so how can i replace video1 and video2 with . $row[‘FirstName’] . and . $row[‘FirstName’] .

Code:

<a href="#" onClick="jwplayer().load({'file': 'video1_SD.mp4', 'hd.file': 'video2.mp4'})">

Are you getting any output from your database query?

yeah the data come out the database for example if i have one row coming from the database works fine like this

echo "<td><a href=\\"#\\" onClick=\\"jwplayer().load('" . $row['FirstName'] . "')\\">" . $row['FirstName'] . "<a/></td>";  echo "<td>" . $row['Age'] . "</td>";

but the problem is only one video linked to video player and usually to add two videos directly to the player it works like this

<a href="#" onClick="jwplayer().load({'file': 'video1.mp4', 'hd.file': 'video2.mp4'})">

so i’m looking to do the same with data coming from the database

<a href="#" onClick="jwplayer().load({'file': '$row['FirstName']', 'hd.file': '$row['FirstName']'})">

but doesnt work
how can i concatened the same way as when haing the file name but coming from the database?

You can only access one row at a time each time the while loop runs.

So, you would probably need to start storing values in variables/arrays outside of the loop to be accessed later.

However, keep in mind that there’s no guarantee video1.mpg and video2.mpg will be in the correct order coming out of the query.

so are you sugesting i do something like
var=player
player= Firsname+second name;

and then go

echo "<td><a href=\\"#\\" onClick=\\"jwplayer().load('" . $row['player'] . "')\\">" . $row['FirstName'] . "<a/></td>";

would this have the same effet if it was like

<a href="#" onClick="jwplayer().load({'file': 'hofbell30732_SD.mp4', 'hd.file': 'videos/film.mp4'})">

ok i tried like this with the array but still didnt work

$arr = array($FirstName, $secondvideo);

echo code

  echo "<td>" . $row['arr'] . "</td>";  

this how the overall looks like

<html>
<head>
<script type="text/javascript" src="jwplayer.js"></script>

</head>


<body>

<script type="text/javascript">
  jwplayer('mediaplayer').setup({
    'flashplayer': 'player.swf',
    'id': 'playerID',
    'width': '640',
    'height': '480',
    'playlistsize': '160',
	'skin': 'modieus.zip',
	'dock': 'false',
     autostart: true, 
    'plugins': {
       'hd-1': {}
    }
	
  });
</script>



<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("droptest", $con);


$arr = array($FirstName, $secondvideo);


$sql="SELECT * FROM user WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
<th>secondvideo</th>

</tr>";

//jwplayer().load('file':hofbell30732_SD.mp4','hd.file':'hofbell30732_SD.mp4')
//<a href="#" onClick="jwplayer().load({'file': 'hofbell30732_SD.mp4', 'hd.file': 'videos/film.mp4'})"> </a>
//onClick="jwplayer().load({\\'file\\': \\'hofbell30732_SD.mp4\\', \\'hd.file\\': \\'videos/film.mp4\\'})">
//  echo $row['FirstName'] . " " . $row['LastName'];
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
echo "<td><a href=\\"#\\" onClick=\\"jwplayer().load('" . $row['FirstName'] . "')\\">" . $row['FirstName'] . "<a/></td>";
   echo "<td>" . $row['LastName'] . ''. $row['Job'] . "</td>";
  echo "<td>" . $row['Age'] . "</td>";
  echo "<td>" . $row['Hometown'] . ''. $row['Job'] . "</td>";
  echo "<td>" . $row['Job'] . "</td>";  
  echo "<td><a href=\\"#\\" onClick=\\"jwplayer().load('" . $row['secondvideo'] . "')\\">" . $row['secondvideo'] . "<a/></td>";  
  
echo "<td><a href=\\"#\\" onClick=\\"jwplayer().load('" . $row['FirstName'] . ',' . $row['secondvideo'] . "')\\">" . $row['FirstName'] . "<a/></td>";

  echo "<td>" . $row['arr'] . "</td>";  

  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

?>

</body>
</html>

The $row variable is an array. It gets its values from the database query, and it’s not good practice to create new array keys in this array if they aren’t column names available from the query which was executed.

Like I alluded to in my last post, how do you know which row contains the correct “FirstName” that you’re looking for?

How is your database structured? It looks like that you just used an unrelated example and tried to use it for your purposes.

In that light, what exactly are you trying to accomplish?

no my database has the following fields well name, video1, video2HD, surname and so on
the line that you gave last time works wonderfull the the problem with it is that the jwplayer link send two files variables into the player like this (‘file’:'hofbell30732_SD.mp4) and (‘hd.file’: 'videos/film.mp4)

echo "<td><a href=\\"#\\" onClick=\\"jwplayer().load({'file': 'hofbell30732_SD.mp4', 'hd.file': 'videos/film.mp4'})\\"> " . $row['Job'] ."</td>";

so the one that you gave me before send one file name to the video player but i neede to send both as if you wrote the file name on the script name itself
as at moment this one only send one file to the player without bene hd link

echo "<td><a href=\\"#\\" onClick=\\"jwplayer().load('" . $row['video1'] . "')\\">" . $row['video1'] . "<a/></td>";

so i am trying grab the file name from the database like this and send the name which is picked from the database but not working

<a href="#" onclick="jwplayer().load({'file': '<?php echo $video1; ?>', 'hd.file': '<?php echo $video2HD; ?>'});">theLink</a>

sorry if i keep repost just to desperate been working on it for 2whole days now

Ok, post what you have in its entirety, rather than in just one-line spices. Also include your table column names.

here they are
now all i want is to grab these values on the database and insert them here

echo "<td><a href=\\"#\\" onClick=\\"jwplayer().load({'file': '".$firstvideo  ."', 'hd.file': '".$secondvideo."'})\\"> " . $row['firstvideo  '] ."</td>";

table field names

id |	firstvideo  |    secondvideo

<html>
<head>

</head>


<body>




<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("droptest", $con);

$FirstName=$_GET['FirstName'];


$sql="SELECT * FROM user WHERE id = '".$q."'";


$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>firstvideo  </th>
<th>secondvideo</th>

</tr>";

while($row = mysql_fetch_array($result))

  {
  echo "<tr>";

   echo "<td>" . $row['firstvideo  '] . ''. $row['Job'] . "</td>";
  echo "<td>" . $row['secondvideo'] . "</td>";
   
echo "<td><a href=\\"#\\" onClick=\\"jwplayer().load({'file': '".$FirstName."', 'hd.file': '".$FirstName."'})\\"> " . $row['FirstName'] ."</td>";

  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

?>

</body>
</html>

ok i managed to find a way to get it to send the data

 <a href="#" onclick="jwplayer().load({'file': '<?php echo $FirstName; ?>', 'hd.file': '<?php echo $secondvideo; ?>'});">'<?php echo $LastName; ?>'</a>

works fine
thanks for the help Force Flow
i’ll be working on another script based on this one might need to create a new thread but will try wrk on it bt basicaly whats will do is grab those same when the user click on that link send the values to a new page and plays the video probably will need help but will work on it first
thanks again for the help Force Flow