Jump to content

[SOLVED] help w/ including in a function...


Recommended Posts

ok... here's the code:

 

ratings/ratings.php contains:

<?php
//declarations
$filez = preg_replace("/&#39;/", "'", $filez);
$title = preg_replace("/&#39;/", "'", $title);

$fullStar = "<img src='ratings/images/all_star_small.png'> ";
$halfStar = "<img src='ratings/images/half_star_small.png'> ";
$emptyStar = "<img src='ratings/images/no_star_small.png'> ";

$numbers = file('ratings/dat/' . $cat . '/' . $subcat . '/' . $filez . '.dat');
$count = "0";
$sum = "0";

//get average from votes
foreach ($numbers as $line) {
list ($ip, $vote) = explode(':', $line);
$count++;
$sum = $sum+$vote;
}

$avg = $sum/$count;
$avg = round($avg,2);


//break up avg into whole number and decimal
list($fullNum, $decimal) = explode (".", $avg);


if($decimal < 10){
  $decimal = $decimal*10;
}

//print stars
$i = "1";
while($i <= $fullNum){
  print "$fullStar";
  $i++;
}
if($decimal > 24 && $decimal <= 74){
  print "$halfStar";
  $i++;
}
while($i <= 10){
  print "$emptyStar";
  $i++;
}
print "<br />\n";
print "rating: $avg with $count votes<br>\n";
?>

 

and i'm trying to include this file:

 

<?php
$files = array(
//array defining video files, titles, and thumbs here
)

$cat = "video";
$subcat = "mac_ads";

function printLinkRow($file){
  global $cat;
  global $subcat;

  $file_path = "files/$cat/$subcat";
  $thumb_path = "$file_path/thumbs";
  $filez = $file['file'];
  $title = $file['title'];
  $thumb = $file['thumb'];
  $size = filesize("$file_path/$filez");
  include("text_files/filesize.php");

  list($thumb_width, $thumb_height) = getimagesize("$thumb_path/$thumb");
  if($thumb_width > 200){
   $difference = $thumb_width / 200;
   $thumb_width = $thumb_width / $difference;
   $thumb_height = $thumb_height / $difference;
  }

  include("text_files/video_info.php");
  $filez = preg_replace("/'/", "&#39;" , $filez);
  $title = preg_replace("/'/", "&#39;" , $title);
  $alt = $title;
  $message =  "<tr><td width='35%'>\n";
  $message .= "<a href='humor_video_play.php?file=$filez&title=$title&cat=$cat&subcat=$subcat'>\n<img border='0' src='$thumb_path/$thumb' width='$thumb_width' height='$thumb_height' alt='$alt'></a></td>\n";
  $message .= "<td><a href='humor_video_play.php?file=$filez&title=$title&cat=$cat&subcat=$subcat'>$title</a><br>\n";
  $message .= "<a href='$file_path/$filez'>download file</a> | file size: ";
  $message .= "$size<br>\n";
  $message .= "duration : ";
  $message .= "$duration<br>\n";
  $message .= include('ratings/ratings.php');
  $message .= "</td></tr>\n";
  return($message);
}

 

attached are 2 images.. one fubar, one not-fubar... with the above code, i get 'fubar' results, and looking for 'not-fubar' results... any ideas on how to get it not-fubar?

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/83856-solved-help-w-including-in-a-function/
Share on other sites

figured it out...

 

changed:

<?php
  $message =  "<tr><td width='35%'>\n";
  $message .= "<a href='humor_video_play.php?file=$filez&title=$title&cat=$cat&subcat=$subcat'>\n<img border='0' src='$thumb_path/$thumb' width='$thumb_width' height='$thumb_height' alt='$alt'></a></td>\n";
  $message .= "<td><a href='humor_video_play.php?file=$filez&title=$title&cat=$cat&subcat=$subcat'>$title</a><br>\n";
  $message .= "<a href='$file_path/$filez'>download file</a> | file size: ";
  $message .= "$size<br>\n";
  $message .= "duration : ";
  $message .= "$duration<br>\n";
  $message .= include('ratings/ratings.php');
  $message .= "</td></tr>\n";
?>

 

to:

<?php
  $message =  "<tr><td width='35%'>\n";
  $message .= "<a href='humor_video_play.php?file=$filez&title=$title&cat=$cat&subcat=$subcat'>\n<img border='0' src='$thumb_path/$thumb' width='$thumb_width' height='$thumb_height' alt='$alt'></a></td>\n";
  $message .= "<td><a href='humor_video_play.php?file=$filez&title=$title&cat=$cat&subcat=$subcat'>$title</a><br>\n";
  $message .= "<a href='$file_path/$filez'>download file</a> | file size: ";
  $message .= "$size<br>\n";
  $message .= "duration : ";
  $message .= "$duration<br>\n";
   include('ratings/ratings.php');
  $message .= "$ratings\n";
  $message .= "</td></tr>\n";
?>

 

and in ratings.php, changed:

<?php
//print stars
$i = "1";
while($i <= $fullNum){
  print "$fullStar";
  $i++;
}
if($decimal > 24 && $decimal <= 74){
  print "$halfStar";
  $i++;
}
while($i <= 10){
  print "$emptyStar";
  $i++;
}
print "<br />\n";
print "rating: $avg with $count votes<br>\n";
?>

 

to:

<?php
$ratings = "";

//print stars
$i = "1";
while($i <= $fullNum){
$ratings .= "$fullStar";
$i++;
}
if($decimal > 24 && $decimal <= 74){
$ratings .= "$halfStar";
$i++;
}
while($i <= 10){
$ratings .= "$emptyStar";
$i++;
}
$ratings .= "<br />\n";
$ratings .= "rating: $avg with $count votes<br>\n";
?>

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.