473,668 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

For Each with 2 different arrays

25 New Member
hi guys.. can anyone help me with that staff?

here is my code..
$cart = $_SESSION['cart'];
$action = $_GET['action'];

switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['id'];
$type .= ','.$_GET['type'];
} else {
$cart = $_GET['id'];
$type= $_GET['type'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$ca rt);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
}
$_SESSION['cart'] = $cart;
$_SESSION['type']=$type;
function writeShoppingCa rt() {

$cart = $_SESSION['cart'];
$type= $_SESSION['type'];
if ($cart) {
$items = explode(',',$ca rt);
$types=explode( ',',$type);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($content s[$item])) ? $contents[$item] + 1 : 1;
}


$output[] = '<form action="cart.ph p?action=update " method="post" id="cart">';
$output[] = '<table>';
foreach ($contents as $id=>$qty) {

$sql = 'SELECT * FROM tracks WHERE v_id = '.$id;
$result = mysql_query($sq l);
$row = mysql_fetch_obj ect($result);
//extract($row);
$output[] = '<tr>';
$output[] = '<td><a href="basket.ph p?action=delete &id='.$id.'" class="r">Remov e</a></td>';
$output[] = '<td>'.$row->title.'</td>';

$output[] = '<td><input type="text" name="qty'.$id. '" value="'.$qty.' " size="3" maxlength="3" /></td>';
$output[] = '</tr>';
}
$output[] = '</table>';
//$output[] = '<div><button type="submit">U pdate cart</button></div>';
$output[] = '</form>';
} else {
$output[] = '<p>You shopping basket is empty.</p>';
}
return join('',$output );
}



echo writeShoppingCa rt();


in the result i have got the title of the track tha have been added to the basket and how mush times the user added it to the basket..
Now i am getting and another value which is the type of the track .
example. <a href="basket.ph p?id=19&type=2" >Add to basket</a>
i am storing this value to the _session['type'] and i want to have this result.

Title
Norah Jones //Which id=12

Number 0f Clicks
12 //Which is the $gty value

Type
2 //the value of the session.. that id=12 when the user clicked


Can anybody help me..
thanks you..
i hope you understand what i want..
Nov 8 '06 #1
1 1983
billkirim
25 New Member
hi guys.. can anyone help me with that staff?

here is my code..
$cart = $_SESSION['cart'];
$action = $_GET['action'];

switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['id'];
$type .= ','.$_GET['type'];
} else {
$cart = $_GET['id'];
$type= $_GET['type'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$ca rt);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
}
$_SESSION['cart'] = $cart;
$_SESSION['type']=$type;
function writeShoppingCa rt() {

$cart = $_SESSION['cart'];
$type= $_SESSION['type'];
if ($cart) {
$items = explode(',',$ca rt);
$types=explode( ',',$type);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($content s[$item])) ? $contents[$item] + 1 : 1;
}


$output[] = '<form action="cart.ph p?action=update " method="post" id="cart">';
$output[] = '<table>';
foreach ($contents as $id=>$qty) {

$sql = 'SELECT * FROM tracks WHERE v_id = '.$id;
$result = mysql_query($sq l);
$row = mysql_fetch_obj ect($result);
//extract($row);
$output[] = '<tr>';
$output[] = '<td><a href="basket.ph p?action=delete &id='.$id.'" class="r">Remov e</a></td>';
$output[] = '<td>'.$row->title.'</td>';

$output[] = '<td><input type="text" name="qty'.$id. '" value="'.$qty.' " size="3" maxlength="3" /></td>';
$output[] = '</tr>';
}
$output[] = '</table>';
//$output[] = '<div><button type="submit">U pdate cart</button></div>';
$output[] = '</form>';
} else {
$output[] = '<p>You shopping basket is empty.</p>';
}
return join('',$output );
}



echo writeShoppingCa rt();


in the result i have got the title of the track tha have been added to the basket and how mush times the user added it to the basket..
Now i am getting and another value which is the type of the track .
example. <a href="basket.ph p?id=19&type=2" >Add to basket</a>
i am storing this value to the _session['type'] and i want to have this result.

Title
Norah Jones //Which id=12

Number 0f Clicks
12 //Which is the $gty value

Type
2 //the value of the session.. that id=12 when the user clicked


Can anybody help me..
thanks you..
i hope you understand what i want..
ok i find it.. i used pointers to move the type arrays to the exactly where i want
thanks
Nov 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3450
by: Dariusz | last post by:
I want to use arrays in my website (flat file for a guestbook), but despite having read through countless online tutorials on the topic, I just can't get my code to work. I know there are guestbook scripts out there - but that doesn't help me learn how to programme arrays !!! The following is the code for the PHP (called externally), which does execute...
4
2824
by: Mingus Tsai | last post by:
Hello- please help with unpickling problem: I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows XPhome system. My problem is with using cPickle to deserialize my pickled arrays of datetime.datetime instances. The following is the code I have written: import cPickle, datetime import Numeric
1
2198
by: rir3760 | last post by:
Since a few days ago I have been working with the program I post below (a school assignment). The purpose of the program is to work with the va_ macros (stdarg.h) and arrays of arrays, hopefully learning a little bit in the process. The objective of the fn_memset function is to set all the chars in the arrays passed (of type array N of array M of char) to a specific char, somewhat similar to what the standard function memset does:
32
6508
by: Joe Rattz | last post by:
Hmmm, I wrote the following code. I want an array of bools and I want to intialize them to false. bool bits = new bool; foreach(bool bit in bits) { bit = false; } The compiler complains on the "bit = false;" stating that bit is read-only.
2
3355
by: Thomas Connolly | last post by:
Anyone know if there is a C# equivallent to: enum { LIFFE_SIZE_AUTOMARKETREF = 15 }; typedef char LiffeAutoMarketReference ; Thanks,
39
19619
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1) What's the difference between these 3 statements: (i) memcpy(&b, &KoefD, n); // this works somewhere in my code
4
9604
by: chy1013m1 | last post by:
In Java, one can do the following: int array = {{1,2,1}, {1}, {0,0,0,0,0,0,0,-1}}; How can one declare such array in C++/C without using various new operators individually to each row indicies? (with a ptr-ptr) Also, I've noticed that it works for char array: char *charArray = {"123456", "1515", "1"}; compiles on mingw32 but int *intArray = {{1,2,1,2,1}, {11}, {0}}; wouldn't compile. thanks =]
19
2448
by: Jim West | last post by:
The execution speed of the following code is dramatically faster if I declare some arrays globally rather than locally. That is FOO a, b, c; void bar() { ... } runs much faster (up to 33%) than
2
4329
by: jwhite68 | last post by:
The essence of my problem is this. 1. I login to my website with user/password. 2. I select any option, which effectively re-calls index2.php with some additional parameters, to control whats displayed next. Immediately at this point, it logs out the user. It is logging out the user because after checking $_SESSION == '1' - it finds that its not 1, and therefore displays login section again and a related message. The website is being...
6
1902
by: Emiurgo | last post by:
Hi there to everyone! I've got a problem which may be interesting to some of you, and I'd be very grateful if there is someone who can give me some advice (or maybe redirect me to some other place). Very brief introduction. Since I'm learning vectorization with SSE (I use gcc 4.1.3 on Ubuntu 7.10) I've built a simple test program in C for comparing running times. I wanted to see how much improvement could give vectorization to simple...
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8378
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8890
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8653
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7398
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.