sheriff Posted May 25, 2007 Share Posted May 25, 2007 hi all ... I have a long list generated from a while loop. --------------------------------------- |ID |Name | Description | --------------------------------------- |22 |product22 | desc22 | |56 |product56 | desc56 | |64 |product64 | desc64 | ---------------------------------------- it's possible to insert this list in a mysql database ? Thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/52938-multiple-inserts-in-mysql/ Share on other sites More sharing options...
jitesh Posted May 25, 2007 Share Posted May 25, 2007 insert into table (ID,Name,Description) Values (22,'product22','desc22') ,(33,'product33','desc33') ,(44,'product44','desc44') ......... Quote Link to comment https://forums.phpfreaks.com/topic/52938-multiple-inserts-in-mysql/#findComment-261422 Share on other sites More sharing options...
sheriff Posted May 25, 2007 Author Share Posted May 25, 2007 ok jitesh .. thanks now, please tell me how can I apply this to my situation This is the page where show up the generated product list. <form action="insert_order.php" method="POST"> <table border="1"> <tr> <td>Client <td> <?php $query = "select comp_id, comp_name from client"; $result = mysql_query($query); print '<select name="cmd_comp" style="background-color: #F89800; border: 1px solid #475558">'; while ($row = mysql_fetch_array($result)) { print '<option value="'.$row[comp_name].'">'.$row[comp_name]; } print '</select>'; ?><br><a href="add_client.php" style="text-decoration: none"><font size="2" color="#000000">Adauga clinet</font></a> </table> <br> <table bgcolor="#DDDAD4" cellpadding="1" cellspacing="1"> <tr> <td width="150" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Nume</strong></font></td> <td width="50" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Descriere</strong></font></td> <td width="50" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Buc</strong></font></td> </tr> <?php if(isset($_POST)){ if(count($_POST['check'])){ $list_selected = ""; foreach($_POST['check'] as $key => $ids){ $list_selected .= $ids .","; } $list_selected = substr($list_selected,0,strlen($list_selected)-1); // This will give ur selected ids like this 100,203,125,123 }else{ $list_selected = "-1"; } } $query = "select * from products WHERE pr_id IN (".$list_selected.")"; $result = mysql_query($query); $count = mysql_num_rows($result); $color1 = "#DDDAD4"; $color2 = "#DDD7CC"; $row_count = 0; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; $id = $row['pr_id']; $name = $row['pr_name']; $desc = $row['pr_desc']; $um = $row['pr_um']; ?> <tr> <td><input type="hidden" name="cmd_id"><input type="hidden" name="pr_id" value="<?php echo $id; ?>"> <input type="text" name="pr_name" value="<?php echo $name; ?>" size="30"></td> <td><font size="3"><input name="pr_desc" type="text" name="pr_desc" value="<?php echo $desc; ?>" size="50"></td> <td align="center"><input name="pr_qty" type="text" name="pr_qty[]" size="5"></font></td> </tr> <?php $row_count++; } ?> </table> <br> <input type="submit" name="submit" value="Adauga"> </form> and this is the insert query! mysql_query("INSERT INTO comenzi (cmd_id, cmd_comp, pr_id, pr_name, pr_desc, pr_qty, cmd_date, cmd_exp) VALUES (NULL , '$_POST[cmd_comp]', '$_POST[pr_id]', '$_POST[pr_name]', '$_POST[pr_desc]', '$_POST[pr_qty]', '$today', '$_POST[cmd_exp]')") or die(mysql_error()); you see, there is many <inpu type="text"> witha a name="something" ... i think it must be something[] .. but this is an array, and when i push the button to add it to mysql, only the last item will be inserted in the database. I want to make something like a shopping cart, but without payment, checkout. I want to enter my customer orders and they products in a database. thanks for help Quote Link to comment https://forums.phpfreaks.com/topic/52938-multiple-inserts-in-mysql/#findComment-261431 Share on other sites More sharing options...
jitesh Posted May 25, 2007 Share Posted May 25, 2007 Like this $insert_qry = " insert into table (ID,Name,Description) "; while(.....){ $insert_qry .= "Values (22,'product22','desc22')" .","; } $insert_qry = substr($insert_qry,0,strlen($insert_qry)-1); $result = mysql_query(insert_qry); Quote Link to comment https://forums.phpfreaks.com/topic/52938-multiple-inserts-in-mysql/#findComment-261436 Share on other sites More sharing options...
sheriff Posted May 25, 2007 Author Share Posted May 25, 2007 thanks i'll check it now Quote Link to comment https://forums.phpfreaks.com/topic/52938-multiple-inserts-in-mysql/#findComment-261438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.