MySQL Forums
Forum List  »  PHP

Sort By Series - Multiple Tables
Posted by: Kim Yi-Na
Date: August 24, 2005 08:07PM

Is it possible to put multiple tables together while targeting a specific row and number of rows? For example I had tables called layouts, wallpapers, avatars, and png. I want to prevent the same series, from different tables, from duplicating. I want the outcome to display like this:

+-----+---------+-----------+--------+----+
Series | Layouts | Wallpapers | Avatars | PNG
+-----+---------+-----------+--------+----+
Ex1; | 12 | 4 | 17 | 3
Ex2 | 25 | 9 | 13 | 5
Ex3 | 7 | 2 | 6 | 2
...
...
...
...and so on...
+-----+---------+-----------+--------+----+

Here's my code. Only partial parts of it, but this is the most important part of the code since the rest are already working properly in the if/elseif statement.

==================================

<?php
include ('mysql.php');
$table = 'layouts';
$limit = '40';
$scroll = '5';
$query1 = mysql_query ("SELECT DISTINCT series FROM $table order by 'series' ASC");
$numrows = mysql_num_rows ($query1);
if (!isset ($_GET[screen])) {
$display = 1;
} else {
$display = $_GET[screen];
}
$start = (($display * $limit) - $limit);
$query2 = mysql_query ("SELECT DISTINCT series FROM $table order by 'series' ASC LIMIT $start,$limit");
$result = mysql_db_query($dbase, $query2);

echo "<p class=\"top\">$x Series - $numrows Total</p>
<center>
<table border=\"0\" align=\"center\">
<tr>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\" colspan=\"2\"><b><a href=\"$PHP_SELF?mode=$mode\">All</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=A\">A</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=B\">B</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=C\">C</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=D\">D</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=E\">E</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=F\">F</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=G\">G</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=H\">H</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=I\">I</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=J\">J</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=K\">K</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=L\">L</a></b></td>
</tr>
<tr>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=M\">M</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=N\">N</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=O\">O</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=P\">P</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=Q\">Q</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=R\">R</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=S\">S</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=T\">T</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=U\">U</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=V\">V</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=W\">W</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=X\">X</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=Y\">Y</a></b></td>
<td class=\"highlight\" align=\"center\" style=\"padding:3px;\"><b><a href=\"$PHP_SELF?mode=$mode&x=Z\">Z</a></b></td></tr>
</table>
<br>


<table width=\"100%\" border=\"0\" cellspacing=\"2\" align=\"center\">
<tr>
<td class=\"above\">Series</td><td class=\"above\">Total</td><td class=\"above\">Series</td><td class=\"above\">Total</td>";

while ($row = mysql_fetch_array($query2)) {
$id=$row["id"];
$title=$row["title"];
$artist=$row["artist"];
$type=$row["type"];
$date=$row["date"];
$series=$row["series"];
$size=$row["size"];
$preview=$row["preview"];
$download=$row["download"];
$image=$row["image"];
$counter=$row["counter"];
$counter2=$row["counter2"];

$tbls = mysql_query("select * from $table where series='$series'");

$numrows = mysql_num_rows($tbls);

$printout = "$series";
$printout2 = "[ <a href=\"$PHP_SELF?x=$series\">$numrows</a> ]";

if ($r==0) // first row)
{
echo '<tr><td class=highlight style=padding:2px;>'.$printout.'</td><td class=highlight align=center style=padding:2px;>'.$printout2.'</td>';

} #end of 1st row
else if ($r==3)
{
echo '<td class=highlight style=padding:2px;>'.$printout.'</td><td class=highlight align=center style=padding:2px;>'.$printout2.'</td></tr>';
}
else
echo '<td class=highlight style=padding:2px;>'.$printout.'</td><td class=highlight align=center style=padding:2px;>'.$printout2.'</td>';

$r++; $r=$r%2;

} #end of while loop

echo '</table>'; // close table

$paging = ceil ($numrows / $limit);
echo "<center>
<table border=\"0\" style=\"padding:2px;\"><tr>";
if ($display > 1) {
$previous = $display - 1;
echo "<td class=\"highlight\" id=\"navhover\"><a href=\"$PHP_SELF?mode=$mode&x=$x&screen=$previous\">&nbsp;&laquo; <b>Previous</b>&nbsp;</a></b>&nbsp;</td>";
}
if ($numrows != $limit) {
if ($paging > $scroll) {
$first = $_GET[screen];
$last = ($scroll - 1) + $_GET[screen];
} else {
$first = 1;
$last = $paging;
}
if ($last > $paging ) {
$first = $paging - ($scroll - 1);
$last = $paging;
}
for ($i = $first;$i <= $last;$i++){
if ($display == $i) {
echo " <td class=\"highlight\">&nbsp;<b>$i</b>&nbsp;</td> ";
} else {
echo " <td class=\"highlight\" id=\"navhover\"><a href=\"$PHP_SELF?mode=$mode&x=$x&screen=$i\">&nbsp;<b>$i</b>&nbsp;</a></td> ";
}
}
}
if ($display < $paging) {
$next = $display + 1;
echo "<td class=\"highlight\" id=\"navhover\"><a href=\"$PHP_SELF?mode=$mode&x=$x&screen=$next\">&nbsp;<b>Next</b> &raquo;&nbsp;</a></td>";
}
echo "</tr>
</table>
</center>";

include ('bottom.txt');
?>

==========================================
The code above (the table called layouts) displays something like this:

+-----------------+------------------------+
Series | Total
+-----------------+------------------------+
Ex1 | 12
Ex2 | 25
Ex3 | 7
...
...
...
...and so on...
+-----------------+------------------------+


However, I want the format displayed from above. I don't know how else I could explain my question despite I'm only 16 =D Help would be greatly appreciated! If not, then that's okay....

Options: ReplyQuote


Subject
Written By
Posted
Sort By Series - Multiple Tables
August 24, 2005 08:07PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.