Jump to content


request help creating simple function

  • Please log in to reply
1 reply to this topic

#1 whitehat

  • Members
  • PipPip
  • Member
  • 18 posts

Posted 19 October 2006 - 11:08 AM

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:

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>";
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:
  `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`)

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`)

#2 obsidian

  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 19 October 2006 - 12:53 PM

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:
$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) . "')";

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

good luck
You can't win, you can't lose, you can't break even... you can't even get out of the game.

while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users