corillo181 Posted December 29, 2006 Share Posted December 29, 2006 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] Quote Link to comment Share on other sites More sharing options...
dbo Posted December 29, 2006 Share Posted December 29, 2006 SELECT artist_id FROM tr_music_top10 ORDER BY counter DESC Quote Link to comment Share on other sites More sharing options...
corillo181 Posted December 29, 2006 Author Share Posted December 29, 2006 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] Quote Link to comment Share on other sites More sharing options...
dbo Posted December 29, 2006 Share Posted December 29, 2006 $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";} Quote Link to comment Share on other sites More sharing options...
corillo181 Posted December 29, 2006 Author Share Posted December 29, 2006 forget it it worked i just wasn't using the first query you gave me everything works fine. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted December 29, 2006 Author Share Posted December 29, 2006 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 Quote Link to comment Share on other sites More sharing options...
dbo Posted December 29, 2006 Share Posted December 29, 2006 You want to update all counters? On only specific counters? If so which ones do you want to update?Let's talk through it high level in normal terms and get an understanding for what we want to accomplish. After that we'll write the code that does it for us. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted December 29, 2006 Share Posted December 29, 2006 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? Quote Link to comment Share on other sites More sharing options...
corillo181 Posted December 29, 2006 Author Share Posted December 29, 2006 alright,when i insert a new artist i give this artist a counter of 0.so in the query i bring out that 0and 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. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted December 29, 2006 Author Share Posted December 29, 2006 yes $a_t_id=$artist['artist_id'];this si coming from a while statement wich search for everything that is in the artist table.. i know the query is working because everythign about the person is been echo out properly. Quote Link to comment Share on other sites More sharing options...
dbo Posted December 29, 2006 Share Posted December 29, 2006 echo the value in $a_t_id before the update command and use Paul's method for incrementing the counter. Let me know what that gets you and we'll move forward. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted December 29, 2006 Author Share Posted December 29, 2006 thanx for the help, but i just separaded the code into another page and linked the voting so it worked perfect.. i don't know why it didn't want to work with $_server['php_self'] Quote Link to comment Share on other sites More sharing options...
paul2463 Posted December 29, 2006 Share Posted December 29, 2006 [code]$_SERVER[’PHP_SELF’][/code]not small letters could have been your problem Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.