Helped a lot by people from this forum, here is our website:[URL="http://www.libromania.cl"]http://www.libromania.cl

As you can see, we offer school textbooks.Now books season is starting here, and I need to publish books lists. It is, for every school working with us, we have to publish the corresponding books that every student has to have next season, and give to the parents the individual price per book and also the total amount of money to pay.The problem is, what happens if one person doesn't need one book, he will want to buy all books but one. Then, I need a table where the book titles and prices are, and also having a check for every item, and when one item is unchecked, the total amount of money to pay also changes accordingly.

Thanks a lot!!!

felgall
—
2011-10-14T01:01:42Z —
#2

This question is posted in the wrong place. Which server side language are you using to process the orders? If you tell us that then the post can be moved to the appropriate forum where people familiar with that language will be able to help.

Sir_Arcturua
—
2011-10-14T03:37:18Z —
#3

I'm really sorry for that.I used PHP for making a function to send e-mails.

felgall
—
2011-10-14T07:53:40Z —
#4

Moved to the PHP forum where it is more likely to get lots of answers.

Cups
—
2011-10-14T09:11:14Z —
#5

Big question.

First off, you can accomplish what you want with Javascript, PHP or a combination of both.

As a programmer you do not want to trust anything coming from the internet, that includes Javascript values - you use JS to make the shopping experience nicer and more responsive for those that have JS turned on on their browser.

Start off by forgetting about clever Javascript solutions -- what you have to start with is the basic HTML form elements and PHP.

Copy that simple script and run it, fill in different values and make sure you understand how checkboxes and PHP work.

Starting from there, you then go on and make $rows an multi-array which also contains prices, say.

But, the html only ever passes back to PHP a list of book ids (say 1 and 2 only), which when the form is posted, PHP queries the database for the prices of books 1 and 2, and passes back to the user the prices which PHP has totalled up.

so even if the user sees:

[checkbox] - Textbook One - $12.99[checkbox] - Textbook One - $10.99

You do not send prices back from the interface to PHP.

The next steps you take might be to show us how you store books, id, titles and prices - in a database?

Sir_Arcturua
—
2011-10-14T13:17:17Z —
#6

Thanks alot for your help!!!

About the page, it is very simple ... we have no database. It only shows stuff in HTML with CSS. The only PHP code is a small server side code for sending e-mails e-mail from the contact form page using mail() function in a separate .php file.

I will be checking and testing the code you sent me in order to learn how to work. Is it possible to use it without database? I mean, make the calculations in the table itself and not just publish the values calculated externally?

The final goal of all this is to have a final amount for payment in a variable for using it as an input in any online payment method, for instance Paypal.

Thanks again!!!

Cups
—
2011-10-14T15:39:45Z —
#7

The nub of my point was this:

That you can write in HTML all the prices and descriptions you want, but some unscrupulous person can change the total to 1 penny, and submit that to your email script, and to your paypal account, so you have to work out the full price on the backend (in PHP).

If you are just dabbling with PHP and don't want/need a database you could just have a multi-array and maintain it by hand, put that in a file called books_array.php

** you might want to do this first, kind of "are you sure you want to order all these books for $xx.xx?"

I have just pseudocoded roughly what order.php should do, but you should get the gist, that you maintain a single array of books, but that it serves 2 purposes - to generate the html list, and to provide something to generate the prices from.

We can fill out those lines of pseudocode when you have got had a play with that and got some more realistic data loaded, filled out your html page and so on.

Sir_Arcturua
—
2011-10-14T23:25:25Z —
#8

Great!! Thanks a lot!

I will start working on it and keeping you posted.

Sir_Arcturua
—
2011-10-15T00:00:43Z —
#9

Done by now!

I copied the code n two files and uploaded them. It is working fine, as you can see in:

The point is I was not clear enough, so there is something else I need to ask you.The idea of our website is not to offer a list of many books to every person to pick some of them ... but, every school defines the books for every grade for next school season, so parents have to buy texts according to grades of their children.

So what indeed we have is many small predefined lists, one per grade per school.We are implementing one webpage per school, it is, when parents select a school, a new webpage is displayed with a list of all grades(here we have 12 grades) from 1 to 12, so when they select one of them, a new webpage is opened, with the small list of textbooks indicated by the school for this specific grade.

In other words:step 1: parents access websitestep 2: go to customers -> school where their children studystep 3: select the grade where their first child will attend next school seasonstep 4: a list of texts defined by the school for this level is displayed, all checked and ready to checkoutstep 5: it is possible to uncheck one or more textbooks, if desiredstep 6: checkout

Sorry for my lack of explanation. What I try to say is according to the grade and school, a different textbook list will be displayed.

Thanks a lot!!

Cups
—
2011-10-15T12:42:35Z —
#10

The idea of our website is not to offer a list of many books to every person to pick some of them ... but, every school defines the books for every grade for next school season, so parents have to buy texts according to grades of their children.

Well you are miles away from nailing that problem if you need me to explain how a html form and a simple PHP array work.

Not trying to put you off -- just to give you a reality check -- and to ask what is your first goal?

(plus, how do you do this task at the moment then?)

Sir_Arcturua
—
2011-10-15T12:50:20Z —
#11

Hi,

About your last question, we are starting selling to parents, so we need to implement this now.

The first goal is to be able to show for every person, textbooks according to his/her child (selecting school and grade), and offering an online payment method.

Thanks a lot!!

Sir_Arcturua
—
2011-10-15T13:42:58Z —
#12

Is it possible, for instance, try this?:- create different "books_array_nn.php" files, one per grade- have a webpage per school with all grades, each one linking to the corresponding table, in order to show it properly- allow people to unclick textbooks- proceed with checkout

Are you saying that Grade 6, say, for all schools is the same list of books?

If so then yes, that would be a good way to start - have different named arrays, just give them an easy to remember name:

$books_grade_6 = array() // etc

Sir_Arcturua
—
2011-10-15T18:51:04Z —
#15

Hi!!

Unfortunately, texts lists for same grade are not the same for different schools, but at this moment we have only one school where parents will purchase us directly from website (others schools purchase from us directly and provide books to the parents).I agree that this way is not a long-term solution if more schools use it, but I guess it is easier than do it using a database, and allow me to know more about PHP/HTML, and maybe better prepared to implement a database solution as a next step.

About integrating HTML in a .php file, please considerate I have defined sections and include them in other .shtm files using #include. I guess this format is wrong for .php files, as they recognize those includes as comments, as in this case:

Could you please let me know the right format? Should I avoid using #include sentences?

Thanks again!!!

Sir_Arcturua
—
2011-10-15T21:22:43Z —
#16

Hi again!!

I was wandering about this situation, and I guess one possible solution is:to have one .php file with all text lists for all levels of one schoolto have a webpage with radiobuttons, in order to select the desired gradedepending the selected grade there is a variable with a certain value, and a based on this variable, a new page with the corresponding table is displayed

Sounds it good?Please take a look to the code I sent you in my last e-mail. There is something I am making wrong including html sentences in a .php file.

Thanks a lot!!!

Cups
—
2011-10-16T10:46:59Z —
#17

I'm not familiar with #include - I have not used anything like that for a long time.

Your idea with radio buttons to choose a single grade is a sound one, though you could use a select box too.

Yes, you do need to look into using a database this may sound daunting, but it is quite easy to grasp as long as you give yourself long enough time to digest and understand the rules that apply and the specialist terms used -- then you will be in a good position to ask pertinent questions(the Mysql forum on Sitepoint is very very good).

Your PHP/HTML will not care whether it is iterating through a PHP array from a csv file, database or a hand-maintained array - so you still have to keep improving that and thinking about what you want to get from your application.

e.g.

how are you going to store orders?how will you maintain each school/grade/books list?will you eventually permit the schools to login and alter their own grade/books lists?

You need to think big, but start small as you have done.

Sir_Arcturua
—
2011-10-16T14:38:55Z —
#18

Hi,

I guess you are right. I will start dealing with databases. Could you please suggest a website/online course for noobies?