I have a table with quite a few columns. The total number of columns is not yet specified, and will change on a regular basis.
In my insert query, I only need to put two values into the table. All other values will be ' '. is there a way to only specify the first fields, without having to include '','','',''...? Please see below for example:
I would like to have this:
$query = mysql_query("INSERT INTO table VALUES('','$id')");
Rather than this:
$query = mysql_query("INSERT INTO table VALUES('','$id','','','','','',''......and on and on...)");
Is there a way to do this? Thanks!
INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of comma-separated column values, with lists enclosed within parentheses and separated by commas.
First, you must specify the name of the table. After that, in parenthesis, you must specify the column name of the table, and columns must be separated by a comma. The values that you want to insert must be inside the parenthesis, and it must be followed by the VALUES clause.
Syntax. The syntax to add a column in a table in MySQL (using the ALTER TABLE statement) is: ALTER TABLE table_name ADD new_column_name column_definition [ FIRST | AFTER column_name ]; table_name.
Insert Mutliple values in a single Field: For inserting the flat no's in a single field, use implode and the values separated by comma. For retrieve the values from database use, explode to separate out all the values.. For Retrieve the values using $i=explode(",",$r);
Yes, specify the column names after the table name:
INSERT INTO table (column1, column2) VALUES ('','$id')
I'd prefer
INSERT INTO table SET columnA = 'valueA', columnB = 'valueB'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With