Jump to content

request help creating simple function


whitehat

Recommended Posts

Hello @all
I'm having a problem creating a function for a deletion and inserting from 1 to another database table.
Below are some sql query's to give you an idea of what i try to do:

[code=php:0]
function orders() {

$mysample1 .= $db->sql_query("select * from cart inner join calendar on cart.products_id = calendar.calendar_id where cart.cookieId = '" . Getbasket_id() . "' and main_id = '$Pid'");
$mysample2 .= $db->sql_query("insert into orders(user_id, products_id, booking_date, qty) values('$uid', '$products_id', now(), '$qty')");
$mysample3 .= $db->sql_query("delete from cart where cookieId = '" . Getbasket_id() . "' and products_id = $products_id");

}
return $mysamples;

$content .= "<div><a href=\"#\" onclick=\"$mysamples\"><img src=\"modules/Fly_to_Basket/images/order.gif\"></div>";
[/code]
on top is just to give an idea pls dont laugh lol.
i really have no clue how to go on
below i add the db examples if it is needed to help me out:
[code]
CREATE TABLE `cart` (
  `basket_id` int(11) NOT NULL auto_increment,
  `cookieId` varchar(50) default NULL,
  `products_id` int(11) default NULL,
  `booking_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `qty` int(11) default NULL,
  PRIMARY KEY  (`basket_id`),
  UNIQUE KEY `id` (`basket_id`)
) TYPE=MyISAM

CREATE TABLE `orders` (
  `orders_id` int(11) NOT NULL auto_increment,
  `user_id` int(11) NOT NULL default '0',
  `products_id` int(11) default NULL,
  `booking_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `qty` int(11) default NULL,
  PRIMARY KEY  (`orders_id`)
) TYPE=MyISAM
[/code]
Link to comment
Share on other sites

i'm not sure i completely understand, but usually, you'll have to have something like this if you're doing multiple inserts based on a query:
[code]
<?php
$sql = mysql_query("SELECT * FROM table1");
if (mysql_num_rows($sql) > 0) {
  $results = array();
  while ($row = mysql_fetch_row($sql)) $results[] = $row;
 
  // connect to database for insertion here
  // now that you have your new connection, insert the records
  foreach ($results as $row) {
    $q = "INSERT INTO tableName VALUES ('" . implode("', '", $row) . "')";
    mysql_query($q);
  }
}
?>
[/code]

you probably would want to update this to allow for some error checking/catching, but at least you can get the idea.

good luck
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.