morgann7 Posted April 21, 2009 Share Posted April 21, 2009 Hi, I'm working on a site that allows a user add and retrive youtube embedded video links. The site is connected to a mysql database. The database table has 6 fields. Video: Contains youtube link, and 5 tag fields: search keywords to retrieve the videos. (All of this is working fine). What I'm having trouble with: I want to be able to sort the search results either horizontally or vertically (radio button option), I'm thinking of a counter here to print out the videos per row or column but can't work this out, the code needs to be generic in order to accomodate many videos. Also I want to be able to sort the results per page (drop down list 2, 4, 6). Below is a copy of my code so far. Anyhelp would be greatly appreciated, also I hope this is easily understood! Thanks, Morgan <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>|Video Jockey Management Site - Homepage|</title> <link rel="stylesheet" type="text/css" href="vj.css" /> </head> <body> <div class="layer1"> <form method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>"> <p>Search: <input class="textbox" type="text" name="tags" size="20" value="<?php echo($_POST['tags']); ?>" /> <p>Layout: <input value="horizontal" type="radio" name="direction" checked="checked">Horizontal</p> <p>            <input value="vertical" type="radio" name="direction">Vertical</p> <p>Results per page: <select name="mydropdown"> <option value="2">2</option> <option value="4">4</option> <option value="6">6</option> </select> </p> <input class="red" type="submit" name="showresult" value="Search"/></p> </form> <hr> <p>Please click here to add a video link:</p> <form method="post" action="insert.php"> <p><input class="red" type="submit" name="insert" value="Insert"/></p> </form> </div> <div class="layer2"> <span class="headertext">Video Manager</span>© <div> <div class="layer3"> <?php if (isset($_POST['showresult']) OR isset($_POST['delete'])) { // set database server access variables: $host = "localhost"; $user = "root"; $pass = "root"; $db = "test"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); //check for delete if (isset($_POST['delete'])) { $delete_query = "DELETE FROM videos WHERE video = '".$_POST['video']."'"; mysql_query($delete_query) or die ("Error in query: $delete_query. ".mysql_error()); echo($_POST['video']." was deleted from the database"); } // create query $tokenNo = 0; $token = strtok($_POST['tags'], ' ,'); while ($token != false) { $tags[$tokenNo] = $token; $tokenNo++; $token = strtok(' ,'); } if ($tokenNo > 0) { $condition = "(tag1 = '$tags[0]') OR (tag2 = '$tags[0]') OR (tag3 = '$tags[0]') OR (tag4 = '$tags[0]') OR (tag5 = '$tags[0]')"; for($i=1; $i<sizeof($tags); $i++) { $condition .= " OR (tag1 = '$tags[$i]') OR (tag2 = '$tags[$i]') OR (tag3 = '$tags[$i]') OR (tag4 = '$tags[$i]') OR (tag5 = '$tags[$i]')"; } $query = "SELECT * FROM videos WHERE $condition"; } else { $query = "SELECT * FROM videos"; } // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another echo('<table class="query_result">'); while($row = mysql_fetch_row($result)) { echo('<tr>'); echo('<td><embed src="'.$row[0].'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="325" height="244"></embed><p>'.$row[0].'</p></td>'); echo('<td><p>'.$row[1].', '.$row[2].', '.$row[3].', '.$row[4].', '.$row[5].'</p>'); ?> <form method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>"> <p><input type="hidden" name="tags" value="<?php echo($_POST['tags']); ?>" /> <input type="hidden" name="video" value="<?php echo($row[0]); ?>" /> <input class="red" type="submit" name="delete" value="Delete" /></p> </form> </div> <?php echo('</td>'); echo('</tr>'); } echo('</table>'); } else { // no // print status message echo('No rows found!'); } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/155024-php-mysql-video-alignment-issue/ Share on other sites More sharing options...
morgann7 Posted April 22, 2009 Author Share Posted April 22, 2009 OK, I added a counter below in the code to get the videos to align properly, my only problem now is to limit each search to a drop down value per page and then a link to the next page of results. I'm looking at doing a Pagination type thing. Can anyone see how I might add this feature. Thanks, <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>|Video Jockey Management Site - Homepage|</title> <link rel="stylesheet" type="text/css" href="vj.css" /> </head> <body> <div class="layer1"> <form method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>"> <p>Search: <input class="textbox" type="text" name="tags" size="20" value="<?php echo($_POST['tags']); ?>" /> <p>Layout: <input value="vertical" type="radio" name="direction" <?php if ($_POST['direction'] == 'vertical') { echo('checked="checked"'); } else echo('checked="checked"'); ?> >Vertical</p> <p>            <input value="horizontal" type="radio" name="direction" <?php if ($_POST['direction'] == 'horizontal') { echo('checked="checked"'); } ?> >Horizontal </p> <p>Results per page: <select name="mydropdown"> <option value="2">2</option> <option value="4">4</option> <option value="6">6</option> </select> </p> <input class="red" type="submit" name="showresult" value="Search"/></p> </form> <hr> <p>Please click here to add a video link:</p> <form method="post" action="insert.php"> <p><input class="red" type="submit" name="insert" value="Insert"/></p> </form> </div> <div class="layer2"> <span class="headertext">Video Manager</span>© </div> <div class="layer3"> <?php if (isset($_POST['showresult']) OR isset($_POST['delete'])) { // set database server access variables: $host = "localhost"; $user = "root"; $pass = "root"; $db = "test"; $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db) or die ("Unable to select database!"); //check for delete if (isset($_POST['delete'])) { $delete_query = "DELETE FROM videos WHERE video = '".$_POST['video']."'"; mysql_query($delete_query) or die ("Error in query: $delete_query. ".mysql_error()); echo($_POST['video']." was deleted from the database"); } // create query $tokenNo = 0; $token = strtok($_POST['tags'], ' ,'); while ($token != false) { $tags[$tokenNo] = $token; $tokenNo++; $token = strtok(' ,'); } if ($tokenNo > 0) { $condition = "(tag1 = '$tags[0]') OR (tag2 = '$tags[0]') OR (tag3 = '$tags[0]') OR (tag4 = '$tags[0]') OR (tag5 = '$tags[0]')"; for($i=1; $i<sizeof($tags); $i++) { $condition .= " OR (tag1 = '$tags[$i]') OR (tag2 = '$tags[$i]') OR (tag3 = '$tags[$i]') OR (tag4 = '$tags[$i]') OR (tag5 = '$tags[$i]')"; } $query = "SELECT * FROM videos WHERE $condition"; } else { $query = "SELECT * FROM videos"; } // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned //if (mysql_num_rows($result) > 0) { // yes // print them one after another $no = mysql_num_rows($result); if(isset ($_POST['direction'])) { echo('<table class="query_result">'); if ($_POST['direction'] == 'horizontal') { $rows = 1; $columns = $no; } if ($_POST['direction'] == 'vertical') { $rows = $no; $columns = 1; } } //while($row = mysql_fetch_row($result)) for rows // Counter for rows for($r=1; $r<=$rows; $r++) { echo('<tr>'); // Counter for cols for($c=1; $c<=$columns; $c++) { $row = mysql_fetch_row($result); echo('<td><embed src="'.$row[0].'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="325" height="244"></embed></td>'); echo('<td><p>'.$row[1].', '.$row[2].', '.$row[3].', '.$row[4].', '.$row[5].'</p>'); ?> <form method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>"> <p><input type="hidden" name="tags" value="<?php echo($_POST['tags']); ?>" /> <input type="hidden" name="video" value="<?php echo($row[0]); ?>" /> <input class="red" type="submit" name="delete" value="Delete" /></p> </form> </div> <?php echo('</td>'); } echo('</tr>'); } echo('</table>'); // free result set memory mysql_free_result($result); // close connection mysql_close($connection); } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/155024-php-mysql-video-alignment-issue/#findComment-816946 Share on other sites More sharing options...
Gighalen Posted April 22, 2009 Share Posted April 22, 2009 Are you saying you want to be able to sort search results like google? Either in a row or a column? Link to comment https://forums.phpfreaks.com/topic/155024-php-mysql-video-alignment-issue/#findComment-816950 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.