Forum Moderators: coopster
<?php
// Database Connection
$username = "root";
$password = "root";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
echo "<br>";
$selected = mysql_select_db("spotovi1", $dbhandle) or die("Could not select DB");
$row['Artist']=$Artist;
$row['Song']=$Song;
$id= $row['id'];
$row['id']= $id;
$id = $_GET['id'];
$Artist = $_GET['Artist'];
$Song = $_GET['Song'];
$sql = mysql_query("SELECT * FROM oblast_metal WHERE ID = '$id'");
while ($row = mysql_fetch_array($sql)) { ?>
<?php $zajedno=$row['Artist']."- ".$row['Song'];
echo "<font size=3><font color=white><b>Download </b></a> </font></font>";
echo "<font size=4><font color='#A49F8B'><a href=\"{$row['Link']}\"><font color='#A49F8B'>$zajedno</font></font></a>";
echo "<font size=3><font color=white><b> Music Video</b> </a> </font></font>";
}
php?>
$tables = array("metal","rock","dance","chill");
foreach($tables as $table){
$sql = mysql_query("SELECT * FROM ".$table." WHERE ID = '$id'");
while ($row = mysql_fetch_array($sql)) { ?>
<?php
$zajedno=$row['Artist']."- ".$row['Song'];
echo "<font size=3><font color=white><b>Download </b></a> </font></font>";
echo "<font size=4><font color='#A49F8B'><a href=\"{$row['Link']}\"><font color='#A49F8B'>$zajedno</font></font></a>";
echo "<font size=3><font color=white><b> Music Video</b> </a> </font></font>";
}
}
Ally
What exactly are the results you are looking for then?
$sql = mysql_query("SELECT * FROM ".$table." WHERE ID = '$id' LIMIT 1");
$sql = mysql_query("SELECT * FROM `".mysql_real_escape_string($_GET['table'])."` WHERE ID = '".mysql_real_escape_string($id)."'");
I wouldn't use the GET variable directly in the query without checking to make sure the table actually exists first, however, this is just an example of how it could be done accordingly to what you are looking for.
$selected = mysql_select_db("spotovi1", $dbhandle) or die("Could not select DB");
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 20;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM oblast_metal ORDER BY id DESC LIMIT $from, $max_results");
$id= $row['id'];
$row['id']=$id;
$row['Artist']=$Artist;
$row['Song']=$Song;
while ($row = mysql_fetch_array($sql)) { ?>
<table border="0" bordercolor=#A49F8B align = "center"
cellspacing="0" cellpadding= 3 width= 500 >
<tr onMouseOver="this.bgColor='#355466';" onMouseOut="this.bgColor='#2c4453';">
<td width= "170" ><font color="white" font size=3><font face="Arial, Helvetica, sans-serif"><? echo
$row['Artist']; ?></font></td>
<td width= "200"><font color="white"><font face="Arial, Helvetica, sans-serif"><? echo
$row['Song']; ?></font></td>
<td width= "50"><font face="Arial, Helvetica, sans-serif"><a href="<?php echo "download.php?id=".$row['id'].">".$row['Artist']."- ". $row['Song'] . "";?>" target="_blank" style="text-decoration:none"><b><font color=#A49F8B>Download</b></a></a></font></td>
</tr>
<?php
echo "</table>";
}
echo "</br></br></br></br>";
echo "</center>";
echo "<center><font color=#C8C9CA><font size = 4>Select a Page<br />";
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM oblast_metal"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
// Build Previous Link
if ($page > 1) {
$prev = ($page - 1);
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=$prev\"><font color=#C8C9CA> <b><font size = 3><< Previous</a> ";
}
for ($i = 1; $i <= $total_pages; $i++) {
if (($page) == $i) {
echo "<b><font size = 3><font color = #C8C9CA>$i ";
} else {
echo "<b><font color=#C8C9CA><a href=\"" . $_SERVER['PHP_SELF'] . "?page=$i\"><style=text-decoration:none><b><font color=#C8C9CA><font size = 3>[ $i ]</a> ";
}
}
// Build Next Link
if ($page < $total_pages) {
$next = ($page + 1);
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=$next\"><font color=#C8C9CA><font size = 3> Next >></a>";
}
?>
And the code from my second page is on this page!
Thank you all in advance and for helping me with this. Thank You :)
You need to get a table variable from somewhere; for your case, I assume it's either going to come from a form on the page or you are going to grab it from a uri query. So for the latter case, it would look something like this before your queries:
$table = $_GET['table'];
# here is where you would do necessary checks to see if
# the table is a valid table name.
Then, you have to change your queries to have a variable table name. So, using your queries, it would be something like this:
$sql = mysql_query("SELECT * FROM `".$table."` ORDER BY id DESC LIMIT $from, $max_results");
And...:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM `".$table."`"),0);
Try making those replacements and see what you can get. You have to try to implement a little of this yourself; if you don't, you will not be learning anything for future application. :)