Re: Unable to send variables to MySQL table

From: Date: Wed, 09 Nov 2005 22:47:00 +0000
Subject: Re: Unable to send variables to MySQL table
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-225475@lists.php.net to get a copy of this message
Stewart Priest wrote:
<snip> What is the structure of that table? </snip> +---------------+--------------+------+-----+---------+-------+
| Field         | Type         | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| invoice_no    | int(10)      | YES  |     | NULL    |       |
| item1_desc    | varchar(255) | YES  |     | NULL    |       |
| item1_cost    | float        | YES  |     | NULL    |       |
| item2_desc    | varchar(255) | YES  |     | NULL    |       |
| item2_cost    | float        | YES  |     | NULL    |       |
| item3_desc    | varchar(255) | YES  |     | NULL    |       |
| item3_cost    | float        | YES  |     | NULL    |       |
| item4_desc    | varchar(255) | YES  |     | NULL    |       |
| item4_cost    | float        | YES  |     | NULL    |       |
| delivery_cost | float        | YES  |     | NULL    |       |
| customer_id   | int(10)      | YES  |     | NULL    |       |
| comments      | varchar(255) | YES  |     | NULL    |       |
+---------------+--------------+------+-----+---------+-------+
This is not a good structure. Have you thought about taking item* columns to a separate table? Table invoices: +---------------+--------------+------+-----+---------+-------+
| Field         | Type         | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| invoice_no    | int(10)      | YES  |     | NULL    |       |
| delivery_cost | float        | YES  |     | NULL    |       |
| customer_id   | int(10)      | YES  |     | NULL    |       |
| comments      | varchar(255) | YES  |     | NULL    |       |
+---------------+--------------+------+-----+---------+-------+ Table invoices_items: +---------------+--------------+------+-----+---------+-------+
| Field         | Type         | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| item_no       | int(10)      | YES  |     | NULL    |       |
| invoice_no    | int(10)      | YES  |     | NULL    |       |
| item_desc     | varchar(255) | YES  |     | NULL    |       |
| item_cost     | float        | YES  |     | NULL    |       |
+---------------+--------------+------+-----+---------+-------+ And columns should be able to hold NULL values only if they can be empty. I'm sure you don't want invoice_no to be NULL ;)

« previous php.general (#225475) next »