Unstoppable Domains

[Resolved] Php/mysql: Passing url variables to query & outputting to html

Spaceship Spaceship
Watch
Impact
24
php/mysql: passing url variables to query & outputting to html

I'm conjuring up a video player and it works (rather crudely) but not as efficiently as I would like.

There are 2 main files involved: videolist.php and player.php

videolist.php outputs mysql into rows with variables $title, $video & $description. From there, I am passing $video & $title which will load the video into Windows Media Player.

videolist.php:
Code:
<?php
include 'library/config.php';

$query = "SELECT * FROM $table ORDER BY id ASC";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
   echo ("<a href=\"player.php?video={$row['video']}&title={$row['title']}\">{$row['title']}</a><br 

/>{$row['description']}<br />");
} 

include 'library/closedb.php';
?>
player.php:
Code:
<?php
$video=$_GET['video'];
$title=$_GET['title'];
?>
<html>
<body>

<div class="title"><? echo $title; ?></div>
<div id="player"><object id="MediaPlayer" width="720" height="540" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">
<param name="autoStart" value="True">
<param name="filename" value="media/<? echo $video; ?>">
<param name="ShowControls" value="True">
<param name="ShowStatusBar" value="True">
<embed type="application/x-mplayer2" SRC="media/<? echo $video; ?>" name="MediaPlayer" width="640" height="480" autostart="1" showcontrols="1"></embed></object>
</div>

</body>
</html>
... this gets the job done but I would like to only pass $id to player.php which would execute a query then echo $video, $title, into the existing html.

What must I do? Thanks in advance for your input!
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
If i understand the problem correctly, :

videolist.php:
PHP:
<?php
include 'library/config.php';

$query = "SELECT * FROM $table ORDER BY id ASC";
$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result)) {
   echo '<a href="player.php?id=', $row['id'], '">', $row['title'], '</a><br />', $row['description'], '<br />';
} 

include 'library/closedb.php';
?>


player.php:
PHP:
<?php
include 'library/config.php';

// Read ID from URL
$id = $_GET['id'];

// Read data from database based on ID
$query = "SELECT * FROM $table WHERE id=$id LIMIT 1";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

// Read video and title
$video=$row['video'];
$title=$row['title'];
?>
<html>
<body>

<div class="title"><? echo $title; ?></div>
<div id="player"><object id="MediaPlayer" width="720" height="540" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">
<param name="autoStart" value="True">
<param name="filename" value="media/<? echo $video; ?>">
<param name="ShowControls" value="True">
<param name="ShowStatusBar" value="True">
<embed type="application/x-mplayer2" SRC="media/<? echo $video; ?>" name="MediaPlayer" width="640" height="480" autostart="1" showcontrols="1"></embed></object>
</div>

</body>
</html>
<?php include 'library/closedb.php'; ?>
 
1
•••
Thanks xrvel, you understood my problem perfectly :tu:

reps + NP$ headed your way
 
0
•••
Just as a note on xrvel's code. Yes it does exactly as you wish however I would slightly change the sql.

In it you have SELECT * ....

Instead of selecting all columns you should only select the ones you actually need. By selecting all you are forcing mySQL to do more work than is needed and also you increase memory consumption as you have redundant information being returned.
 
1
•••
I would also advise to perform validation against the parameters, so as to avoid possible SQL injection attacks.
 
Last edited:
1
•••
Thanks to everybody for the input :)

I would like to improve efficiency one step further.

The current wireframe is index.php which includes player.php & videolist.php, once user makes a selection from videolist.php it spawns player.php which I then have to include videolist.php in order for the user to be able to keep selecting videos.

I've been digging into ajax to spawn the player from within index.php so I don't have to duplicate the player/videlist structure in player.php

snippet from index.php:
Code:
<table>
  <tr>
    <td><?php include_once ('player.php');?></td>
    <td valign="top"><?php include_once ('videolist.php');?></td>
  </tr>
</table>
I have to do this again in player.php in order to keep the videolist visible and I know this isn't the most efficient way but it's definitely above my programming level.
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back