Jump to content

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


Noctagon

Recommended Posts

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.


[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
Share on other sites

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
Share on other sites

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
Share on other sites

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