Jump to content

AasimAzam

New Members
  • Posts

    8
  • Joined

  • Last visited

AasimAzam's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have about 1000+htm files they have data like the attached files. I have the following code that converts this data into a csv file. I then wanted to convert the whole folder into csv files so I have the following code <?php header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=data.csv'); ini_set('display_errors',1); error_reporting(E_ALL); // have to put files in another folder that does not include this script foreach (glob("directory/*.*") as $filename) { $dump = file_get_contents($filename); $stats_wanted = array('playedPositionsShort', 'name', 'playerId', 'age', 'rating', 'shotOnTarget', 'shotsTotal', 'penaltyScored', 'penaltyMissed', 'passLongBallAccurate', 'passLongBallTotal', 'passTotal', 'passCrossAccurate', 'passCrossTotal', 'passThroughBallTotal', 'passThroughBallAccurate', 'keyPassTotal', 'dribbleWon', 'dribbleTotal', 'tackleWon', 'tackleLost', 'tackleWonTotal', 'tackleTotalAttempted', 'challengeLost', 'interceptionLost', 'penaltyTaken', 'interceptionAll', 'clearanceTotal', 'offsideGiven', 'offsideProvoked', 'foulGiven', 'foulCommitted', 'dispossessed', 'duelAerialWon', 'duelAerialLost', 'duelAerialTotal', 'touches', 'totalPasses', 'offsideWonPerGame', 'offsideGivenPerGame', 'passSuccessInMatch' ); $output = json_decode($dump); foreach($output->playerTableStats as $o){ foreach($o as $key=>$value){ if(!in_array($key, $stats_wanted)){ unset($o->$key); } } $new[$o->name] = $o; } $output = fopen('php://output', 'w'); fputcsv($output, $stats_wanted); foreach ($new as $n) { foreach($n as $a){ $ar[] = $a; } fputcsv($output, $ar); unset($ar); }} ?> This script does export a csv file which I can save, that file has ALL the data of every file in the folder that was processed, however when I open it, the data is all wrong. Its all mixed up. I tested the above 1 file at a time = no errors 2+ files at a time = jumbled up. What I want to do is convert each of the htm files I have to individual csv files in one batch. I also want the file name to match the htm file name. I don't know if that is possible with amendments to this script or would I need a totally new script? Any help on this matter would be very much appreciated, I have been banging on this for more than a week now. BLIGA001.htm BLIGA002.htm BLIGA003.htm BLIGA004.htm BLIGA005.htm
  2. -- phpMyAdmin SQL Dump -- version 4.4.14 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: Nov 08, 2015 at 05:57 PM -- Server version: 5.6.26 -- PHP Version: 5.6.12 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `alltime` -- -- -------------------------------------------------------- -- -- Table structure for table `fixtures` -- CREATE TABLE IF NOT EXISTS `fixtures` ( `id` int(11) NOT NULL, `stage` int(11) NOT NULL, `game_no` int(11) NOT NULL, `hometeam` varchar(255) NOT NULL, `goalsfor` int(11) DEFAULT NULL, `goalsagainst` int(11) DEFAULT NULL, `awayteam` varchar(255) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; -- -- Dumping data for table `fixtures` -- INSERT INTO `fixtures` (`id`, `stage`, `game_no`, `hometeam`, `goalsfor`, `goalsagainst`, `awayteam`) VALUES (1, 1, 1, 'Team 1', 1, 0, 'Team 2'), (2, 1, 2, 'Team 3', 1, 3, 'Team 4'), (3, 3, 3, 'Team 1', 2, 0, 'Team 3'); -- -- Indexes for dumped tables -- -- -- Indexes for table `fixtures` -- ALTER TABLE `fixtures` ADD PRIMARY KEY (`id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `fixtures` -- ALTER TABLE `fixtures` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=4; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
  3. Not sure how I upload the SQL file, or should I just post the code here?
  4. Hi Chris, Thank you for your answer. I assume that one file will house the drop down and on selecting the relevant choice from the drop down, and when it populates the page, a second page to run the update part when I input results .... If I assume correctly, I will be able to do the drop down list part to populate the page but not the update results part ...
  5. If I have a drop down list and with the java script code submitChange() it populates the page with a set of results from the database, where some of the data is an input feild which I can then input data to, to update the database. I have tried for the last four days to get somewhere with this and I am banging my head against the wall. It either works but just with one row, or it throws up an undefined error even though I have defined all the variables! Anyway, I have to do this using PDO and/or Mysqli as I've been told, so I have learned some basics and got this so far where I can output my results my data base (structure) id (INT) stage (INT) game_no (INT) hometeam (VARCHAR) goalsfor (INT) goalsagainst (INT) awayteam (VARCHAR) +----+-------+---------+----------+----------+--------------+-----------+ | id | stage | game_no | hometeam | goalsfor | goalsagainst | awayteam | +----+-------+---------+----------+----------+--------------+-----------+ | 1 | 1 | 1 | teamname | 1 | 2 | teamname | (etc) +----+-------+---------+----------+----------+--------------+-----------+ then my php if($results = $db->query("SELECT * FROM fixtures")){ if($results->num_rows){ while($row = $results->fetch_object()){ $records[] = $row; } $results->free(); } } and echo (without formating) <?php if(!count($records)){ echo 'NO Records'; } else { foreach($records as $r) { echo $r->hometeam; echo $r->goalsfor; echo $r->goalsagainst; echo $r->awayteam; } } ?> this is as far as I can go as I can't find anything that shows me what I want to do. So I want to create a drop downlist to select the stage eg WHERE stage=5. And when that outputs the list of fixtures, the "goalsfor" and "goalsagainst" should be an input feild that I can update the results in the database (individually without refreshing the page). All done in the same page. I understand the theory but I can put it into practice. Thank you for taking the time to read and thank you in advance for any answers.
  6. Hi, I have a database that has the following layout (only relevant colums detailed index season day month year goals_scored I want to create an array with a running total of goals scored by a quarter. For example, Sum of goals scored between month=8 to month=10 month=11 to month=1 month=2 to month=4 month=5 to month=7 Where year=2002 then go through years 2002-current year what ever it is and it up. So if I have sum of month=8-10: 0 sum of month=11-1: 2 sum of month=2-4: 8 sum of month=5-7: 5 When I echo the array it will be in this format: (0,2,10,15) I also want to make a separate query for a single year, by month, i.e sum of goals scored where month=7, month=8 etc. Any indication and help explaining the function for this would help. My php is very basic, I know how create a query and make loop to echo a table of results etc. These arrays are for graphs. I want the graph to be ready for the full season even if its not happened yet.
  7. Hi, I have a list of football results in a MYSQL database and have written a function to access whatever I need from it. I would like to use this in conjunction with a drop down list. $query1 = query_create('cristiano', '$season', '$year', '$competition', '$level', 'Cristiano Ronaldo', '2013/2014'); echo $query1; There will be several drop down lists, 2002/2003 > selecting this will create a variable called $season with the value " WHERE season=1" 2003/2004 > selecting this will create a variable called $season with the value " WHERE season=2" 2004/2005 > selecting this will create a variable called $season with the value " WHERE season=3" etc etc OR 2002 > selecting this will create a variable called $year with the value " WHERE year=2002" 2003 > selecting this will create a variable called $year with the value " WHERE year=2003" 2004 > selecting this will create a variable called $year with the value " WHERE year=2004" etc etc When I have selected any of the above form the form I will get another drop down list La Liga > selecting this will create a variable called $competition with the value " WHERE competition=La Liga" Champions League> selecting this will create a variable called $competition with the value " WHERE competition=Champions League" etc and finally another drop down list International > selecting this will create a variable called $level with the value " WHERE level=International" Domestic> selecting this will create a variable called $level with the value " WHERE level=Domestic" When the submit button is pressed that variable will pass through the query_create and echo out the relevant results. I don't know where to start on this as I am a total novice at this, could someone help me out with this? Also if there is someway I can do this with AJAX to refresh results without refreshing the page?
×
×
  • 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.