Jump to content


Photo

array problem....I think...though its probably just me :)


  • Please log in to reply
3 replies to this topic

#1 Noctagon

Noctagon
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 13 October 2006 - 05:49 AM

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 help

BTW, My aim is to sum the values in the votes column of table vote_table where the user_id value =1

Then if the value is within a certain value range then run the appropriate if line.


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


#2 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 13 October 2006 - 06:06 AM

Give this a try:
$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>';
  }
}


#3 Noctagon

Noctagon
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 13 October 2006 - 06:09 AM

That looks like the same code to me :)

I actually omited something any way...this is the code I was using:

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


#4 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 13 October 2006 - 06:12 AM

Why are you fetching "vote_table"? That is the table that holds the field "votes", which contains the votes correct? If so, you need:
$tvotes['votes']

Try:
$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>';
  }
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users