Jump to content

adamgonge

New Members
  • Posts

    6
  • Joined

  • Last visited

Posts posted by adamgonge

  1. Hey thanks for the help it seemed to be the <br/> tags, thanks for the rewrite I compared to mine and made adjustments accordingly. the final code takes your style which I am lacking in and and also your for each block. I appreciate it because im really trying to become a great programmer, not just capable of doing it.  If you have any suggestions on how I could improve please let me know, and again thanks for the help.

    final code:

    <?php
    // this script reads data from a text file
    // open file and read data
    $fp=fopen("nflstats.csv", "rw");
     if (!$fp){
     echo "Could not open the file!";
     exit();
     }
     displayData($fp);
    
    function displayData($fp){
        $line1 = fgets($fp, 256);
        $ratings = array();
        while(!feof($fp)){
            //read one line at a time
            $line= fgets($fp, 256 );
            $total= 0;
           //Split the data using explode() function
            if($line !=""){
                $info=explode(",", $line);
                $player_name = $info[0];
                $c_value = ($info[2]*100/$info[3] - 30)/20;
                $y_value = ($info[4]/$info[3] - 3)/4;
                $t_value = $info[5]*20/$info[3];
                $i_value = 2.375 - $info[6]*35/$info[3];
                $pass_rating =round(($c_value + $y_value + $t_value + $i_value)*100/6, 2);
                $ratings[$player_name]= $pass_rating;
            }
        }
        arsort($ratings);
    
        echo "<table border=1>";
        echo "<tr><td colspan=\"3\" ><h2>"."NFL Player Pass Ratings"."</h2></td></tr>";
        echo "<tr><th>Name</th><th>Pass Rating</th></tr>\n";
    
        foreach ($ratings as $player_name=>$pass_rating){
        echo "<tr><td>{$player_name}</td><td>{$pass_rating}</td></tr>\n";
        }
        echo"</table>\n";
    
        echo"<table border=1>";
        echo "<tr><th colspan=\"22\" ><h2>"."NFL Player Pass Ratings: Great, Good, Mediocre"."</h2></td></tr>";
        echo "<tr><th>Name</th><th>Pass Rating</th></tr>\n";
    
        foreach ($ratings as $player_name=>$pass_rating){
            if($pass_rating > 95) {
                $rating_label = "Great";
            } elseif($pass_rating >90){
                $rating_label = "Good";
      } elseif($pass_rating >85){
                $rating_label = "Mediocre";
            } else{
                $rating_label = "Terrible";
            }
            echo "<tr>\n";
            echo "<td>{$player_name}</td><td>{$pass_rating}<b> -- {$rating_label}</b></td>\n";
            echo "</tr>\n";
    }
       echo"</table>\n";
    }
    ?>
    
    
  2. Hi! I wrote this script that takes a nflstats.csv file reads it and then does some stuff to show the player name  and corresponding pass rating. when I put it into tables the tables show up really far down the page and Im not sure why. If I remove the tables the info is displayed at the top but for some reason the tables move it down drastically. Here is my code:

    <?php
    // this script reads data from a text file
    
    // open file and read data
     $fp=fopen("nflstats.csv", "rw");
    if (!$fp){
            echo "Could not open the file!";
    exit();
    }
    //read the first line
    $line1 = fgets($fp, 256);
    
     displayData($fp);
    
    function displayData($fp){
    
    $ratings = array();
    
    
    while(!feof($fp)){ // as long as it is not the end of the file.
            //read one line at a time
            $line= fgets($fp, 256 );
            $total= 0;
           //Split the data using explode() function
        if($line !=""){
           $info=explode(",", $line);
       $player_name = $info[0];
    
    
            $c_value = ($info[2]*100/$info[3] - 30)/20;
            $y_value = ($info[4]/$info[3] - 3)/4;
            $t_value = $info[5]*20/$info[3];
            $i_value = 2.375 - $info[6]*35/$info[3];
            $pass_rating = ($c_value + $y_value + $t_value + $i_value)*100/6;
            $ratings[$player_name]= $pass_rating;
    
    }}
    
    
     echo "<h2>"."NFL Player Pass Ratings"."</h2>";
     arsort($ratings);
     echo"<table>";
    
       foreach ($ratings as $player_name=>$pass_rating){
       echo "<tr><td>Name: </td><td>".$player_name."</td><td> Pass Rating: </td><td>".round($pass_rating,2)."</td></tr><br/>";
       }
     echo"</table>";
     echo "<h2>"."NFL Player Pass Ratings: Great, Good, Mediocre"."</h2><br/>";
      arsort($ratings);
       echo"<table>";
       foreach ($ratings as $player_name=>$pass_rating){
    
            // display name and team
       if($pass_rating > 85&& $pass_rating <=90)
       echo "<tr><td>Name: </td><td>".$player_name."</td><td>Pass Rating: </td><td>".round($pass_rating, 2)."<b> --Mediocre</b></td></tr><br/>";
       elseif ($pass_rating > 90 && $pass_rating <=95)
       echo "<tr><td>Name: </td><td> ".$player_name."</td><td> Pass Rating: </td><td>".round($pass_rating, 2)."<b> --Good</b></td><td><br/>";
            elseif($pass_rating > 95)
            echo "<tr><td>Name: </td><td>".$player_name."</td><td> Pass Rating: </td><td>".round($pass_rating, 2)."<b> --Great</b></td></tr><br/>";        
    }
             echo"</table>";
    }
    ?>
    
    
  3.  

    so i have a series of problems ive been working on and the last one is giving me problems.  I have a script that reads a text file does some stuff with it and then displays it. that all works just fine now i have to add a fwrite to a external text file. basically the fget brings it in does some calculations and displays them line by line, I need to do the the same with fwrite but all it will do is write from the first line. heres my code

     

    <?php
    $fp =fopen("sales.csv", "r");
      if(!$fp){
            echo "could not open the file!";
            exit();
            }
            echo "<h2>Display Monthly Sales: "."</h2><br/>";
      displayData($fp);
    function displayData($fp){
            //define an array to store data
     
    while(!feof($fp)){
      // read the current line
      $info = fgetcsv($fp, 250, ',');
      // add dataa only if data is nonempty
      if ($info[0] !=""){
     
              // read the date into a variable
             $month = $info[0];
             $sales =$info[1];
             $rent =$info[2];
             $wages =$info[3];
             $supplies =$info[4];
     
            }// end if
     // echo"<b>Month: </b> ".$month.",<b> Sales: </b> ".$sales."<b> Rent </b>".$rent."<b>Wages:</b>".$wages."<b>Supplies:</b>".$supplies."<br/>\n";
      echo"<b>Month:  Rent: Sales:  Wages:  Supplies:  </b>"."<br/>\n";
      echo "<b>".$month."</b>"." ".$sales." ".$rent." ".$wages." ".$supplies."<br/>\n";
      echo "<br/>\n";
     
    $fw = fopen("problem4.txt", "w");
    $total_cost=$rent+$wages+$supplies;
    $operating_income = $sales-$total_cost;
    $net_income= $operating_income*.60;
    // use fwrite() to write data
    // syntax: fwrite('file_pointer, "string");
    fwrite($fw, "Month: Sales: Total Cost: Operating Income: Net Income:"."\n");
    fwrite($fw, $month."   ".$sales." ".$total_cost."       ".$operating_income."          ".$net_income."\n"  );
     
     
     
     
     
     
          }//end while
          }
    ?>

  4. hello, Im stuck on a problem with my code. the program takes a csv file and breaks it down to use. I am using an array and displaying the dates and the differences between each open/close and hi/lo. My code does that much now after thats complete i want to display the highest and lowest of both the hi/lo and open/close. open/close is assigned to $dif_o hi/lo assigned to $dif. Ive tried the min max function but that's not working. not sure how to go about doing this heres my code:

     

     <?php//read the data from the file and display player's name and team$fp = fopen("http://cs.uww.edu/data/stocks/AAPL.csv", 'r');if(!$fp){        echo "could not open the file!";        exit(); } displayData($fp); function displayData($fp){//define an array to store data  $stocks = array(); //read each line into an array, save name and team using an associative arraywhile(!feof($fp)){  // read the current line  $info = fgetcsv($fp, 250, ',');  // add dataa only if data is nonempty  if ($info[0] !=""){           // read the date into a variable        $date = $info[0];         // add this information to associative array        //use $date as the key          $dif =($info[2])-($info[3]);         $dif_o=$info[1]-$info[4];         $stocks[$date]= $dif;         $stocks[$date]=$dif_o; }// end if         echo "Date: ".$date.", Difference between Hi and Lo: ".$dif.", Difference between Open and Close: ".$dif_o."<br/>";}//end while//sort data $min=min($dif);$max=max($dif); echo "Min: ".$min." Max: ".$max."<br/>";}?>
    

  5. i changed the equation but now it just ends up with 64squared whereas i think i need the sum of all the squares.

     

    new

    <html>
     <head>
      <title>PHP Test</title>
     </head>
     <body>
     <?php echo '<p>Multiplication test</p>'; ?>
    <?php
     
    $total = 0;
    $even = 0;
     
    for ( $x = 0; $x < 64; $x++ ) {
     
        $sum =($x+1*2)*$x;
     
      }
     
    echo "The total sum: ".$sum."<br />";
     
    ?>
     
     
    </body>
    </html>
    
  6. im working on a problem that involves a loop that goes to 64 with each time the number is doubling itself so it would be 1,2,4,8,16.. I dont know how to do it .

    I currently have this code which is wrong it just ends up taking 64*2 but i dont know how else to set this up. 

     

     

     
    <html>
     <head>
      <title>PHP Test</title>
     </head>
     <body>
     <?php echo '<p>Multiplication test</p>'; ?>
    <?php
     
    $total = 0;
    $even = 0;
     
    for ( $x = 1; $x <= 64; $x++ ) {
     
        $sum = 1+$x*2;
     
      }
     
    echo "The total sum: ".$sum."<br />";
     
    ?>
     
    
    
×
×
  • 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.