Jump to content

query question


corillo181

Recommended Posts

i'm trying to arrange a counter by the person id, i want who ever counter is greater to be on top first..and from there on the rest..

i did something like this but it doesn't seen to be workin.


[code]<?php
$sel=mysql_query("SELECT artist_id FROM tra_music_top10 WHERE counter>counter")or die(mysql_error());
while($ar=mysql_fetch_array($sel)){
echo $ar['artist_id'];
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/32192-query-question/
Share on other sites

that worked fine but i tried getting the artist name with the id and i think i'm doing something wrong

[code]
$i1=1;
$sel=mysql_query("SELECT artist_id FROM tra_music_top10 WHERE counter>counter")or die(mysql_error());
while($ar=mysql_fetch_array($sel)){
$slna=mysql_query("SELECT name FROM tra_music_artist WHERE artist_id=".$ar['artist_id']);
while($rname=mysql_fetch_array($slna)){

  ?>
        <tr>
          <td><?=$i1?></td>
          <td><?=$rname['name']?></td>
        </tr>
        <tr>
<?php
$i1++;
}
}
        ?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/32192-query-question/#findComment-149427
Share on other sites

$query = "SELECT artist_id, artist_name FROM tra_music_top10 ORDER BY counter DESC";
$result = mysql_query($query);
$len = mysql_num_rows($result);

for( $i = 0; $i < $len; ++$i )
{
  $row = mysql_fetch_row($result);
  $artist_id = $row[0];
  $artist_name = $row[1];
 
  echo "<tr>\n";
    echo "<td>ArtistID: $artist_id</td>\n";
    echo "<td>ArtistName: $artist_name</td>\n";
  echo "</tr>\n";
}
Link to comment
https://forums.phpfreaks.com/topic/32192-query-question/#findComment-149433
Share on other sites

what i'm having problem right now is with this code is a mess.. it update every counter in the table..

[code] <?php
$a_t_id=$artist['artist_id'];

$getcounter=mysql_query("SELECT counter FROM tra_music_top10 WHERE artist_id='$a_t_id'")or die(mysql_error());

$count=mysql_fetch_array($getcounter);

$i=$count['counter'];
echo $i;

if($_GET['vote']){
$voted=($i+1);

$update=mysql_query("UPDATE tra_music_top10 SET counter='$voted' WHERE artist_id='$a_t_id'")or die(mysql_error());

}

?>
[/code]

thanx for the help dbo
Link to comment
https://forums.phpfreaks.com/topic/32192-query-question/#findComment-149441
Share on other sites

another way to do all that code would bew to do something like this
[code]
<?php
$a_t_id=$artist['artist_id'];
if($_GET['vote']){
mysql_query("UPDATE tra_music_top10 SET counter=(counter+1) WHERE artist_id='$a_t_id'")or die(mysql_error());
}
?>
[/code]
as to why it is updating all the entries in the table, is the $a_t_id=$artist['artist_id']; being set correctly?

Link to comment
https://forums.phpfreaks.com/topic/32192-query-question/#findComment-149446
Share on other sites

alright,

when i insert a new artist i give this artist a counter of 0.

so in the query i bring out that 0

and when someone vote for this artist the counter goes from 0 to 1 and every time someone vote for this artist the counter keeps adding up..
right now what i have working is inserting the artist and the 0 value..

after that i got the value querying out..

where my code is going wrong is when someone votes and the counter has to update to add up with whatever is already in the counter..

the problem i'm having is that every counter of every artist is adding up instaed of just the one select.
Link to comment
https://forums.phpfreaks.com/topic/32192-query-question/#findComment-149447
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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