[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Can anyone help me with some PHP? Or if you're well ver

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 94
Thread images: 10

File: 1423852294824.png (39KB, 290x336px) Image search: [Google]
1423852294824.png
39KB, 290x336px
Can anyone help me with some PHP? Or if you're well versed in another language

Basically what I'm trying to do is load a CSV (Comma Separated Value) file and then then have it printed to a page. I've managed to print the data, but the next step is grouping it by column. So say for example the third "column" in the CSV file was an age and I wanted to group by that third column, every row would be presented sorted by age.

I'd also like for there to be a way to display the number in the groups, e.g., 9 people are aged 18, 16 people are aged 21, 3 people are aged 30

Could anyone help with this? Here's what I have so far, it just prints all the data in the CSV file by column, I'm not sure how to enhance it.
https://pastebin.com/NzixRsz6
Would it be better doing this in Java?

Thanks. Any help is appreciated. Also pastebin unlisted and set to expire preferably
>>
>>>/g/59761113
>>
>>292244
There's more efficient ways to do it (way more efficient ways to do it. file_get_contents, str_getcsv and array_map get you about the same in a couple of lines with no loop), but you're clearly just learning, so that's fine.

But let's take advantage of your loop: You have something like
[code]
$numberOfRows = 0;
while (($row = fgetcsv($handle, 1024, $delimeter)) !== FALSE)
{
$csvData[$numberOfRows] = $row;
$numberOfRows++;
}
[/code]

Which, by the way, can be simplified as
[code]
while (($row = fgetcsv($handle, 1024, $delimeter)) !== FALSE)
{
$csvData[] = $row; //empty square brackets means previous numeric key+1
}
[/code]

So, for now, you can just save your statistical data in the same loop. Something like, say, an array called $ages counting the instances of a particular age in the 'age' row of your csv, located in the third column for example, with a conditional going
[code]
$ages = array();
while (($row = fgetcsv($handle, 1024, $delimeter)) !== FALSE)
{
$csvData[] = $row;
if (array_key_exists($row[3],$ages)) //that is, if $row[3] (the value of the third (age) column of the current row, let's say the value is currently 9 meaning the column is specifying 9 years old) exists in the array $ages
{
$ages[$row[3]]++; //if $ages['9'] exists, $ages['9']++
} //if
else
{
$ages[$row[3]] = 1; //if $ages['9'] doesn't exist, $ages['9'] = 1
} //else
} //while
[/code]

So after the loop you have an array kinda like
$ages = array('9'=>18,'16'=>21,'3'=>30)

Again, there's more efficient ways to do this, but this way is congruent with your level.

Oh, also, for($i=0; $i < count($array); $i++) can be iterated more efficiently with foreach($array)
>>
>>292540
Thanks a lot for this, I'm going to have a proper look at it later and I'll report back
>>
>>292540
Once again, I appreciate the help man
I see that the counter's doing something, but is there a way to group the data when its echo'd? You can see in the pastebin it just prints out everything it can, but I'd rather it was echo'd in a way that things were grouped together. Preferably in such a way that I can easily replicate it for every column. I tried looking this up online but got confused desu

>Oh, also, for($i=0; $i < count($array); $i++) can be iterated more efficiently with foreach($array)
Not sure how to go about that. I tried it and instead ended up with the first row repeating over and over.
>>
>>293040
>is there a way to group the data when its echo'd?
Of course. Divs and spans. And tables, though tables haven't been standard for like a decade, and for good reason.

[code]
for ($row = 0; $row < count($csvData); $row++) {

?><div class="row"><?="\n"?><?

for ($col = 0; $col < count($csvData[$row]); $col++) {

?><span class="column <?=$col_identifiers[$col]?>">
<?=$csvData[$row][$col]?>
</span><?="\n"?><? //close span class="column"

} //for $col

?></div><?="\n"?><? //close div class="row"

} //for $row
[/code]

I'm going out of php to html (closing php with ?> and opening it with <?) to print instead of using echo, just for convenience. The "<?="\n"?>"s are newlines, for page source readability.

<div>s will print a newline unless it's specified in the css, so if you don't want that, use <span>s, which are the same as <div>s, but they don't print a newline. That's why I'm using <span>s for the columns.

As you can see, I'm using a $col_identifiers variable. That can be, for example, a keyed array containing the key numbers. Like, if you know your third iteration of the $col array will be ages, and want the printed elements to be of the 'age' class, and the first and second ones 'name' and 'lastname' then $col_identifier should be something like array(1=>"name", 2=>"lastname", 3=>"age").

Then, you do whatever you want to the classes with css, like, say.
[code]
.row {
position: relative;
}
.column {
position: absolute;
}
.name {
left: 0px;
}
.lastname{
left: 200px;
}
.age {
left: 400px;
}
[/code]

So they'll be properly tabbed without needing ugly, hard to style tables.

>Not sure how to go about that. I tried it and instead ended up with the first row repeating over and over.
Read the php manual.

But for($i=0; $i < count($array); $i++) is the same as foreach($array as $i) (I forgot to add the "as $i" in my previous post), except it also works with arrays that don't use perfectly ordered number keys starting from zero, and it's much easier to read.
>>
>>293118
Oh, also, you can do foreach($array as $k=>$i) for $k being the key and $i being the content.
>>
>>292244
Are you looking to analyse the data, or to produce a website from it?

Because for the former, something like AWK or Excel is a much better fit than PHP.

In Excel, to do what you're asking, you literally load the CSV, select the data, and add it to a PivotTable.
>>
>>293145
>server-side excel
oh god just kill me
>>
>>293145
It's more I'm looking to process the data myself than look at existing tools
>>
>>293277
Find me one single word in OP that implies client-server.

No, "PHP" doesn't count: you can easy-peasy #!/usr/bin/php .
>>
>>293656
>>
>>293656
>>293925
Why the fuck are you still bumping?

The answers have already been given here >>292540 and here>>293118

Unless they don't answer everything, in which case, ask. Don't just bump.
>>
>>294041
Because I've not managed to get round to working on it properly
I figure its better to keep the thread bumped in case I have another question than create a new one later
>>
>>294101
Mate. Fucking hell.

Here. Made your homework in like 5 minutes. Left it as a single nested loop, though there's still way more efficient ways to do that shit:
https://comfy.moe/uqqaxc.zip
>>
>>294170
Thanks for the help.
Big thanks to everyone in the thread also. Didn't want to be a bother, so I'm sorry I kept doing the bump thing because I hadn't got round to it yet. I'm also sorry for taking so long to get to it. I really do appreciate the help, thanks /wsr/
>>
>>293118
Thanks for the explanation but I don't quite get this part
>I'm using a $col_identifiers variable. That can be, for example, a keyed array containing the key numbers. Like, if you know your third iteration of the $col array will be ages, and want the printed elements to be of the 'age' class, and the first and second ones 'name' and 'lastname' then $col_identifier should be something like array(1=>"name", 2=>"lastname", 3=>"age").
Should I have it as $col_identifiers[$1] depending on which row I want to print out.

Sorry for bumping and again thanks for taking the time to explain in basic terms for me
>>
>>295119
Yes.

Look at the applied code here: >>294170
It's being used in line 52, as
>$col_identifiers[$i]
Where $i is an iterator that gets ++'d at the end of the column foreach (line 66), and goes back to =1 before the column foreach starts on the next round of the row while loop (line 50).
>>
>>295149
>>295119
Wait. I think I can be clearer.

The while loop (which was your own loop) iterates the rows. On top, it prints the row's div opening tag, and resets $i to 1.
The foreach loop, which is nested inside the while loop, prints a lot of things, but one of them is the column identifier, through the $col_identifiers array.
As soon as the foreach loop begins, it prints $col_identifiers[1] (that is, "name").
At the end of the foreach loop, $i++, so $i = 2.
Then on the second round of the foreach loop, it prints $col_identifiers[2] ("lastname"), and at the end goes $i++, so $i = 3, and on the third round of the foreach loop, it prints $col_identifiers[3] (age).

Now, the csv only has 3 columns. So the foreach loop ends, the closing row div tag gets printed, and the second round of the while loop starts. Before the foreach, it resets $i to 1 (in line 50), and then does its thing for the 3 columns again, and again and again 'til you reach the last row.
>>
>>295149
>>295153
Thanks once again
>>
>>295624
np
>>
>>294170
By the way I tried running this and got these errors

"name", 2=>"lastname", 3=>"age"); $ages = array(); while (($row = fgetcsv($handle, 1024, $delimeter)) !== FALSE) { ?>

Notice: Undefined variable: col in E:\xampp\htdocs\3.php on line 39

Amount of ages

$amount) { ?>
Notice: Undefined variable: age in E:\xampp\htdocs\3.php on line 62
:
Notice: Undefined variable: amount in E:\xampp\htdocs\3.php on line 62

>>292540
>an array called $ages counting the instances of a particular age in the 'age' row of your csv, located in the third column for example, with a conditional going

I'm currently working on putting some of the code you top lads have given me together, but get a few errors. If I'm understanding correctly, >>292540 is going to be a counter for each instance a specific entry pops up. Ages was just an example I gave, the csv file I do have has 20 or so columns per row, with both strings and integers. Is there a more efficient way of implementing this counter so it'd work for all columns? That is, if the first column was "First Name", it'd count the number of times John, Jacob, Charlotte, Tom etc would appear?

>>293118
>>294170
>>295149
These two seem to be what I need to get the data to print in a grouped manner (so all the "John"'s together, or if sorted by last name all the "Smith"'s), but I haven't managed to get it working yet.

I'm sorry a lot of this looks new to me even though the comments are massively beneficial in understanding what's going on
>>
File: 15 lines in python.png (25KB, 631x396px) Image search: [Google]
15 lines in python.png
25KB, 631x396px
>>292244
This is why you should be using a higher-level language than PHP.

https://pastebin.com/NaxFAXEP
>>
>>296404
>error messages
Mh. It might be because of the way I'm printing (that is, going out of PHP to print), and the way your php interpreter is configured.
http://php.net/short-open-tag

Open your php.ini (should be in either E:\xampp\php\ or in E:\xampp\etc\), and make sure the last instance of short_open_tag is set to On.

But if you don't want to change that, just echo instead. Change line 39 to:
echo $col;
and change line 62 to:
echo $age.": ".$amount."<br />\n";

>counter for more columns
Sure. Just use the same logic I used for the ages, and go one level up for the columns instead of the fields.

That is to say, instead of the unidimensional $ages array, use the $col_identifiers array as a list of keys. Or even better, turn it into an already keyed multidimensional array like
[code]
$col_identifiers = array(
'name'=>array(),
'lastname'=>array(),
'age'=>array()
)
[/code]
and, when you need the keys like in line 39 when printing the span class, get the key instead of the content.

Or, you know what? Here. Applied the multidimensional array idea, and removed the short open tags.
https://comfy.moe/wotuqa.zip

Study the differences between the two files. Notice specially how I'm using a multidimensional array (the new $col_identifiers) to preserve several columns instead of only one (like I did with $ages). And make sure to read the comments.

>>296520
You can do the same with php. You'd use str_getcsv and array_map.

I'm doing it like this to match OP's level.
>>
>>296586
>Notice specially how I'm using a multidimensional array (the new $col_identifiers) to preserve several columns instead of only one (like I did with $ages). And make sure to read the comments.
I think I'm understanding this, you've made it so it's working dynamically as opposed to with one instance.

I'm not sure what the key stuff is. Is that just to provide headers for each column? So the first row, which in the (brilliant) csv file you gave as "fname, lname, age", would be treated as the headers.
Or actually, looking at it further, is the key just the current value and it's using that as a way to count? So when the age is "9", that's the key?

I don't have titles in my CSV file, I assume lined 60-65 aren't necessary?

Thanks once again for all the help. It works fine with the data you provided, since my csv file has 20 or so columns per row it's giving me a few errors as of yet. I love the way you've done the breakdown of each column and the amounts, but is it at all possible for the first echo of all the data to be grouped by one of the columns? So if there were 3 "Nigger" first names, they'd be at top, followed by 2 "Tits" etc.
>>
>>296650
>I'm not sure what the key stuff is
A key is just the identifier of an array's value.
https://secure.php.net/manual/en/language.types.array.php

So yeah, when the age is 9, I either set a key=>value pair of 9=>1, or take $age[9] (that is, the value of the array $age with key 9) and add 1 to it.

>I don't have titles in my CSV file, I assume lined (sic) 60-65 aren't necessary?
Yeah.

I'd echo a title tag between lines 57 and 58 in that case.

>Thanks once again for all the help. It works fine with the data you provided, since my csv file has 20 or so columns per row it's giving me a few errors as of yet
Other than the css, nothing should have to be modified...

>but is it at all possible for the first echo of all the data to be grouped by one of the columns? So if there were 3 "Nigger" first names, they'd be at top, followed by 2 "Tits" etc.
Eh, I wouldn't use an array for that. It's not the adequate data structure.

For more complex manipulation like that, I'd make a database table mimicking the csv, and import the csv to it. Then I'd do what you want (easily, with order_by). But you need to learn mysql for that, or a framework to simplify it like codeigniter.

But if you HAVE to do it with arrays, then I'd go back to what you had at the beginning: I'd populate the array first, in the order you want, with one loop, and then I'd print it with another. But I won't be programming it for you because I just burnt my left hand making tea, and I'm having to type, slowly, just with the right one. Don't know how long it'll be out of commission. At least I can still fap...
>>
>>296683
>>296650
By the way, you should just follow some beginners php course. HTML, XHTML and CSS All-In-One For Dummies is one I've been recommending for years to complete novices (covers html, css, javascript, php and mysql), though I guess it should be just a bit outdated by now.
>>
>>296683
>I'd use a database and query engine to sort a spreadsheet
Jesus christ, just use an array and a comparison function.
>>
>>296699
Again,
>if you HAVE to do it with arrays, then I'd go back to what you had at the beginning: I'd populate the array first, in the order you want, with one loop, and then I'd print it with another

But it's not the adequate data structure to do those kinds of operations. It's very inefficient.
>>
File: a.png (45KB, 2142x718px) Image search: [Google]
a.png
45KB, 2142x718px
>>296683
>Other than the css, nothing should have to be modified...
See I thought that, it seemed robust enough to handle any CSV file but this is what I'm getting strangely

>>296683
>For more complex manipulation like that, I'd make a database table
Is there no way within PHP? I do know some mySQL, now that you mention it I probably could do exactly what you're asking but it seems like an odd workaround. Say if I loaded a different CSV file into the program, I'd have to change the code and make a new database wouldn't I?

>but if you HAVE to do it with arrays, I'd go back to what you had at the beginning
In the Pastebin, right?

>I just burnt my left hand making tea
Bloody hell what were you doing that's put your whole hand out of action? Sorry to hear that all the same, hope it heals quickly love. Was the tea worth the pain?

>>296686
Thanks
>>
>>296520
Also I appreciate the time you took to do this. Unfortunately I'm not very familiar with Python at all. I couldn't really get this script to run properly
>_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
>>
>>296702
>pic
It's because of the $col_identifiers array set in line 31. You're asking for the content of $col_identifiers[$curkey] in line 40, and $curkey = key($col_identifiers) in line 36. So everything goes fine for the first 3 columns (they get wrong classes though, but just that), and then it breaks for the rest.

You just need to edit $col_identifiers for your 20 columns.

>In the Pastebin, right?
Yeah. You had 2 loops that I nested.

>Say if I loaded a different CSV file into the program, I'd have to change the code and make a new database wouldn't I?
Yeah.

But again, you could just populate an array in the order you want in one loop, and then print it in another instead of doing it all at once.

>Bloody hell what were you doing that's put your whole hand out of action?
Pot slipped, open carboy heater faucet ran on my hand, in between my fingers.

Eh, it doesn't hurt anymore, at least. But it's green and sticky due to the ointment thing I rubbed. in it. Maybe it'll be back to normal in a few hours. And I'm now using my left thumb to write too.

>Sorry to hear that all the same, hope it heals quickly love.
Tits or gtfo.

>Was the tea worth the pain?
tbqdesu no.
>>
>>296703
It's in Python2, which isn't compatible with Python3 but confusingly has the same name.
>>
>>296701
So long as your comparator is O(1), your sort is still O(nlogn) for any dataset that fits in memory.

At least so long as you're using a competently-implemented sort, like the one that's in the standard library.

Are you expecting a .CSV file to take more memory than the entire MySQL engine?
>>
>>296728
Not memory. Processing.

Though now that I think about it, there's php excel libraries too that could take care of stuff like this.

https://github.com/PHPOffice/PHPExcel
>>
>>296709
>edit $col_identifiers for your 20 columns.
Ah, so basically have 20 "'name'=>array()"'s, though obviously with different values for each? Seems a bit inefficient, no? The second issue I'm having is the CSV file actually has 35 or so columns and having group data for all 35 of them seems largely unnecessary. Would I change $curkey or $col if I just wanted to group a specific column?

>Pot slipped, open carboy heater faucet ran on my hand, in between my fingers.
Sounds a right mess
>tbqdesu no.
Shame

Also, any pointers on how I'd present the grouped data in a table (the counts of each occurrence, that is)?
>>
>>296732
>Not memory. Processing.
If you don't understand Big-O notation, you probably shouldn't be talking about said.
>>
>>296726
>>296703
Here's a version with comments that works on both editions: https://pastebin.com/byMcJjmW
>>
>>296743
>Also, any pointers on how I'd present the grouped data in a table (the counts of each occurrence, that is)?
Draw the table you want with some example data, and group it with the row/column divs you want. Then, just set your css rules.

>Ah, so basically have 20 "'name'=>array()"'s, though obviously with different values for each? Seems a bit inefficient, no?
Nope. You need it to apply your css classes to draw it like a table.

You could use an ordered array instead of a hard-keyed one if you were, say, only counting the instances (though you'd be unable to present titles other than "column # 10"), but if you want to print it in table form, you need class names.

I'm using that array for several things there.

>The second issue I'm having is the CSV file actually has 35 or so columns and having group data for all 35 of them seems largely unnecessary. Would I change $curkey or $col if I just wanted to group a specific column?
No.

Let's say you only want 3 columns out of 35. You know they'll be the 10th, 24th, and 35th. So you use a counter and a conditional to fill your $col_identifiers only on the 10th, 24th and 35th iteration.

Of course, this also means $col_identifiers would only need 3 'key'=>array() pairs. But you need to know what each will contain and how many there'll be to use as identifiers.

>>296746
What I'm saying is you can't implement a sorting algorithm with php as which is as efficient as using mysql, because an array and a database are different, and a csv file is more akin to a database table.
>>
>>296759
You can WRT big-O complexity, which is all that matters with a dataset of this size.

If you use any nlogn sort and a comparator to do the sort in one pass, then the most embedding MySQL (or even Excel, FFS) can offer you is a linear speedup, which does not matter if the dataset is not gigabytes long.
>>
>>296759
>Let's say you only want 3 columns out of 35. You know they'll be the 10th, 24th, and 35th. So you use a counter and a conditional to fill your $col_identifiers only on the 10th, 24th and 35th iteration.
>Of course, this also means $col_identifiers would only need 3 'key'=>array() pairs. But you need to know what each will contain and how many there'll be to use as identifiers.

columns_I_want = map(itemgetter(9,23,34),entire_table)

Just sayin'.
>>
>>296761
Say that when you're iterating millions-long compromised password lists (ie rockyou) for crypto and are forced to wait 5 seconds per verification per registration/modification.

>>296767
Yeah, but we're trying to keep this on OP's level.

See first line here >>292540
>>
>>296759
>Draw the table you want with some example data, and group it with the row/column divs you want.
I've no idea why I said table, I meant a graph. Like a bar chart or something. Sorry. Would a table be easier? I reckon either works actually.
>you need class names.
So I go through and give each of the ~30 columns a class name? So I'd have something like
'1'=>array(), '2'=>array(), '3'=>array(), '4'=>array(), '5'=>array(), '6'=>array(), '7'=>array() etc...
But with names as opposed to numbers. Also where do you use these class names again? Because I tried implementing it like above but it screwed my spacing and everything just echo'd on top of each other like the first column here >>296702.

>Let's say you only want 3 columns out of 35.
I do want all the data displayed, I just don't want the "Amounts in" for every single column

>this also means $col_identifiers would only need 3 'key'=>array() pairs
Doesn't it handle things consecutively though, so if I wanted 3 I'd only get the first 3 colums rather than the 10th, 24th and 35th?

Also here's an example of the CSV file I'm working with
https://pastebin.com/2G2yz96j
Not that you have to look at it, just thought it might help give you a better idea rather than me mumbling on about 35 columns and 20 columns and ages.
>>
File: srsly.png (677B, 143x142px)
srsly.png
677B, 143x142px
>>296771
So long as your algorithm is right (and if all you're doing is giving the provided library a comparator, your algorithm will be right), millions of lines is absolute childsplay.

Just because you never did ADS, don't take it out on the language.

https://pastebin.com/daHKCERP
>>
>>296783
>8.5 real
>I mentioned empiric 5
Come on.

>>296781
>Like a bar chart or something
http://raphaeljs.com/

>So I go through and give each of the ~30 columns a class name?
No. You only need to give a name to the ones you want.

>where do you use these class names again? Because I tried implementing it like above but it screwed my spacing and everything just echo'd on top of each other like the first column here >>296702.
On the stylesheet. Between lines 4 and 21.

>I do want all the data displayed, I just don't want the "Amounts in" for every single column
Then you do need the 35 identifiers. Unless you want to output something like "amount in column #1" instead of "amount in 'name' column".

>Doesn't it handle things consecutively though, so if I wanted 3 I'd only get the first 3 colums rather than the 10th, 24th and 35th?
That's why you use a conditional (that is, an if statement) to only do whatever you need to do in the 10th, 24rth and 35th iterations.

>CSV file
That's fine as long as you know what each column you want to do something with has.
>>
>>296789
You're planning on re-sorting it every time? Why would you do that?
>>
>>296792
No. I just imported it to a mysql table, and do a get where in mysql to to see if it exists, and if it does, it doesn't verify.
>>
>>296789
>Unless you want to output something like "amount in column #1"
I'm fine with that

>on the stylesheet. Between lines 4 and 21
I see it, but does that also mean I'm going to have to create a .4-.35 if I want to echo out the entire CSV file? What I'm thinking now is that I use the pastebin I had to display the CSV, then have a button that displays the "grouped" information with the counters. So the "Amount in"

I'm still a bit unsure how to display the CSV file in a grouped order though (3 niggers first, 2 dicks second etc) and what kind of if would I be using to make it only work on the 10th, 24th and 35th?
$col_identifiers[$curkey][$col]
I feel like it's something around here
>>
>>296801
>does that also mean I'm going to have to create a .4-.35 if I want to echo out the entire CSV file?
if you want the columns to be properly formatted, sure.

Or you could just ignore the css ans print the raw csv with commas and all.

>I'm still a bit unsure how to display the CSV file in a grouped order though
On your populating loop, insert your row wherever it should be printed.

>and what kind of if would I be using to make it only work on the 10th, 24th and 35th?
Add an $i=1 between lines 34/35 with $i++ in 48/49, and add an if (in_array($i,array(10,24,35))) that would nest the array_key_exists($col,$col_identifiers[$curkey]) conditional between lines 40 and 47.
>>
>>296807
>print the raw csv with commas and all.
I wouldn't be able to group that though, right?

Also to clarify, am I repeating this
.age {
left: 400px;
}
for every column, or, at least, the ones I want printed out?

>on your populating loop, insert your row
Line 37?

>Add an $i=1
Thanks
>>
File: nosrsly.png (698B, 239x120px)
nosrsly.png
698B, 239x120px
>>296795
You're using an entire database engine instead of a hashtable?

Wow.

https://pastebin.com/nmjucFhg
>>
>>296795
I mean, don't get me wrong, if you've got to use MySQL anyway, you definitely use it (especially if you can use a stored procedure to save a round-trip), but to advocate it as a general-purpose array manipulator seems dumb.
>>
>>296814
>I wouldn't be able to group that though, right?
Not visually, no.

>repeating css
Yes, except you define how many pixels you want it to the left. If you leave it like that, they'll all be on top of each other.

No, this would be a whole different file, more similar to your original one with 1 loop populating an array and another printing the array.

>>296815
>>296816
I'm not advocating its use as a general-purpose array manipulator. Just if you need a csv-like structure.

But the hashtable idea has intrigued me. It makes so much sense... I'll give it a try, thanks for the suggestion.
>>
File "D:\Python\assign.py", line 16, in <module>
l = [ (firstname, lastname, int(age)) for (firstname, lastname, age) in list(r)]
File "D:\Python\assign.py", line 16, in <listcomp>
l = [ (firstname, lastname, int(age)) for (firstname, lastname, age) in list(r)]
ValueError: not enough values to unpack (expected 3, got 0)
>>
>>296807
I've managed to get it working so that only certain columns are displayed in the amount breakdown, which is fantastic.
My issue is that while the first three columns (I changed it to array(1,2,3))) ) correctly display the "Amount in Column Name", the sixth column is just displayed as "Amount in Column"

I'm not sure if I'm making sense desu.

>>296928
Meant to quote >>296747
>>
>>296935
Don't know the issue without seeing the code.

Going to bed though.
>>
>>296976
Goodnight. I'm mostly good at the moment, it's just that and trying to have the data printed in a grouped manner which I'm struggling on.
Think after that I'm mostly done, just got to mess with hash sums which I've no idea about but will look up.
I'll upload it
>>
>>296976
https://comfy.moe/bsnjmx.zip
>>
>>296976
>>297064
Actually never mind the column name thing. Just grouping I can't quite figure out.
Also writing to a file, I managed to generate a hash and output it to a file but rather than adding to the file it always seems to delete what was in there before
I'm after the hashing so I can detect when there's been a change in the file through the file hashes
>>
>>297090
Use the file's modification time.
>>
>>297092
To determine if it's changed? It has to be done through hashing
>>
>>297090
>>296976
Also I've noticed the counter doesn't take into account any '0' values. Any way to fix this?
>>
>>297095
To hash the file you have to read it in its entirety, so you already paid the cost of processing it, and so you might as well just process it every time.
>>
>>297108
I'm not sure I follow
>>
>>297132
You're checking the hash of the file so you don't have to read the file all the time.

To get the hash of the file, you need to read the whole file, so you're reading the file to avoid reading the file.

So your options are:

- check the modification time, which doesn't require reading the file
- subscribe to the file using File Alteration Monitor, which doesn't require reading the file
- just process the whole file every time, because it's the same amount of I/O as hashing it
>>
>>297142
I get you know. Even if what I'm doing is pointless, hashes are the way I'm advised to go about this which is why I'm keen on doing it that way, even if it's not actually optimum
I can write the hash to an external .txt file, but I'm not sure how to keep that hash in there, and then compare it with the next hash generated when the page is reloaded
>>
>>297176
get you now*
>>
Anyone have any ideas on how to make the counter include '0' values too?
>>
>>297337
>>297096
Really?
You start with $i=0 instead of $i=1
>>
File: dsadada.png (25KB, 509x950px) Image search: [Google]
dsadada.png
25KB, 509x950px
>>297341
Appreciate the assistance but I'm not sure I was clear enough, sorry
You see pic related? The "amounts in column 1"? Well, 0 appears multiple times in that column, but for some reason doesn't appear at all in the counter. These 0's are supposed to be accounted for, yet they're just ignored.
Does that make more sense or am I still waffling?
>>
>>297344
Because the conditional between lines 59 and 64 is ignoring the first counter array entry.

Delete that conditional (just leave the content of the else statement in the foreach), and add this between lines 56 and 57:
echo "<h3>Amounts in column ".$col_counter_key."</h3>\n";

There's also some issue with your fourth subarray. You have an empty array for the key "Six", and then the array that should go under "Six" with an empty space as key. Checking that.
>>
>>297365
>>297344
I don't know what the problem was. I didn't look for it much, because I changed the whole thing once I noticed how you are only saving data from 4 columns,, so it makes no sense to iterate all the columns and only save stuff on conditionals. Just iterate the needed 4 columns. It wasn't like that on the other one because the breakdown and the full column list were combined, but now that you have two separate scripts, iterating only what's needed makes sense.
https://comfy.moe/qepmvi.zip

Notice that the array is array(0,1,2,5) because, as automatic array keys start with 0, columns 1,2,3,6 become keys 0,1,2,5.
>>
>>297374
>>297365
I'm so sorry for wasting your time man, I switched it up in that time and have gone back to taking data from all the columns. Sorry I didn't mention.
Thank you so much on the title thing though. I saw it but didn't realise it was ignoring the first counter array and thought it was actually just setting the title from the Arrays created above.

I know you've mentioned it before, but any more tips on echoing the data in a grouped fashion? I've been looking online and just can't make sense of it, especially with the code that I had in the pastebin
>>
>>297383
just use array_multisort
https://secure.php.net/manual/en/function.array-multisort.php
>>
>>297390
I tried using
>array_multisort($list);
>var_dump($list);

But that's not it. What I'm having trouble with is understanding how this works when there are 40 arrays, each taken into account by column rather than row.
I'm clear in what I'm wanting to achieve, right? I know I talk shit sometimes
>>
>>297396
Read the link.

For multidimensional arrays in table style, you need to provide a column array. It's in the... let me see.. fourth example.
>>
>>297401
You mean the 3rd right
>>
>>297406
Yes.

How did that happen?

Anyway, I just tried with the fifth row, and it works. just fine. Just add a $column_to_sort_by = array(); before the while, a $column_to_sort_by[] = $row[4] at the end of the while, and array_multisort($column_to_sort_by,SORT_ASC,$data); after the if. Boom. Ordered by the fifth row.
>>
File: dsopdjsopj.png (92KB, 1416x1026px) Image search: [Google]
dsopdjsopj.png
92KB, 1416x1026px
>>297407
Guess I got the wrong idea. I was trying this
foreach($data as $priority => $entries ){
$volume[$priority] = $row[1];
$edition[$priority] = $row[2];
}

array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);

I mean, it grouped something, but there also seemed to be a lot of repeat values. Not sure what it did desu.

I did what you said and I'm clearly doing something wrong because it doesn't seem to group right.
https://pastebin.com/szagVwNP
It's like its almost there but isn't

Btw, how's the hand?
>>
>>297409
Wait. So what you want is for shit that's repeated to only be there once?

Change
$data[$numOfRows] = $row;
to
if (!in_array($row,$data)) $data[$numOfRows] = $row;

As for the hand... red and with a few small blisters where the water ran, but usable.
>>
>>297418
Oh, also, again, you don't need that counter. Just do $data[] = $row;
>>
>>297418
Nah, nah that's not what I want sorry

It's just not grouping right. You see the pastebin? That code is supposed to group by the 5th column, right? In the image the 5th column is 105, but there's a random 29 and 185 thrown in there, which happens through the whole grouping

>but usable.
Bettter, I guess
>>
>>297424
Your pastebin doesn't have all the information. But on my end, it's running fine.

Here.
https://pastebin.com/xcp77RAx
>>
File: thanks.webm (625KB, 1280x720px) Image search: [Google]
thanks.webm
625KB, 1280x720px
>>297435
Thank you kindly.
Might work on creating a dropdown box which lets me sort by any column.
By the way, any idea on the hashing stuff I was working on?
What I basically want is for the hash to be outputted to a text file and then checked each time the page loads to see if the hash is the same or if it is different if the file has been changed.
Honestly though, if you can't be bothered with any of that it's totally fine. You've helped so much and I appreciate the hell out of it. You're a real top lad.
I've got some shitty humble bundle games if you want any of them, nothing any good though
>>
>>297446
>What I basically want is for the hash to be outputted to a text file and then checked each time the page loads to see if the hash is the same or if it is different if the file has been changed
Hashing and ouptutting to a text file I'm assuming you already know how to do. Just, you know, hash_file and fwrite.

Checking if the csv has changed is also simple: hash the csv again with hash_file, and check this hash against your saved hash. If they're not the same, inform in the page, and overwrite your saved hash with your new one. Otherwise, ignore.

But again, this would be more efficient with a database instead of files.

>I've got some shitty humble bundle games if you want any of them, nothing any good though
Thanks, but I have tpb and torrentz2. And linux, so anyway.

I'd appreciate a bibliotik invite if you happened to have one though, but if you don't, that's fine. Can also trade bbt/jps/avistaz. Or hardware, hardware is always nice. Or my cock sucked. Or making america great again.
>>
>>297458
>check this hash against your saved hash. If they're not the same, inform in the page, and overwrite your saved hash with your new one. Otherwise, ignore.
This is where I struggle. See, I can write the hash to a file, but if I change the CSV file, the file that I saved the hash in just stores the new CSV hash.
This is how I went about it, but again, really you don't have to bother anymore.
https://pastebin.com/SxdVyv2h

>I'd appreciate a bibliotik invite if you happened to have one though, but if you don't, that's fine. Can also trade bbt/jps/avistaz. Or hardware, hardware is always nice. Or my cock sucked. Or making america great again.
Can't help you on any of those fronts. I'm in the UK anyway. What are you doing having Tea in Murica?
>>
>>297464
>I can write the hash to a file, but if I change the CSV file, the file that I saved the hash in just stores the new CSV hash
Because you have a conditional that checks if the hash file exists, and saves to it regardless.

Inside the else, read the contents of the hash file, make the new hash, and compare them. Then do a conditional where if they're not the same, echo your message and overwrite your hash file.

>What are you doing having Tea in Murica?
I'm in latin america actually. Central america. Coffee production central, ironically.

My mom was forbidden to drink coffee by the doctor for a while when I was a kid, and she had tea during that while. I got a taste for it, and I never really liked coffee. I then graduated from baggiess, and have been importing Twinings Earl Grey tins for some years.

And then I got betrayed by tea yesterday.
>>
>>297470
>Inside the else, read the contents of the hash file, make the new hash, and compare them. Then do a conditional where if they're not the same, echo your message and overwrite your hash file.
Thanks, I'll try this in a few.

And it wasn't the tea that betrayed you, he dindu nuffin. Interesting you developed a taste for it over there though. What biscuits you have with your tea?
>>
>>297485
Just sweet bread from the local bakers. Same with coffee really:
https://en.wikipedia.org/wiki/Pan_dulce

Interestingly enough, during easter, they make this kind of huge bread where they also use the egg yolks, called pan de semana santa. I'm eating some right now.
>>
>>297488
Never heard of it. Probably nice though. But, I mean, Bread's good and all but get some Custard Creams in there lad
>>
>>297490
We have them. Packaged though, not from the local bakers.

I'd rather have bread filled with custard. Mh. Yeah. Cream puffs. Oh my.
>>
File: worst.png (331KB, 700x3287px)
worst.png
331KB, 700x3287px
>>297491
I'll tell /fit/ on you
Have some damn biscuits
>>
>>297501
Hey, FUCK YOU, buddy.
Bread is AWESOME.
>>
File: 13642287542.gif (2MB, 1920x1070px) Image search: [Google]
13642287542.gif
2MB, 1920x1070px
>>297503
Shouldn't you be getting ready for bed?
Thread posts: 94
Thread images: 10


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.