Jump to content

Code returns data from 5 tables instead 1?


scepanmali

Recommended Posts

Why this code returns data from all 5 tables? It suppose to return only one result from id.

What I have to do to resolve this problem? Please, someone, HELP

 

 

$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'];


$tables = array("oblast_metal","oblast_rock","oblast_pop","oblast_hip_hop","oblast_domaca");

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>";
}
} 
php?>

Link to comment
Share on other sites

I have to explain some more! When I execute the query for just one row in this five tables it return rows from all five tables. I have metal, rock... tables and when I want to pull data from, let say, metal(by 'id'), it returns data not from just that table, but all tables for the requested "id" number. I just need to pull data from the clicked id row of the particular table, not the rest of them!

 

Thank you in advance!

Link to comment
Share on other sites

No, it is still the same. :-[

I don't know what to do. I just can't find the mistake.

 

-- The first mistake is in your data structure, why do you have different tables for different genres of music?

 

-- If you don't fix that, then you have to have some way to determine which table that particular song is in before you display it. I am assuming that your id is the auto increment id for that table, so all 5 tables are going to have an id #1, all 5 will have a #2, all 5 will have #3, so you are going to get 5 results every time.

 

 

Link to comment
Share on other sites

Yes, I done it, but the problem is I have 5 different tables so I can't do that(or I don't know how)!

If it is only one table, it won't be a problem!

 

If you are sending Artist, Song, and id from the page before this one, where does that information come from?

 

Yes, I agree that it wouldn't be a problem if it was all in one table.

Link to comment
Share on other sites

make 1 new table then make a function that says

<?php
$tables = array("oblast_metal","oblast_rock","oblast_pop","oblast_hip_hop","oblast_domaca");
foreach($tables as $table){
$q = "Select * from `".$table."`";
$r = mysql_query($q) or die(mysql_error())."<br />".$q);
while($row = mysql_fetch_assoc($r)){
$q = "Insert into `NEW_TABLE` FIELDS VALUES($ROW STUFF)
$r2 = mysql_query($q) or die(mysql_error()."<br /><br />".$q);
}
}
?>

and its all in 1 table now and u are happy

Link to comment
Share on other sites

I tried to use LIMIT 1 function for the code, but it's not working! It continues to echo results from all 5 tables.

Can someone tell me why, or help me out to get it work?

 

Thank you all for the help :D

 

 $sql = mysql_query("SELECT * FROM ".$table." WHERE ID = '$id' LIMIT 1"); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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