0

Not that it matters, but here it is in Ruby.

Simple, elegant and concise. Dare I say, beautiful?

lower, upper = 20, 400

lower.upto(upper)
    .select{|i| i.modulo(3).zero? && i.modulo(4).zero?}
    .each_slice(5){|m| puts m.join("  ")}

.upto loops from the called number to the arg. Normally I'd have written this (lower..upper).select… but this makes it a bit clearer.

.select returns an array containing elements where the block returns true.

.each_slice iterates through the enumerable object in chunks (the first arg, 5 in this case) and executes the block for each chunk (printing the array joined by two spaces).

1

Keeping questions and scenarios fresh helps prevent lesser students (like this one) from just finding the answers online.

This problem has been solved hundreds of times, and there's an exact duplicate in this forum.

I don't mind helping but I like to see some effort first, not just pasting the question directly into a forum. If you want to help the OP do his homework without actually learning anything, go ahead.

0

This problem was solved like 40 years ago.

$ sort -t" " -rnk4 data.tsv
ascon1 201707015 Jack 97.5 11.5 11.5 11.5
ascon1 201707013 Josh 79.5 11.5 11.5 11.5
ascon1 201707011 John 77.5 11.5 11.5 11.5
ascon1 201707012 Grld 70.0 11.5 11.5 11.5
ascon1 201707014 Jess 67.5 11.5 11.5 11.5
  • -t" " to tell sort to split on spaces
  • -r for reverse (highest first)
  • -n to tell sort that it's a numeric field
  • -k4 to tell sort that we're loking at the fourth column
3

Yes, you can definitely normalise further, like with the nutrients approach @diafol suggests, but you need to know the data before making a judgement on whether it's worth it.

There are advantages and disadvantages in cases like that.

Votes + Comments
Thanks for the advise!
1

Should I turn those into an extra column or should they become seperate tables?

They should definitely be stored in a separate table (say, food_category) and you should add an appropriately-named foreign key to the table you posted (let's called that food).

In SQL, you'd use a statement like this to create the tables with the foreign-key relationship in place, note the references line:

create table food_category (
        id     serial primary key,
        name   varchar(32) not null unique
);

create table food (
        id          serial primary key,
        category_id int references food_category(id) not null,
        name        varchar(32) not null unique,
        calories    numeric,
        cholesterol numeric,
        sugar       numeric
);
0

I'd start by learning Java. Then SQL. When you've learned Java and SQL, then learn HTML. Now you've mastered those relatively simple subjects, just learn all of the glue that connects them together. Once you've done that, it's quite simple:

Your attendence is probably represented by a join table; a student attends a lesson. so your attendance table will contain student_id and lesson_id.

Now, on your HTML form you should generate a list of checkboxes for every student who might attend the class (probably based on their subject and grade, or whatever). The checkbox's value should equal the student's ID:

<input type="checkbox" name="attendance" value="2345"/>

When the form is submitted, only the checked checkboxes that are checked (i.e. those who have attended the lesson) will be included in the form data. Save each of the IDs you recieve as a row in the attendance table. Easy.

-1

True, and if she wants to continue and learn then fair play, and I hope she manages to build something great.

However, she's using a discontinued tool that outputs unmaintainable HTML, and developing her site clearly isn't her goal; letting people know about her jewelry (which looks fantastic, by the way Sanda) is.

Plus, as there's a products tab on her site, one would expect that some kind of 'web shop' is on the radar. That won't be doable in Webplus, and it's not the easiest thing to implement from scratch at the best of times.

-1

I'd suggest using something like SquareSpace for this kind of site, rather than attempting to build it yourself. It has an e-commerce module built-in and plenty of easy templates to choose from.

A note unrelated to the original question, when at 100% zoom, I can only see 2/3 of the page, I need to scroll right to see the whole thing (or zoom out to about 80%).

0

I doubt it's your query that's slow. What happens if you simply run the query select * from Doopgegevens; in a shell? For ~10k rows, providing your table is holding 'normal' data (and not base64 encoded movie files or something) it should be fast. If it is fast, try changing your data list to only use a subset of your table's columns, which will indicate if that's where your performance problem is.

0

[QUOTE=red_ruewei;1694533]thanks for reply.
I try something like this to read record with range month and year.
Example from June, 2011 to June 2012
[CODE]
Select * from table where (YEAR(date1)>='$year1' AND MONTH(date1)>='$mon1') and (YEAR(TKH_date1)<='$year2' AND MONTH(TKH_date1)<='$month2')
[/CODE]

i had test this. And run separately.
[CODE]
(YEAR(date1)>='$year1' AND MONTH(date1)>='$mon1')
[/CODE]
For above code it run smoothly

[CODE]
(YEAR(TKH_date1)<='$year2' AND MONTH(TKH_date1)<='$month2')
[/CODE]
But for this code, it fail....

TQ[/QUOTE]

Fails why? What error? What variables? Also, by calling YEAR(blah) you're going to bypass your indices and your query will be slow. Something like this is better and will work.

[code=mysql]
SELECT * FROM table WHERE date_data >= '2011-06-01' AND date_data < '2011-07-01';
[/code]