Page 1 of 1

Present list, is this possible?

Posted: Sun Mar 28, 2004 8:10 am
by magdi
Hello,

First of all I'm a beginner at php/mysql, so that's why my 'logic' might not be correct.
What I want to do is get our baby presents list online so friends that live far away can choose a present and order it by email.

I have a mysql database with two tables:

a) presents (id;name;fk_customer;sold_yn)
b) customers (id;name;email)

By running a query on sold_yn (=1 or 0) I have a php page that shows me a table with the presents that haven't been selected/sold yet.
I've added a new column to this table with a check box (guess that's my first mistake).

Under the table there's a form with input fields for the name and email of the customer (who will be our friends) and a submit button.

What I'd like to happen is that visitors can check/uncheck the presents they choose, fill in the form underneath the list and then press submit.

By pressing submit they would receive a thankyou email, the shop would receive an email with the order and the database would be updated.

the database update

This is how I would do it in a regular database I'm used to work with:

- the customer info is inserted in the database, the new customer id is stored in a temporary field.
- then there would be a loop on the table to see what records are checked. (id of checked presents stored in a variable? But I don't now how to do that because how am I going to name this variable and it changes row by row...aaargh, so I would need an array or something)
- these checked records are updated in the table (fk_customer- that's just been added to the database and who's id is in a temp field, I guess a variable; sold_yn = 1) - I know the second field is not really necessary but I'd like to keep it that way.


the emails
- one thankyou email is being send to the customer
- one order email is being send to the shop

Can anybody help cause I'm stuck. As far as I understood only records in a form can be updated, but my results appear in a table. Grrrr...I'm going crazy. Do I really have to zoom in the product (with a link or so), then update and then go back to the main page.

I realise this is a long question but if you could put me in the right direction it would be great!

Thank you, thank you, thank you.

Posted: Sun Mar 28, 2004 11:15 am
by tim
i guess i'll tackle a few aspects.

You can change as many fields as you wish within a SQL table, check out the UPDATE command.

You can sort thru your presents via checkbox (as u said) but you must turn the form into an array so you can send > 1 variables.

Changing a field from 0 to 1 would be simple, heres an example.

Code: Select all

<?php
$sql = "UPDATE table_name SET field=1";
$results = mysql_query($sql);
//this would change field from 0 to 1.
?>
if this wasnt what you was requesting help for, i apologise in advance.

Posted: Sun Mar 28, 2004 11:50 pm
by magdi
Thx Tim,

But it wasn't exactly what I meant, most of what you told me I know.

What I'm confused about is the fact that my presents appear in a table and as far as I've figured out I need a form (as you mention) to make changes. Is it possible to show query results in a form instead of a table?

There is a part that is usefull in your answer, the fact I should turn my 'form' (as soon as I know how to turn my table with results into a form) into an array.
How do you do that? If you don't feel like explaining maybe you know an online tutorial to explain me.

Posted: Mon Mar 29, 2004 8:47 pm
by tim

Code: Select all

<?php
$sql = "select * from table_name";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {

// make your form and have the following 
echo "<input type=text name=tim[] value=$row>";
}
?>
Note this is generic and un-tested, the theory if there.

notice the name=tim[], this turns the form into an array.