Jump to content

AasimAzam

New Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by AasimAzam

  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 would you be able to help? I'm not sure what I am doing.
  5. 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 ...
  6. 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.
×
×
  • 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.