Page 1 of 1

php / sql question

Posted: Tue Sep 15, 2009 10:42 pm
by razz
Hello.

the code bellow get's and pastes the name of a file, the size of it and when it was uploaded for example "epic.swf - 2Mb - 2009-09-16". in the code i pasted bellow i have a someting i wanna ask. how could i do so that when someone for example clicks on "epic.swf" and "play.php" opens in a new window the row ". $row["name"] . " should print out the name of the file that was clicked in this manner "echo '<a href="/. $row["name"] . "></a>"'" how could i do this?

Code: Select all

 
<?
$sql = "SELECT * FROM flash ORDER BY date DESC LIMIT 10";
 
$result = mysql_query($sql);
 
if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}
 
if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}
 
<?
     while ($row = mysql_fetch_assoc($result)) {
     
            echo "<table border=\"0\" width=\"100%\" bgcolor=\"#8b8077\" bordercolor=\"#d3dfe2>\" style=\"border-collapse: collapse\">";
            echo "<tr>";
                echo "<td width=\"159\">THUMBS;</td>";
                echo "<td width=\"159\"><a href=\"play.php\">" . $row["name"] ."</a></td>";
                echo "<td width=\"159\">VIEWS;</td>";
                echo "<td width=\"159\">" . $row["size"] . "</td>";
                echo "<td width=\"194\">" . $row["date"] . "</td>";
            echo "</tr>";
        echo "</table>";
        }
?>
</td>
</td>
</tr>
</tr>
</table>

Re: php / sql question

Posted: Tue Sep 15, 2009 10:53 pm
by requinix
What's the name of the unique field in the table? Might be auto_incremented? I'll call it "id" - make sure you change it to whatever it needs to be.

Code: Select all

echo "<td width=\"159\"><a href=\"play.php?id=" . $row["id"] . "\">" . $row["name"] ."</a></td>";
play.php then uses $_GET["id"] (the unique ID of whatever it should play) to look up which file to use.

Re: php / sql question

Posted: Tue Sep 15, 2009 11:43 pm
by razz
tasairis wrote:What's the name of the unique field in the table? Might be auto_incremented? I'll call it "id" - make sure you change it to whatever it needs to be.

Code: Select all

echo "<td width=\"159\"><a href=\"play.php?id=" . $row["id"] . "\">" . $row["name"] ."</a></td>";
play.php then uses $_GET["id"] (the unique ID of whatever it should play) to look up which file to use.
Id did like you said so now my links are "/play.php?id=4" but when i open play.php nothing happens, the values are empety. what i have i play.php now is this

Code: Select all

<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" >
    <param name="movie" value="<? $_GET["id"] ?>">
    <param name="quality" value="High">
    <embed src="<? $_GET["id"] ?>" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj1"></object>

Re: php / sql question

Posted: Wed Sep 16, 2009 12:49 am
by requinix
tasairis wrote:play.php then uses $_GET["id"] (the unique ID of whatever it should play) to look up which file to use.
You can't use $_GET["id"] directly as you are doing now.