Jump to content

sorting a mysql query on click


IJMcG

Recommended Posts

okay so for my final project for my php class we have to build a video management system. I've got video upload, viewing, and user registration working, and the videos display themselves in my playlist using this code posted below. What I want to do is add a hyperlink above the code that when clicked by the user can sort the videos by a column in my mysql database and then display them in the format shown below (sort by views, or data posted, or alphabetically by title)

 

                <div id="videoList">
             
            		<?php
            		
            		require_once('config.php');
            		
				$con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
				if (!$con)
					{
					die('Could not connect: ' . mysql_error());
					}

				mysql_select_db(DB_DATABASE, $con);

				$result = mysql_query("SELECT * FROM video_list");

				while($row = mysql_fetch_array($result))
					{
					echo "<div title=\"<b>title: </b>" . $row['title'] . "<br />";
					echo "<b>user: </b>" . $row['username'] . "\">";
					echo "<p title=\"description\"><span class=\""title\">" . $row['title'] . "</span><br/>";
					echo "<br/>" . $row['info'] . "<br/>";
					echo "<br/><a href=\"users/" . $row['username'] . "\" target=\""_blank\">visit my page</a></p>";
					echo "<ul title=\"preview\"><li title=\"video/preview/" . $row['ogv_preview'] . "\">video/ogg</li>";
					echo "<li title=\"video/preview/" . $row['mp4_preview'] . "\">video/mp4</li></ul>";
					echo "<ul title=\"main\"><li title=\"video/main/" . $row['ogv_filename'] . "\">video/ogg</li>";
					echo "<li title=\"main/preview/" . $row['mp4_filename'] . "\">video/mp4</li></ul>";
					echo "<ul title=\"thumb\"><li title=\"video/thumb/" . $row['thumb'] . "\"></li></ul>";
					echo "<ul title=\"poster\"><li title=\"video/poster/" . $row['poster'] . "\"></li></ul></div>";
					}

				mysql_close($con);
				?>       
                     
                 </div>

 

this generates a piece of html code that looks like this. 1 block of code for each video in the mysql database. i just need to be able to sort this code, can anyone help me out??

 

THANKS!

 

<div title="<b>title: </b>funny video<br />
<b>user: ijmcg</b>">
<p title="description">
<span class=""title">funny video</span><br/><br/>blah blah blah blah<br/><br/>
<a href="users/ijmcg" target=""_blank">visit my page</a>
</p><ul title="preview">
<li title="video/preview/01.ogv">video/ogg</li>
<li title="video/preview/01.mp4">video/mp4</li></ul>
<ul title="main"><li title="video/main/01.ogv">video/ogg</li>
<li title="main/preview/01.mp4">video/mp4</li></ul>
<ul title="thumb"><li title="video/thumb/01.jpg"></li></ul>
<ul title="poster"><li title="video/poster/01.jpg"></li></ul>
</div>

Link to comment
https://forums.phpfreaks.com/topic/252969-sorting-a-mysql-query-on-click/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.