Noctagon Posted October 13, 2006 Share Posted October 13, 2006 Hi all, I must be still missing something, when I run this code I end up with 'array'I thought the while fixes this.Total noob so go easy on me ;)Thanks in advance for your helpBTW, My aim is to sum the values in the votes column of table vote_table where the user_id value =1Then if the value is within a certain value range then run the appropriate if line.[code] $query = 'SELECT votes FROM vote_table where user_id="1"'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); while ($tvotes = mysql_fetch_array($result)) { if ($tvotes['vote_table'] < 1000) { $votecolour = '<b><font color=black>Black</font></b>'; } else { if ($tvotes['vote_table'] < 5000 and $tvotes['vote_table'] >= 1000) { $votecolour = '<b><font color=blue>Blue</font></b>'; } else { $votecolour = '<b><font color=red>Red</font></b>';[/code] Link to comment https://forums.phpfreaks.com/topic/23822-array-problemi-thinkthough-its-probably-just-me/ Share on other sites More sharing options...
hostfreak Posted October 13, 2006 Share Posted October 13, 2006 Give this a try:[code]$query = 'SELECT votes FROM vote_table where user_id="1"';$result = mysql_query($query) or die('Query failed: ' . mysql_error());while ($tvotes = mysql_fetch_array($result)) { $votes = $tvotes['votes']; if ($votes < 1000) { $votecolour = '<b><font color=black>Black</font></b>'; } else if (($votes < 5000) && ($votes >= 1000)) { $votecolour = '<b><font color=blue>Blue</font></b>'; } else { $votecolour = '<b><font color=red>Red</font></b>'; }}[/code] Link to comment https://forums.phpfreaks.com/topic/23822-array-problemi-thinkthough-its-probably-just-me/#findComment-108195 Share on other sites More sharing options...
Noctagon Posted October 13, 2006 Author Share Posted October 13, 2006 That looks like the same code to me :)I actually omited something any way...this is the code I was using: [code]$query = 'SELECT SUM(votes) FROM vote_table where user_id="1"'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); while ($tvotes = mysql_fetch_array($result)) { if ($tvotes['vote_table'] < 1000) { $votecolour = '<b><font color=black>Black</font></b>'; } else { if ($tvotes['vote_table'] < 5000 and $tvotes['vote_table'] >= 1000) { $votecolour = '<b><font color=blue>Blue</font></b>'; } else { $votecolour = '<b><font color=red>Red</font></b>';[/code] Link to comment https://forums.phpfreaks.com/topic/23822-array-problemi-thinkthough-its-probably-just-me/#findComment-108197 Share on other sites More sharing options...
hostfreak Posted October 13, 2006 Share Posted October 13, 2006 Why are you fetching "vote_table"? That is the table that holds the field "votes", which contains the votes correct? If so, you need:[code]$tvotes['votes'][/code]Try:[code]$query = "SELECT SUM(votes) AS vote_count FROM vote_table WHERE user_id='1'";$result = mysql_query($query) or die('Query failed: ' . mysql_error());while ($tvotes = mysql_fetch_array($result)) { $vote_count = $tvotes['vote_count']; if ($vote_count < 1000) { $votecolour = '<b><font color=black>Black</font></b>'; } else if (($vote_count < 5000) && ($vote_count >= 1000)) { $votecolour = '<b><font color=blue>Blue</font></b>'; } else { $votecolour = '<b><font color=red>Red</font></b>'; }}[/code] Link to comment https://forums.phpfreaks.com/topic/23822-array-problemi-thinkthough-its-probably-just-me/#findComment-108198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.