Member Avatar for Borderline

Good evening

I'm looking for yet more assistance, and hope someone is able to point me in the right direction.

I'm trying to produce a format for our tipping competition, whereby people who fail to complete their entries are shown a) without a result in the profit column, and b) are highlighted with a grey background. I have attempted to write the code, but it's not producing the right effect:

                <?php

                $query = "  SELECT SUM(comptipsterselections.profit) as Profit, comptipsterselections.stable, comptipsterboard.link
                            FROM comptipsterselections INNER JOIN comptipsterboard
                            ON comptipsterselections.stable=comptipsterboard.stable 
                            AND comptipsterselections.comp=comptipsterboard.comp 
                            WHERE comptipsterselections.comp = 'aintree 2011'
                            GROUP BY comptipsterselections.stable, comptipsterboard.link
                            ORDER BY SUM(comptipsterselections.profit) DESC";


                $result = mysql_query($query) or die(mysql_error());

                // Set-up table

                            echo "<table class='english' border='1' cellpadding='4' cellspacing='0' width='75%'>";
                            echo "<tr class='toprow'> <th>Stable</th> <th>Daily Profit</th></tr>";


                // Print out result
                            while($row = mysql_fetch_array($result)){

                            $link='/site/competitions/tipster'.$row[link];

                            if ($row[completed] == 'no') {

                            echo "<tr><td bgcolor='#C0C0C0'>";
                            echo "<a href='$link'>";
                            echo $row[stable];
                            echo "</td><td bgcolor='#C0C0C0'>";
                            echo "";
                            echo "</td></tr>";
                            }
                            else
                            {
                            echo "<tr><td>";
                            echo "<a href='$link'>";
                            echo $row[stable];
                            echo "</td><td>";
                            echo " £". $row[Profit];
            }

            echo "</td></tr>"; 
            } 
            echo "</table>";?>

Any assistance in getting the right effect would be very much appreciated.

Member Avatar for diafol

Do not write inline outdated inline styles. Just use css and apply a class attribute to the relevant entry.

Member Avatar for Borderline

Is this likely to fix the error, or additional advice on the subject?

Member Avatar for diafol

I don't know about fixing the error, but part of your query seemed to be with regard to formatting output. That was my 2p (additional advice, if you want).

But delving into your php:

if ($row[completed] == 'no') {

where is the 'completed' field in the SQL? Can't see it.

Member Avatar for Borderline

Great, thanks! That did the job. If this is of any use, the updated code looks like this:

                $query = "  SELECT SUM(comptipsterselections.profit) as Profit, comptipsterselections.stable, comptipsterboard.link,    
                            comptipsterboard.completed
                            FROM comptipsterselections INNER JOIN comptipsterboard
                            ON comptipsterselections.stable=comptipsterboard.stable 
                            AND comptipsterselections.comp=comptipsterboard.comp 
                            WHERE comptipsterselections.comp = 'aintree 2011'
                            GROUP BY comptipsterselections.stable, comptipsterboard.link
                            ORDER BY SUM(comptipsterselections.profit) DESC";


                $result = mysql_query($query) or die(mysql_error());
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.