Jump to content

[SOLVED] Trouble Getting Results From Query


TNGuy03

Recommended Posts

I am trying to pull my file name from a database using the following code, grabbing the record id from the URL.  I have confirmed that the id is held under $media for $query; however, I can't seem to get any results from the query itself, and no apparent query/connection errors.

 

<?php

require "cont/access.php";

 

$media = "$_GET[id]";

         

                      function showVideo($result)

                      {

                      print "\n<table border=1 align=center>\n<tr>\n" .

                            "\n\t<th align=center><font size=2>Folder</font></th>" .

                            "\n\t<th align=center><font size=2>File</font></th>" .

                            "\n</tr>";

 

         

                      while($row=@mysql_fetch_assoc($result))

                      {

                          // ... start a TABLE row ...

                          print "\n<tr>";

                         

                          // ... and print out each of the attributes in that row as a separate TD (Table Data).

                            print "\n\t<td align=right><font size=2> $row[f] </font></td>";

                            print "\n\t<td align=right><font size=2> $row[n] </font></td>";

 

                          //Finish the row

                          print "\n</tr>";

                      }

                     

                      //Then, finish the table

                      print "\n</table>\n";

                      }

                     

                      showVideo($result);

                     

$query = "SELECT folder as f, f_name as n

          FROM  Pages

          WHERE  page_id = '$media'

          GROUP BY n";

 

?>

Link to comment
Share on other sites

You do understand you never even queried the database in that script using mysql_query, right?  And you're also trying to pass the $result variable to showVideo, but $result hasn't been defined.

 

You should have:

$result = mysql_query($query) or die(mysql_error());

After you define $query but before you call showVideo

Link to comment
Share on other sites

Glyde,

Yeah...I'm new to PHP - painfully obvious.  Thanks for the tip.

 

I am now able to see the result of the query, but one of the results is a file name, which I am now trying to put into an embedded media player for viewing in the user's web browser.  While I am now seeing the results successfully as text, I cannot get the filename $row[n] to appear in the embedded media script.

 

<?php

                    require "cont/access.php";

                   

                    $media=$_GET[id];

 

                    //Show the categories in an HTML <table>

                    function showFile($result)

                    {

                      //Find out how many rows are available

                      $rowsFound=@mysql_num_rows($result);

                                             

                      //Start a table with column headers

                      print "\n<table border=1 align=center>\n<tr>\n" .

                            "\n\t<th align=center><font size=2>Folder</font></th>" .

                            "\n\t<th align=center><font size=2>File</font></th>" .

                            "\n</tr>";

                           

                      //Until there are no rows in the result set, fetch a row into the $row array and ...

                      while($row=@mysql_fetch_assoc($result))

                      {

                          // ... start a TABLE row ...

                          print "\n<tr>";

                         

                          // ... and print out each of the attributes in that row as a separate TD (Table Data).

                            print "\n\t<td align=right><font size=2> $row[f] </font></td>";

                            print "\n\t<td align=right><font size=2> $row[n] </font></td>";

 

                          //Finish the row

                          print "\n</tr>";

                      }

                     

                      //Then, finish the table

                      print "\n</table>\n";

                     

                      //Report how many rows were found

                      print "<center><br><font size=1><i>Top {$rowsFound} Audio Files (Real Time)</i></font><br></center>";

                    }

                   

                    $query="SELECT folder as f, f_name as n

                            FROM  Pages

                            WHERE  page_id = '{$media}'

                            GROUP BY n";

                                               

                    //Connect to the MySQL server

                    if(!($connection=@mysql_connect($hostName, $userName, $password)))

                      die("Cannot connect");

                   

                    if(!(mysql_select_db($databaseName, $connection)))

                      showerror();

                     

                    //Run the query on the connection

                    if(!($result=@mysql_query($query, $connection)))

                      showerror();

                     

                    //Display the results

                    showFile($result);

                   

echo "                   

<OBJECT ID=MediaPlayer1 width=400 height=300

  classid=CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95

  CODEBASE=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715

        standby=Loading Microsoft® Windows® Media Player components...

        type=application/x-oleobject>

  <PARAM NAME=AutoStart VALUE=True>

  <PARAM NAME=FileName VALUE=/video/{$row[n]}>

  <PARAM NAME=ShowControls VALUE=True>

  <PARAM NAME=EnableContextMenu Value=False>

  <PARAM NAME=ShowStatusBar VALUE=True>

  <EMBED type=application/x-mplayer2

  pluginspage=http://www.microsoft.com/Windows/MediaPlayer/

  SRC=/video/{$row[n]}

  name=MediaPlayer1

  width=400

  height=300

  autostart=1

  showcontrols=1

  enablecontextmenu=0

  showstatusbar=1>

  </EMBED>

</OBJECT>";

 

?>

Link to comment
Share on other sites

Glyde,

The print_r($row) shows the same results that I confirmed with display in the table.

 

The filename of the video clip I want to display (abc.wmv) is what is returned by the showFile function above.  Now I want to take that filename ($row[n] from my query) and use it in the embedded media player.  The player is loading but if I look at the HTML source from the browser the file name (abc.wmv aka $row[n]) is missing from the source code.  Is this an issue with where I am placing the code for the embedded player?

 

Regards

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.