Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's
Author Message
NoFantasy
Worker
Worker


Joined: Apr 26, 2005
Posts: 114

PostPosted: Fri May 20, 2005 5:03 am Reply with quote

This is the function for showing a spesific page in a Discohgrapy:
Code:
function more($sid){

include("header.php");
global $prefix, $db, $module_name, $nukeurl, $dbi;
OpenTable();
$result = $db->sql_query("SELECT * FROM ".$prefix."_discography WHERE sid='$sid'");
while ($row2 = $db->sql_fetchrow($result)) {
$sid = $row2['sid'];
$title = $row2['title'];
$bodytext = $row2['bodytext'];
$hometext = $row2['hometext'];
$img = $row2['img'];
$img2 = $row2['img2'];
$alanguage = $row2['alanguage'];
$year = $row2['year'];
$comment = $row2['comment'];
$company = $row2['company'];
$artist = $row2['artist'];
$contrib = $row2['contrib'];
$track01 = $row2['track01'];
$track02 = $row2['track02'];
$track03 = $row2['track03'];
$track04 = $row2['track04'];
$track05 = $row2['track05'];
$track06 = $row2['track06'];
$track07 = $row2['track07'];
$track08 = $row2['track08'];
$track09 = $row2['track09'];
$track10 = $row2['track10'];
$track11 = $row2['track11'];
$track12 = $row2['track12'];
$track13 = $row2['track13'];
$track14 = $row2['track14'];
$track15 = $row2['track15'];
$track16 = $row2['track16'];
$track17 = $row2['track17'];
$track18 = $row2['track18'];
$track19 = $row2['track19'];
$track20 = $row2['track20'];
echo "<table><tr><td>";
echo "<a href=\"images/discography/$img2\" target=\"_blank\"><img src=\"images/discography/$img2\" alt=\"$title\" width=\"250\" height=\"250\" border=\"0\"></a></td>";
echo "<td valign=\"top\"><font class=\"title\">$artist</font><br><br>";
echo "<font class=\"boxtitle\"><b><i>$title</i></b></font><br><br>";
echo "<b>"._RELEASEYEAR.":</b>&nbsp;$year<br><br>";
echo "<b>"._RECORDCOMP.":</b>&nbsp;$company<br><br>";
echo "<b>"._PAGETEXT.":</b>&nbsp;$bodytext<br><br>";
echo "<b>"._COMMENT.":</b>&nbsp;$comment<br><br>";
echo "<center><b>"._CONTRIB."</b><br>$contrib</center><br><br>";
echo "<br><center><b>"._GOBACK."</b></center>";
echo "</td></tr>";
echo "<tr><td colspan=\"2\"><br><b>"._TRACKLIST."</b><br><br><ol>";
echo "<li>$track01</li><br>";
echo "<li>$track02</li><br>";
echo "<li>$track03</li><br>";
echo "<li>$track04</li><br>";
echo "<li>$track05</li><br>";
echo "<li>$track06</li><br>";
echo "<li>$track07</li><br>";
echo "<li>$track08</li><br>";
echo "<li>$track09</li><br>";
echo "<li>$track10</li><br>";
echo "<li>$track11</li><br>";
echo "<li>$track12</li><br>";
echo "<li>$track13</li><br>";
echo "<li>$track14</li><br>";
echo "<li>$track15</li><br>";
echo "<li>$track16</li><br>";
echo "<li>$track17</li><br>";
echo "<li>$track18</li><br>";
echo "<li>$track19</li><br>";
echo "<li>$track20</li></ol><br>";
echo "</td></tr>";
echo "</table>";
}
CloseTable();
include("footer.php");
}

I'm happy with the look, but it's one problem. Not all albums have 20 tracks, i want the list to exclude empty trackfields.

What is the best way to do this? Probably some code saying "If $track06=empty, then...".
Thanks in advance for any suggestions.
 
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17086

PostPosted: Fri May 20, 2005 7:00 am Reply with quote

A very quick way, but by no means the only way, would be to change
Code:
echo "<tr><td colspan=\"2\"><br><b>"._TRACKLIST."</b><br><br><ol>";

echo "<li>$track01</li><br>";
echo "<li>$track02</li><br>";
echo "<li>$track03</li><br>";
echo "<li>$track04</li><br>";
echo "<li>$track05</li><br>";
echo "<li>$track06</li><br>";
echo "<li>$track07</li><br>";
echo "<li>$track08</li><br>";
echo "<li>$track09</li><br>";
echo "<li>$track10</li><br>";
echo "<li>$track11</li><br>";
echo "<li>$track12</li><br>";
echo "<li>$track13</li><br>";
echo "<li>$track14</li><br>";
echo "<li>$track15</li><br>";
echo "<li>$track16</li><br>";
echo "<li>$track17</li><br>";
echo "<li>$track18</li><br>";
echo "<li>$track19</li><br>";
echo "<li>$track20</li></ol><br>";
to
Code:
echo "<tr><td colspan=\"2\"><br><b>"._TRACKLIST."</b><br><br>";

echo "<ol>";
for ($i=1;$i<21;$i++) {
   if ($i<10) $addZero = '0'; else $addZero = '';
   $_track = ${track.$addZero.$i};
   if (!empty($_track)) echo "<li>$_track</li><br>";
}
echo "</ol><br>";

Please note that I haven't tested this but it should work Smile.
 
View user's profile Send private message
NoFantasy
PostPosted: Fri May 20, 2005 7:39 am Reply with quote

Working just fine, thanks!

It did solve the problem and made the script smaller, thats the mainpriority for me Very Happy
 
Raven
PostPosted: Fri May 20, 2005 10:18 am Reply with quote

Assuming I didn't miss anything, replace your code above with
Code:
function more($sid){

   include("header.php");
   global $prefix, $db, $module_name, $nukeurl;
   OpenTable();
   $result = $db->sql_query("SELECT * FROM ".$prefix."_discography WHERE sid='$sid'");
   while ($row2 = $db->sql_fetchrow($result)) {
      echo "<table><tr><td>";
      echo "<a href=\"images/discography/".$row2['img2']."\" target=\"_blank\"><img src=\"images/discography/".$row2['img2']."\" alt=\"".$row2['title']."\" width=\"250\" height=\"250\" border=\"0\"></a></td>";
      echo "<td valign=\"top\"><font class=\"title\">".$row2['artist']."</font><br><br>";
      echo "<font class=\"boxtitle\"><b><i>".$row2['title']."</i></b></font><br><br>";
      echo "<b>"._RELEASEYEAR.":</b>&nbsp;".$row2['year']."<br><br>";
      echo "<b>"._RECORDCOMP.":</b>&nbsp;".$row2['company']."<br><br>";
      echo "<b>"._PAGETEXT.":</b>&nbsp;".$row2['bodytext']."<br><br>";
      echo "<b>"._COMMENT.":</b>&nbsp;".$row2['comment']."<br><br>";
      echo "<center><b>"._CONTRIB."</b><br>".$row2['contrib']."</center><br><br>";
      echo "<br><center><b>"._GOBACK."</b></center>";
      echo "</td></tr>";
      echo "<tr><td colspan=\"2\"><br><b>"._TRACKLIST."</b><br><br>";
      echo "<ol>";
      for ($i=1;$i<21;$i++) {
         eval('$track=$row2['."'track".($i<10?'0':'').$i."'];");
         if (!empty($track)) echo "<li>".$track."</li><br>";
      }
      echo "</ol><br>";
      echo "</td></tr>";
      echo "</table>";
   }
   CloseTable();
   include("footer.php");
}
 
NoFantasy
PostPosted: Fri May 20, 2005 10:55 am Reply with quote

Good point, it's no need to transform the databaseresults into $'s when it's in use only one time inside the function i guess. Working just fine, and did the script even smaller....and probably a bit faster.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©