Options for displaying DB data
Posted: Fri Aug 16, 2013 3:57 pm
I'm a relative noob when it comes to programming. No educational background but I've been playing with HTML, CSS for about a year now and recently made the jump to PHP a couple months ago. I have some code that I wrote that displays data from a database I created. The code displays the data wonderfully as it is written but I'd like to learn how to give the user options on filtering the data. The DB contains several movie names, images of movie covers and links to the individual movies page at IMDB.com. The code that i've written displays the data in a table that is 4 entries wide and runs until there are no more DB entries. The DB's primary key is "movie_id" and I am using it to sort the display. It worked fine in the beginning b/c movie_id matched up w/an alphabetical list of movie_name. When I added more movie names to the DB the list is no longer alphabetical. If I try to sort by movie_name the display is no longer symetrical. What can I do to have a symetrical display (i.e. 4 entries/row) and sort by "movie_name?" Here is the code:
(there is html above and below the above code to open and close table tags. i just didn't want to fill up the page with html)
If anyone has suggestions or resources for me to read please reply. I don't mind, and actually enjoy, figuring out problems on my own but this one has me stumped.
Thanks in advance for all of your help.
fletch
Code: Select all
<?php
$link = mysqli_connect("localhost","xxxx","xxxxx","xxxxx_movies");
if (mysqli_connect_errno()) {
printf("Connect failed %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT * FROM Sheet1 ORDER BY movie_id";
$result = mysqli_query($link, $query);
while($row = mysqli_fetch_row($result)) {
if ($row[0] === 0) {continue;}
elseif ($row[0] % 4 != 0) {
echo("
<td align=\"center\">
<a href=\"$row[2]\">$row[1]<p><img src=\"movieCovers/$row[3]\" height=200 width = 150>
</td>");
}
else {
echo ("
<td align=\"center\">
<a href=\"$row[2]\">$row[1]<p><img src=\"movieCovers/$row[3]\" height=200 width = 150>
</td>
</tr>
<tr>");
}
}
?>
If anyone has suggestions or resources for me to read please reply. I don't mind, and actually enjoy, figuring out problems on my own but this one has me stumped.
Thanks in advance for all of your help.
fletch