Jump to content

Returning Null Values


Xtremer360

Recommended Posts

How do I make the most successful defenses and longest reign if they are null return and place in there that "No champion has been crowned". Because I keep getting this error:

 

No champions have been crowned yet!

Warning: rsort() expects parameter 1 to be array, null given in /home/content/y/a/n/yankeefaninkc/html/titlehistory.php on line 86

 

Warning: rsort() expects parameter 1 to be array, null given in /home/content/y/a/n/yankeefaninkc/html/titlehistory.php on line 87

 

 

 

<?php echo "<body bgcolor=\"black\" text=\"white\" link=\"red\" vlink=\"red\">"; ?>

<?php
function dateConvert($date)
{
    $eDat = explode("-",$date);
    $year = $eDat[0];
    $nMon = $eDat[1];
    $day  = $eDat[2];
    switch ($nMon)
    {
        case 1:     $mont = "January"; break;
        case 2:     $mont = "February"; break; 
        case 3:     $mont = "March"; break;
        case 4:     $mont = "April"; break;
        case 5:     $mont = "May"; break;
        case 6:     $mont = "June"; break;
        case 7:     $mont = "July"; break;
        case 8:     $mont = "August"; break;
        case 9:     $mont = "September"; break;
        case 10: $mont = "October"; break;
        case 11: $mont = "November"; break;
        case 12: $mont = "December"; break;    
    } 
    $out = $mont . " " . $day . ", " . $year;
    return $out;
}
?>

<?php
// Connects to your Database
$link = mysql_connect("?", "?", "?") or die(mysql_error());
mysql_select_db("?",$link) or die(mysql_error());

if (isset($_GET['id']))
{    
    // First, we need to get the champs, so do some mysql stuffs.
    $qry0 = "SELECT * FROM `titlechamps` WHERE `title` = '".addslashes($_GET['id'])."';";
    $res0 = mysql_query($qry0) or die('Qry zero error!');
    if(!mysql_num_rows($res0)) echo "No champions have been crowned yet!";
    else
    {
        while($list0 = mysql_fetch_assoc($res0))
        {
            // We have at least one champ.
            // First, we have to do a little math. We need to determine 
            // how many days have elapsed between the date won and today.
            $today = explode("-",date("Y-m-d", time()));
            $yesterday = explode("-",$list0['date']);
            $hi = gregoriantojd($today[1],$today[2],$today[0]);
            $lo = gregoriantojd($yesterday[1],$yesterday[2],$yesterday[0]);
            $days = round($hi - $lo);
            
            // We will add the days and name to an array for the header.
            $longestR[] = $days . " - " . $list0['name'];
            // We also add the most successful defences to another array.
            $sucessfulD[] = $list0['defenses'] . " - " . $list0['name'];
            
            if($list0['news'] != null)
            $body .= "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tbody><tr><td colspan=\"2\" bgcolor=\"#e0e0e0\" valign=\"top\" width=\"100%\"><i>".$list0['news']."</i></td></tr></tbody></table>\n";
            
            $body .= 
            "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tbody>\n".
                "<tr>\n".
                "<td width=\"115\" valign=\"top\" align=\"center\"><img src=\"".$list0['pic']."\" /></td>".
                "<td>".
                "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\"><tbody><tr>".
                    "<td width=\"25\" bgcolor=\"#e0e0e0\" align=\"center\"><b>".$list0['num']."</b></td>".
                    "<td bgcolor=\"#e0e0e0\"><font color=\"#ff0000\">".$list0['name']."</font></td>".
                "</tr></tbody></table>".
                "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\"><tbody>".
                    "<tr><td align=\"center\" bgcolor=\"#e0e0e0\" width=\"50%\"><b>Successful Defenses</b></td><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Event</b></td></tr>".
                    "<tr><td align=\"center\">".$list0['defenses']."</td><td align=\"center\">".$list0['event']."</td></tr>".
                    "<tr><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Reign</b></td><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Date Won</b></td></tr>".
                    "<tr><td align=\"center\">$days</td><td align=\"center\">".dateConvert($list0['date'])."</td></tr>".
                    "<tr><td colspan=\"2\"><i>".$list0['blurb']."</i></td></tr>".
                "</tbody></table>".
                "</td></tr>".
            "</tbody></table>\n";
            
        }
        
    }
    
    // Now, determine the longest reign and most defenses
    rsort($longestR);
    rsort($sucessfulD);


//next, we need to assemble the header of the page.
    $query = "SELECT *, DATE_FORMAT(`datecreated`, '%M %e, %Y') AS datecreated FROM titlehistory WHERE id='".addslashes($_GET['id'])."';";

    if ($r = mysql_query ($query)){ // Run the query. 
        while ($row = mysql_fetch_array ($r)){


            $head .= '<table border=0 cellspacing="0" cellpadding=3 width=575>';
            $head .='<tr><td background="images/bg_bar4.gif" height=35> <font color="white">Title Histories</font></td></tr>';
            $head .='<tr><td></td></tr>';
            $head .='</table>';
            $head .='<table border=0 cellspacing="0" cellpadding=3 width=575>';
            $head .='<tr><td background="images/bg_bar3.gif" height=35 colspan=2> <font color=black>KOW '.$row['titlename'].'</font></td></tr>';
            $head .='<tr><td width=200><img src="/images/' . $row['titleimage'] . '" width=208px height=156px border=0 alt="View KOW '.$row['titlename'].' History"></td><td valign=top>';
            $head .='<table cellpadding="2" cellspacing="0" border="0" width=100%>';
            $head .='<tr><td align=center bgcolor=#E0E0E0><b><font color="#000000">Date Created</font></b></td></tr><tr><td align=center>'.$row['datecreated'].'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Status</font></b></td></tr>';
            $head .='<tr><td align=center>'.$row['status'].'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Longest Reign</font></b></td></tr>';
            $head .='<tr><td align=center>'.$longestR[0].'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Most Successful Defenses</font></b></td></tr>';
            $head .='<tr><td align=center>'.$sucessfulD[0].'</td></tr>';
            $head .='</table>';
        }
    }
}
    else
    {
        print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
        print '<tr><td background="images/bg_bar4.gif" height=35> <font color="white">Title Histories</font></td></tr>';
        print '</table>';
        print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
        print '<tr><td background="images/bg_bar3.gif" height=35 colspan=4> <font color="#000000">Active Titles</font></td></tr>';
        print '<tr>';

        //Define the query
        $query = "SELECT * FROM titles WHERE status = 'Active'"; // Active rows

        if ($r = mysql_query ($query)){ // Run the query. 

            while ($row = mysql_fetch_array ($r)){
    
                print '<td><a href="titlehistory.php?id=' . $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
                print '<img src="/images/' . $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
             }

        } 
        else {
                die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was $query.</p>');
        }//End of query IF 

        print '</tr>';
        print '</table>';
        print '<img src=images/spacer.gif><br>';
        print '<table border=0 cellspacing=0 cellpadding=3 width=575><tr><td background="images/bg_bar3.gif" height=35 colspan=2> <font color="#000000">Inactive Titles</font></td></tr>';
        print '<tr>';

        //Define the query
        $query = "SELECT * FROM titles WHERE status = 'Inactive'"; // Inactive Rows

        if ($r = mysql_query ($query)){ // Run the query. 

            while ($row = mysql_fetch_array ($r)){
    
                print '<td><a href="titlehistory.php?id=' . $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
                print '<img src="/images/' . $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
    
            }

        } 
        else {
            die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was $query.</p>');
        } //End of query IF 
    }
print '</tr>';
print '</table>'; 

?> 

Link to comment
Share on other sites

rsort will return true if it works or false if it does not. So...

 

<?php echo "<body bgcolor=\"black\" text=\"white\" link=\"red\" vlink=\"red\">"; ?>

<?php
function dateConvert($date)
{
    $eDat = explode("-",$date);
    $year = $eDat[0];
    $nMon = $eDat[1];
    $day  = $eDat[2];
    switch ($nMon)
    {
        case 1:     $mont = "January"; break;
        case 2:     $mont = "February"; break; 
        case 3:     $mont = "March"; break;
        case 4:     $mont = "April"; break;
        case 5:     $mont = "May"; break;
        case 6:     $mont = "June"; break;
        case 7:     $mont = "July"; break;
        case 8:     $mont = "August"; break;
        case 9:     $mont = "September"; break;
        case 10: $mont = "October"; break;
        case 11: $mont = "November"; break;
        case 12: $mont = "December"; break;    
    } 
    $out = $mont . " " . $day . ", " . $year;
    return $out;
}
?>

<?php
// Connects to your Database
$link = mysql_connect("?", "?", "?") or die(mysql_error());
mysql_select_db("?",$link) or die(mysql_error());

if (isset($_GET['id']))
{    
    // First, we need to get the champs, so do some mysql stuffs.
    $qry0 = "SELECT * FROM `titlechamps` WHERE `title` = '".addslashes($_GET['id'])."';";
    $res0 = mysql_query($qry0) or die('Qry zero error!');
    if(!mysql_num_rows($res0)) echo "No champions have been crowned yet!";
    else
    {
        while($list0 = mysql_fetch_assoc($res0))
        {
            // We have at least one champ.
            // First, we have to do a little math. We need to determine 
            // how many days have elapsed between the date won and today.
            $today = explode("-",date("Y-m-d", time()));
            $yesterday = explode("-",$list0['date']);
            $hi = gregoriantojd($today[1],$today[2],$today[0]);
            $lo = gregoriantojd($yesterday[1],$yesterday[2],$yesterday[0]);
            $days = round($hi - $lo);
            
            // We will add the days and name to an array for the header.
            $longestR[] = $days . " - " . $list0['name'];
            // We also add the most successful defences to another array.
            $sucessfulD[] = $list0['defenses'] . " - " . $list0['name'];
            
            if($list0['news'] != null)
            $body .= "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tbody><tr><td colspan=\"2\" bgcolor=\"#e0e0e0\" valign=\"top\" width=\"100%\"><i>".$list0['news']."</i></td></tr></tbody></table>\n";
            
            $body .= 
            "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tbody>\n".
                "<tr>\n".
                "<td width=\"115\" valign=\"top\" align=\"center\"><img src=\"".$list0['pic']."\" /></td>".
                "<td>".
                "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\"><tbody><tr>".
                    "<td width=\"25\" bgcolor=\"#e0e0e0\" align=\"center\"><b>".$list0['num']."</b></td>".
                    "<td bgcolor=\"#e0e0e0\"><font color=\"#ff0000\">".$list0['name']."</font></td>".
                "</tr></tbody></table>".
                "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\"><tbody>".
                    "<tr><td align=\"center\" bgcolor=\"#e0e0e0\" width=\"50%\"><b>Successful Defenses</b></td><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Event</b></td></tr>".
                    "<tr><td align=\"center\">".$list0['defenses']."</td><td align=\"center\">".$list0['event']."</td></tr>".
                    "<tr><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Reign</b></td><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Date Won</b></td></tr>".
                    "<tr><td align=\"center\">$days</td><td align=\"center\">".dateConvert($list0['date'])."</td></tr>".
                    "<tr><td colspan=\"2\"><i>".$list0['blurb']."</i></td></tr>".
                "</tbody></table>".
                "</td></tr>".
            "</tbody></table>\n";
            
        }
        
    }
    
    // Now, determine the longest reign and most defenses
##### START CHANGES #####
    $longestReign = (rsort($longestR))?$longestR[0]:'No champion has been crowned';
    $successDefense = (rsort($sucessfulD))?$sucessfulD[0]:'No champion has been crowned';
##### END CHANGES #####

    //next, we need to assemble the header of the page.
    $query = "SELECT *, DATE_FORMAT(`datecreated`, '%M %e, %Y') AS datecreated FROM titlehistory WHERE id='".addslashes($_GET['id'])."';";

    if ($r = mysql_query ($query)){ // Run the query. 
        while ($row = mysql_fetch_array ($r)){


            $head .= '<table border=0 cellspacing="0" cellpadding=3 width=575>';
            $head .='<tr><td background="images/bg_bar4.gif" height=35> <font color="white">Title Histories</font></td></tr>';
            $head .='<tr><td></td></tr>';
            $head .='</table>';
            $head .='<table border=0 cellspacing="0" cellpadding=3 width=575>';
            $head .='<tr><td background="images/bg_bar3.gif" height=35 colspan=2> <font color=black>KOW '.$row['titlename'].'</font></td></tr>';
            $head .='<tr><td width=200><img src="/images/' . $row['titleimage'] . '" width=208px height=156px border=0 alt="View KOW '.$row['titlename'].' History"></td><td valign=top>';
            $head .='<table cellpadding="2" cellspacing="0" border="0" width=100%>';
            $head .='<tr><td align=center bgcolor=#E0E0E0><b><font color="#000000">Date Created</font></b></td></tr><tr><td align=center>'.$row['datecreated'].'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Status</font></b></td></tr>';
            $head .='<tr><td align=center>'.$row['status'].'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Longest Reign</font></b></td></tr>';
##### START CHANGES #####
            $head .='<tr><td align=center>'.$longestReign.'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Most Successful Defenses</font></b></td></tr>';
            $head .='<tr><td align=center>'.$successDefense.'</td></tr>';
##### END CHANGES #####
            $head .='</table>';
        }
    }
}
    else
    {
        print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
        print '<tr><td background="images/bg_bar4.gif" height=35> <font color="white">Title Histories</font></td></tr>';
        print '</table>';
        print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
        print '<tr><td background="images/bg_bar3.gif" height=35 colspan=4> <font color="#000000">Active Titles</font></td></tr>';
        print '<tr>';

        //Define the query
        $query = "SELECT * FROM titles WHERE status = 'Active'"; // Active rows

        if ($r = mysql_query ($query)){ // Run the query. 

            while ($row = mysql_fetch_array ($r)){
    
                print '<td><a href="titlehistory.php?id=' . $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
                print '<img src="/images/' . $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
             }

        } 
        else {
                die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was $query.</p>');
        }//End of query IF 

        print '</tr>';
        print '</table>';
        print '<img src=images/spacer.gif><br>';
        print '<table border=0 cellspacing=0 cellpadding=3 width=575><tr><td background="images/bg_bar3.gif" height=35 colspan=2> <font color="#000000">Inactive Titles</font></td></tr>';
        print '<tr>';

        //Define the query
        $query = "SELECT * FROM titles WHERE status = 'Inactive'"; // Inactive Rows

        if ($r = mysql_query ($query)){ // Run the query. 

            while ($row = mysql_fetch_array ($r)){
    
                print '<td><a href="titlehistory.php?id=' . $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
                print '<img src="/images/' . $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
    
            }

        } 
        else {
            die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was $query.</p>');
        } //End of query IF 
    }
print '</tr>';
print '</table>'; 

?> 

Link to comment
Share on other sites

change

            "</tbody></table>\n";
            
        }
        
    }
    
    // Now, determine the longest reign and most defenses
    rsort($longestR);
    rsort($sucessfulD);

to

            "</tbody></table>\n";
            
        }
    // Now, determine the longest reign and most defenses
    rsort($longestR);
    rsort($sucessfulD);        
    }
    

Link to comment
Share on other sites

I'm sorry I've tried all those suggestions and it's just not showing up right at all.

 

Okay what I'm wanting is it to show up like this for example:

 

http://epw.e-wrestling.org/titlehistories.php?id=1

 

I don't have of course any champions crowed yet so when it comes back from getting the rows and sees that there is not champs so the most successful defenses and longest reigns are void it would say "No champions crowned yet"

 

Link to comment
Share on other sites

Let's try again:

<?php echo "<body bgcolor=\"black\" text=\"white\" link=\"red\" vlink=\"red\">"; ?>

<?php
function dateConvert($date)
{
    $eDat = explode("-",$date);
    $year = $eDat[0];
    $nMon = $eDat[1];
    $day  = $eDat[2];
    switch ($nMon)
    {
        case 1:     $mont = "January"; break;
        case 2:     $mont = "February"; break; 
        case 3:     $mont = "March"; break;
        case 4:     $mont = "April"; break;
        case 5:     $mont = "May"; break;
        case 6:     $mont = "June"; break;
        case 7:     $mont = "July"; break;
        case 8:     $mont = "August"; break;
        case 9:     $mont = "September"; break;
        case 10: $mont = "October"; break;
        case 11: $mont = "November"; break;
        case 12: $mont = "December"; break;    
    } 
    $out = $mont . " " . $day . ", " . $year;
    return $out;
}
?>

<?php
// Connects to your Database
$link = mysql_connect("?", "?", "?") or die(mysql_error());
mysql_select_db("?",$link) or die(mysql_error());

if (isset($_GET['id']))
{    
    // First, we need to get the champs, so do some mysql stuffs.
    $qry0 = "SELECT * FROM `titlechamps` WHERE `title` = '".addslashes($_GET['id'])."';";
    $res0 = mysql_query($qry0) or die('Qry zero error!');
    if(!mysql_num_rows($res0)) echo "No champions have been crowned yet!";
    else
    {
        while($list0 = mysql_fetch_assoc($res0))
        {
            // We have at least one champ.
            // First, we have to do a little math. We need to determine 
            // how many days have elapsed between the date won and today.
            $today = explode("-",date("Y-m-d", time()));
            $yesterday = explode("-",$list0['date']);
            $hi = gregoriantojd($today[1],$today[2],$today[0]);
            $lo = gregoriantojd($yesterday[1],$yesterday[2],$yesterday[0]);
            $days = round($hi - $lo);
            
            // We will add the days and name to an array for the header.
            $longestR[] = $days . " - " . $list0['name'];
            // We also add the most successful defences to another array.
            $sucessfulD[] = $list0['defenses'] . " - " . $list0['name'];
            
            if($list0['news'] != null)
            $body .= "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tbody><tr><td colspan=\"2\" bgcolor=\"#e0e0e0\" valign=\"top\" width=\"100%\"><i>".$list0['news']."</i></td></tr></tbody></table>\n";
            
            $body .= 
            "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tbody>\n".
                "<tr>\n".
                "<td width=\"115\" valign=\"top\" align=\"center\"><img src=\"".$list0['pic']."\" /></td>".
                "<td>".
                "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\"><tbody><tr>".
                    "<td width=\"25\" bgcolor=\"#e0e0e0\" align=\"center\"><b>".$list0['num']."</b></td>".
                    "<td bgcolor=\"#e0e0e0\"><font color=\"#ff0000\">".$list0['name']."</font></td>".
                "</tr></tbody></table>".
                "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\"><tbody>".
                    "<tr><td align=\"center\" bgcolor=\"#e0e0e0\" width=\"50%\"><b>Successful Defenses</b></td><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Event</b></td></tr>".
                    "<tr><td align=\"center\">".$list0['defenses']."</td><td align=\"center\">".$list0['event']."</td></tr>".
                    "<tr><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Reign</b></td><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Date Won</b></td></tr>".
                    "<tr><td align=\"center\">$days</td><td align=\"center\">".dateConvert($list0['date'])."</td></tr>".
                    "<tr><td colspan=\"2\"><i>".$list0['blurb']."</i></td></tr>".
                "</tbody></table>".
                "</td></tr>".
            "</tbody></table>\n";
            
        }
        
    }
    
    // Now, determine the longest reign and most defenses
##### START CHANGES #####
    if (is_array($longestR))
    {
        rsort($longestR);
        $longestReign = $longestR[0];
    }
    else
    {
        $longestReign = 'No champion has been crowned';
    }
    if (is_array($sucessfulD))
    {
        rsort($sucessfulD);
        $successDefense = $sucessfulD[0];
    }
    else
    {
        $successDefense = 'No champion has been crowned';
    }
##### END CHANGES #####

    //next, we need to assemble the header of the page.
    $query = "SELECT *, DATE_FORMAT(`datecreated`, '%M %e, %Y') AS datecreated FROM titlehistory WHERE id='".addslashes($_GET['id'])."';";

    if ($r = mysql_query ($query)){ // Run the query. 
        while ($row = mysql_fetch_array ($r)){


            $head .= '<table border=0 cellspacing="0" cellpadding=3 width=575>';
            $head .='<tr><td background="images/bg_bar4.gif" height=35> <font color="white">Title Histories</font></td></tr>';
            $head .='<tr><td></td></tr>';
            $head .='</table>';
            $head .='<table border=0 cellspacing="0" cellpadding=3 width=575>';
            $head .='<tr><td background="images/bg_bar3.gif" height=35 colspan=2> <font color=black>KOW '.$row['titlename'].'</font></td></tr>';
            $head .='<tr><td width=200><img src="/images/' . $row['titleimage'] . '" width=208px height=156px border=0 alt="View KOW '.$row['titlename'].' History"></td><td valign=top>';
            $head .='<table cellpadding="2" cellspacing="0" border="0" width=100%>';
            $head .='<tr><td align=center bgcolor=#E0E0E0><b><font color="#000000">Date Created</font></b></td></tr><tr><td align=center>'.$row['datecreated'].'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Status</font></b></td></tr>';
            $head .='<tr><td align=center>'.$row['status'].'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Longest Reign</font></b></td></tr>';
##### START CHANGES #####
            $head .='<tr><td align=center>'.$longestReign.'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Most Successful Defenses</font></b></td></tr>';
            $head .='<tr><td align=center>'.$successDefense.'</td></tr>';
##### END CHANGES #####
            $head .='</table>';
        }
    }
}
    else
    {
        print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
        print '<tr><td background="images/bg_bar4.gif" height=35> <font color="white">Title Histories</font></td></tr>';
        print '</table>';
        print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
        print '<tr><td background="images/bg_bar3.gif" height=35 colspan=4> <font color="#000000">Active Titles</font></td></tr>';
        print '<tr>';

        //Define the query
        $query = "SELECT * FROM titles WHERE status = 'Active'"; // Active rows

        if ($r = mysql_query ($query)){ // Run the query. 

            while ($row = mysql_fetch_array ($r)){
    
                print '<td><a href="titlehistory.php?id=' . $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
                print '<img src="/images/' . $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
             }

        } 
        else {
                die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was $query.</p>');
        }//End of query IF 

        print '</tr>';
        print '</table>';
        print '<img src=images/spacer.gif><br>';
        print '<table border=0 cellspacing=0 cellpadding=3 width=575><tr><td background="images/bg_bar3.gif" height=35 colspan=2> <font color="#000000">Inactive Titles</font></td></tr>';
        print '<tr>';

        //Define the query
        $query = "SELECT * FROM titles WHERE status = 'Inactive'"; // Inactive Rows

        if ($r = mysql_query ($query)){ // Run the query. 

            while ($row = mysql_fetch_array ($r)){
    
                print '<td><a href="titlehistory.php?id=' . $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
                print '<img src="/images/' . $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
    
            }

        } 
        else {
            die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was $query.</p>');
        } //End of query IF 
    }
print '</tr>';
print '</table>'; 

?>

Link to comment
Share on other sites

Well atleast it says something now. lol but all it says on the window when you click a title is "No champions have been crowned yet!". It needs to atleast show the main table that shows the name, status, date it was created, most successful title defenses and longest reign.

Link to comment
Share on other sites

I just thought of osmething it's going to only keep saying that "No champions have been crowned yet!" because I have no rows for champions. It's going to be empty until I put a champion there but I want to be changed so that even though there are no rows of champions for the  if(!mysql_num_rows($res0)) echo "No champions have been crowned yet!"; then it'll put that table.

Link to comment
Share on other sites

Try this:

<?php echo "<body bgcolor=\"black\" text=\"white\" link=\"red\" vlink=\"red\">"; ?>

<?php
function dateConvert($date)
{
    $eDat = explode("-",$date);
    $year = $eDat[0];
    $nMon = $eDat[1];
    $day  = $eDat[2];
    switch ($nMon)
    {
        case 1:     $mont = "January"; break;
        case 2:     $mont = "February"; break; 
        case 3:     $mont = "March"; break;
        case 4:     $mont = "April"; break;
        case 5:     $mont = "May"; break;
        case 6:     $mont = "June"; break;
        case 7:     $mont = "July"; break;
        case 8:     $mont = "August"; break;
        case 9:     $mont = "September"; break;
        case 10: $mont = "October"; break;
        case 11: $mont = "November"; break;
        case 12: $mont = "December"; break;    
    } 
    $out = $mont . " " . $day . ", " . $year;
    return $out;
}
?>

<?php
// Connects to your Database
$link = mysql_connect("?", "?", "?") or die(mysql_error());
mysql_select_db("?",$link) or die(mysql_error());

if (isset($_GET['id']))
{    
    // First, we need to get the champs, so do some mysql stuffs.
    $qry0 = "SELECT * FROM `titlechamps` WHERE `title` = '".addslashes($_GET['id'])."';";
    $res0 = mysql_query($qry0) or die('Qry zero error!');
    $longestR = $sucessfulD = array();
    if(!mysql_num_rows($res0)) echo "No champions have been crowned yet!";
    else
    {
        while($list0 = mysql_fetch_assoc($res0))
        {
            // We have at least one champ.
            // First, we have to do a little math. We need to determine 
            // how many days have elapsed between the date won and today.
            $today = explode("-",date("Y-m-d", time()));
            $yesterday = explode("-",$list0['date']);
            $hi = gregoriantojd($today[1],$today[2],$today[0]);
            $lo = gregoriantojd($yesterday[1],$yesterday[2],$yesterday[0]);
            $days = round($hi - $lo);
            
            // We will add the days and name to an array for the header.
            $longestR[count($longestR)] = $days . " - " . $list0['name'];
            // We also add the most successful defences to another array.
            $sucessfulD[count($sucessfulD)] = $list0['defenses'] . " - " . $list0['name'];
            
            if($list0['news'] != null)
            $body .= "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tbody><tr><td colspan=\"2\" bgcolor=\"#e0e0e0\" valign=\"top\" width=\"100%\"><i>".$list0['news']."</i></td></tr></tbody></table>\n";
            
            $body .= 
            "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tbody>\n".
                "<tr>\n".
                "<td width=\"115\" valign=\"top\" align=\"center\"><img src=\"".$list0['pic']."\" /></td>".
                "<td>".
                "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\"><tbody><tr>".
                    "<td width=\"25\" bgcolor=\"#e0e0e0\" align=\"center\"><b>".$list0['num']."</b></td>".
                    "<td bgcolor=\"#e0e0e0\"><font color=\"#ff0000\">".$list0['name']."</font></td>".
                "</tr></tbody></table>".
                "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\"><tbody>".
                    "<tr><td align=\"center\" bgcolor=\"#e0e0e0\" width=\"50%\"><b>Successful Defenses</b></td><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Event</b></td></tr>".
                    "<tr><td align=\"center\">".$list0['defenses']."</td><td align=\"center\">".$list0['event']."</td></tr>".
                    "<tr><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Reign</b></td><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Date Won</b></td></tr>".
                    "<tr><td align=\"center\">$days</td><td align=\"center\">".dateConvert($list0['date'])."</td></tr>".
                    "<tr><td colspan=\"2\"><i>".$list0['blurb']."</i></td></tr>".
                "</tbody></table>".
                "</td></tr>".
            "</tbody></table>\n";
            
        }
        
    }
    
    // Now, determine the longest reign and most defenses
    rsort($longestR);
    rsort($sucessfulD);


//next, we need to assemble the header of the page.
    $query = "SELECT *, DATE_FORMAT(`datecreated`, '%M %e, %Y') AS datecreated FROM titlehistory WHERE id='".addslashes($_GET['id'])."';";

    if ($r = mysql_query ($query)){ // Run the query. 
        while ($row = mysql_fetch_array ($r)){


            $head .= '<table border=0 cellspacing="0" cellpadding=3 width=575>';
            $head .='<tr><td background="images/bg_bar4.gif" height=35> <font color="white">Title Histories</font></td></tr>';
            $head .='<tr><td></td></tr>';
            $head .='</table>';
            $head .='<table border=0 cellspacing="0" cellpadding=3 width=575>';
            $head .='<tr><td background="images/bg_bar3.gif" height=35 colspan=2> <font color=black>KOW '.$row['titlename'].'</font></td></tr>';
            $head .='<tr><td width=200><img src="/images/' . $row['titleimage'] . '" width=208px height=156px border=0 alt="View KOW '.$row['titlename'].' History"></td><td valign=top>';
            $head .='<table cellpadding="2" cellspacing="0" border="0" width=100%>';
            $head .='<tr><td align=center bgcolor=#E0E0E0><b><font color="#000000">Date Created</font></b></td></tr><tr><td align=center>'.$row['datecreated'].'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Status</font></b></td></tr>';
            $head .='<tr><td align=center>'.$row['status'].'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Longest Reign</font></b></td></tr>';
            $head .='<tr><td align=center>'.$longestR[0].'</td></tr>';
            $head .='<tr><td bgcolor=#E0E0E0 align=center><b><font color="#000000">Most Successful Defenses</font></b></td></tr>';
            $head .='<tr><td align=center>'.$sucessfulD[0].'</td></tr>';
            $head .='</table>';
        }
    }
}
    else
    {
        print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
        print '<tr><td background="images/bg_bar4.gif" height=35> <font color="white">Title Histories</font></td></tr>';
        print '</table>';
        print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
        print '<tr><td background="images/bg_bar3.gif" height=35 colspan=4> <font color="#000000">Active Titles</font></td></tr>';
        print '<tr>';

        //Define the query
        $query = "SELECT * FROM titles WHERE status = 'Active'"; // Active rows

        if ($r = mysql_query ($query)){ // Run the query. 

            while ($row = mysql_fetch_array ($r)){
    
                print '<td><a href="titlehistory.php?id=' . $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
                print '<img src="/images/' . $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
             }

        } 
        else {
                die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was $query.</p>');
        }//End of query IF 

        print '</tr>';
        print '</table>';
        print '<img src=images/spacer.gif><br>';
        print '<table border=0 cellspacing=0 cellpadding=3 width=575><tr><td background="images/bg_bar3.gif" height=35 colspan=2> <font color="#000000">Inactive Titles</font></td></tr>';
        print '<tr>';

        //Define the query
        $query = "SELECT * FROM titles WHERE status = 'Inactive'"; // Inactive Rows

        if ($r = mysql_query ($query)){ // Run the query. 

            while ($row = mysql_fetch_array ($r)){
    
                print '<td><a href="titlehistory.php?id=' . $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
                print '<img src="/images/' . $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
    
            }

        } 
        else {
            die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was $query.</p>');
        } //End of query IF 
    }
print '</tr>';
print '</table>'; 

?> 

 

Link to comment
Share on other sites

All it shows is No champions crowned at this time. But that's still because I'm betting because there's no rows so it posts that message.

Oh, well that's why. Do you see the if statement?

 

    if(!mysql_num_rows($res0)) echo "No champions have been crowned yet!";
    else
    {
        while($list0 = mysql_fetch_assoc($res0))
        {
            // We have at least one champ.
            // First, we have to do a little math. We need to determine 
            // how many days have elapsed between the date won and today.
            $today = explode("-",date("Y-m-d", time()));
            $yesterday = explode("-",$list0['date']);
            $hi = gregoriantojd($today[1],$today[2],$today[0]);
            $lo = gregoriantojd($yesterday[1],$yesterday[2],$yesterday[0]);
            $days = round($hi - $lo);
            
            // We will add the days and name to an array for the header.
            $longestR[count($longestR)] = $days . " - " . $list0['name'];
            // We also add the most successful defences to another array.
            $sucessfulD[count($sucessfulD)] = $list0['defenses'] . " - " . $list0['name'];
            
            if($list0['news'] != null)
            $body .= "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tbody><tr><td colspan=\"2\" bgcolor=\"#e0e0e0\" valign=\"top\" width=\"100%\"><i>".$list0['news']."</i></td></tr></tbody></table>\n";
            
            $body .= 
            "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tbody>\n".
                "<tr>\n".
                "<td width=\"115\" valign=\"top\" align=\"center\"><img src=\"".$list0['pic']."\" /></td>".
                "<td>".
                "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\"><tbody><tr>".
                    "<td width=\"25\" bgcolor=\"#e0e0e0\" align=\"center\"><b>".$list0['num']."</b></td>".
                    "<td bgcolor=\"#e0e0e0\"><font color=\"#ff0000\">".$list0['name']."</font></td>".
                "</tr></tbody></table>".
                "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\"><tbody>".
                    "<tr><td align=\"center\" bgcolor=\"#e0e0e0\" width=\"50%\"><b>Successful Defenses</b></td><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Event</b></td></tr>".
                    "<tr><td align=\"center\">".$list0['defenses']."</td><td align=\"center\">".$list0['event']."</td></tr>".
                    "<tr><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Reign</b></td><td align=\"center\" bgcolor=\"#e0e0e0\"><b>Date Won</b></td></tr>".
                    "<tr><td align=\"center\">$days</td><td align=\"center\">".dateConvert($list0['date'])."</td></tr>".
                    "<tr><td colspan=\"2\"><i>".$list0['blurb']."</i></td></tr>".
                "</tbody></table>".
                "</td></tr>".
            "</tbody></table>\n";
            
        }

If the `if` statement runs, the else statement doesn't run. Therefore, the HTML is never displayed.

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.