Xtremer360 Posted August 26, 2008 Share Posted August 26, 2008 Can I get some assistance rewriting my if statement because the if(!mysql_num_rows($res0)) I still want it to post the html table even if there are no rows. <?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 https://forums.phpfreaks.com/topic/121395-rewriting-my-if-statement/ Share on other sites More sharing options...
efficacious Posted August 26, 2008 Share Posted August 26, 2008 you could just remove the html from the statement and just use the statement to fill in the values.. is this for a boxing thing? j/w Link to comment https://forums.phpfreaks.com/topic/121395-rewriting-my-if-statement/#findComment-625911 Share on other sites More sharing options...
Xtremer360 Posted August 26, 2008 Author Share Posted August 26, 2008 No but your close on the boxing part. Link to comment https://forums.phpfreaks.com/topic/121395-rewriting-my-if-statement/#findComment-625913 Share on other sites More sharing options...
Xtremer360 Posted August 26, 2008 Author Share Posted August 26, 2008 How should it look because if I try and work with it then it won't come out right. What I'm wanting to happen is http://epw.e-wrestling.org/titlehistories.php but that part of my script works it's just what shows when you click on a title. This is where I got the idea from. Link to comment https://forums.phpfreaks.com/topic/121395-rewriting-my-if-statement/#findComment-625920 Share on other sites More sharing options...
revraz Posted August 26, 2008 Share Posted August 26, 2008 You have two tables in your code, which one are you referring to? Also, both tables contain data from your query, if you show it without that data, is there really a point? Link to comment https://forums.phpfreaks.com/topic/121395-rewriting-my-if-statement/#findComment-625942 Share on other sites More sharing options...
Xtremer360 Posted August 26, 2008 Author Share Posted August 26, 2008 Well I gave the link of the script I'm trying to create on the other site but here's what I have so far: http://www.kansasoutlawwrestling.com/titlehistory5.php Link to comment https://forums.phpfreaks.com/topic/121395-rewriting-my-if-statement/#findComment-625971 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.