How Do I Delete Items From Array?
I can add several items to the basket, but how do I delete one from the basket? I want to delete any of the added items. Here is my code for creating the array and adding items to it.
// creating the array
$item = array();
$item['id'] = "1";
$item['price'] = "100";
$item['quantity'] = "1";
// add item
$_SESSION['basket'][] = $item;
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Add/Delete Items
I have the following code, that displays a message whether a users shopping cart contains items or not. How do I add/delete items from the shopping cart, upon the appropriate product link being clicked? If a items is already in the cart, how do I display a message notifying the user? Code:
How Many Items Are In An Array?
I dont know how many values there are in my array after it's been split.. is there a command? array_count_values doesnt do what I need sadly.
Display All Array Items
How do I display all the items within an array? Also, how do I delete a particular item from an array?
Compare Items In An Array...
I have been getting on fine with basic coding until I stumbled accross a problem. I cant seem to figure out how to check to see if a value in one array is in another array - and if so just simple report back "true" or "false". Lets call the two arrays LOCKS and KEYS. Doing a print_r($locks) would give: Code:
Adding Only Unique Items To An Array
I've made a small code snippet that adds a new item ($value = $_GET) to an array in a cookie. My main question is in the title of the post, and I have a related one: How do I delete a specific value from the array and shift all the other values down to fill its place? Will this happen on its own? And one more: Using this code I display the array values in descending order; foreach ($_COOKIE['best'] as $name => $value) { $best = urlencode($value); echo //insert code here } } Is there any way to display this in ascending order?
Counting Items In An Array Having X Attribute
I want to randomly select 5 cards from a standard playing card deck and count how many of each suit are returned: [connect] $sql = "SELECT * FROM cards ORDER BY RAND()LIMIT 5"; $result = mysql_query($sql); while($cards = mysql_fetch_array($result)) { $value = $cards["card_value"]; $suit = $cards["card_suit"]; $image = $cards["card_image"]; -------- Using count() within the loop returns a count of 1 since each card can only be of one suit. I tried using something like this: $spades = 0; if($suit='spades') { $spades = $spades+1; } and I tried a foreach statement to count within the loop which always returns a count of 1. Would someone be so kind as to point me in the right direction?
Trying To Return Mysql Array Items From Function
I am writing a calendar script which returns events, holidays etc.. from MySQL for days with events. This was easy BUT then I tried to return multiple events on some days and thats where I am stuck. I found some examples of returning arrays from functions from functions but they all use some form of array(Ƈ',ƈ',Ɖ') and then use a for loop... I am using mysql_fetch_array so this does not seem to work... First, here is some of the code from the function where I am returning the value: PHP Code:
Check If Any Items In An Array (php) Is In A Table (mysql).
I want to check if any of the items in a PHP array exist in a MySQL table. What is the best way to do this with making repeated calls to the database for each item? Actual application is: I have an array (in PHP) of serial numbers of units about to be shipped.I want to check the ship record (a table in a MySQL database) to check if that serial number has been used before. According to our quality policy we never reuse serial numbers, serial numbers are unique. So prior to printing the packing slip I want to warn the shipping guy/gal a serial number may be incorrect. I could brute force it and increment through the "to be shipped array" and check each item against the table. But that is, as I said brute force, and I am having to be concerned with system speed lately.
Remove Items From Array, Shift Positions
Hey, lets say I have: x = array("red", "blue", "green", "yellow", "orange", "grey"); Now lets say I have a loop that prints out what is in the array. I want to be able to remove blue green and yellow, but effectively shift down everything else in the array (in this case orange and grey) so that orange is now positioned relative to where blue was and grey is where green was. By this I mean x[1] = "blue" and x[2] now quals "grey". How can I do this?
Delete From Array
let's say I have an array $letters(a,b,c,d,e,f) is there a function that will remove 'd' from the middle. I'm looking for something like array_delete($letters,'d');
Delete/drop Value From An Array
Hi, I have an array of values that I am matching against a string and I want to drop the value from the array if it is in the string. My array looks like: 0=>val1, 1=>val2, etc I understand how to check to see if the value is in the array, but not how do get rid of it if it is.
Delete Array Element
How can i delete an element from one array. Let us suppose that i've an array of 10 elements $a[0], $a[1], $a[2]...etc And when i delete $a[2] i wanna the elements to be re-ordered like this $a[0] will be the same $a[0] $a[1] will be the same $a[1] but $a[2] will be the $a[3] element i had before deleting $a[2] It would be called in Delphi, HOW TO DELETE AN ELEMENT FROM A COLLECTION? Is this possible? Have i to use another type of data? Hope you've understood the idea.
How To Clear/delete An Array?
I am using an array in a loop, and every time I loop I need to have the array be empty. I cannot find an array function to empty the array, or clear it. Have I missed something somewhere ( I suspect I have) ?
Safe To Delete Elements Of Array In Foreach
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to a temp array and delete afterwards if necessary but since I'm actually working in a nested situation this could get a little messy. I guess I could set there values to
Related Items
I noticed a lot of websites show "Related Items" on each product page. I want to know how usually do you implement it. Should I add a field in the mysql table to hold the "Related Items" information? What's the best solution?
Get ID Of Deleted Items
I wonder if there is anything similar to "mysql_insert_id();" for deleted/updated id's? If i do a query and DELETE WHERE text_field="", can i get the id's of the fields that were deleted?
Favorit Items
i have many tables with different data structure due, am making a service which will allow users to add itimes to thier "favorit items" tables I thinked to use the table names as a hidden filed, like if the table name is "hotel" and the user added a hotel to his favorit items , the hidden fild will be hotels, and then pass that field as a variable then use it in a query to get the hitel data, does this adea work? or there is a better way ?
Using If Empty With Two Items
I am trying to say if $_Post and $_Session are empty set the variable $dcparent to equal 1, but it doesn't like what I am doing. if(isset($_POST['dcparent'])) { $dcparent = mysql_real_escape_string($_POST['dcparent']); } if(isset($_SESSION['dcparent'])) { $dcparent = mysql_real_escape_string($_SESSION['dcparent']); } if(empty($_POST['dcparent']) && (empty($_SESSION['dcparent'])) { $dcparent = 1; }
Multiple Cart Items
I've created a shopping cart application using php 4.06 and postgres. a problem i had was that when i added the same item twice it was adding an extra item as opposed to adding the quantities together. i did manage to sort this out to an extent but my only solution means using a block of code for each item which has made my script very long and i'm pretty sure has made the script somewhat unreliable. I would appreciate it greatly if someone could offer a solution to this, this is my code for adding items to the cart: PHP Code:
Finding @ In A String, And Other Items
Ok - I want to check a string for @ in it (Im checking to see if a string that should contain an email holds a @ ) How would I go about this? preg_match? ereg? strstr? Examples? Also - how would I find any non alpha numeric characters in a string so I can give the user an error message. I dont want any characters besides alpha-numeric in the strings.
Multiple Items Of Same Name In Session?
I have a shopping cart where I can add tshirt designs to the cart. The designs are added to a php session object called cart. The object 'cart' consists of the design name, color and the quantity. The probem is that if someone adds the same design to the cart again then it just increments the quantity of the existing design with the same name instead of adding another instance of it to the cart. How can I have multiple instances of the same design with the same name in the cart at the same time. One thing I thought of was to append some sort of incrementing id to the design name before it is added to the cart. Thus the next time the design is added it would have a new id appended and the resulting name would be different.
Dynamic Form Items
I am trying to create A form that its fields will depend on a form menu. for example. /***********************************************/ <form name="form1" method="post" action=""> <select name="select"> <option value="1">option 1</option> <option value="2">option 2</option> <option value="3">option 3</option> </select> Text field 1<input type="text" name="textfield"> Text Field 2<input type="text" name="textfield2"> Text Field 3 <input type="text" name="textfield3"> Text Field 4 <input type="text" name="textfield4"> <input type="submit" name="Submit" value="Submit"> </form> /***********************************************/ When the option 1 is selected only the textfields 1 and 2 to appear, when option 2 is selected only textfields 1 and 3 to appear and so on... any combination I would like. I tried puting the textfields in "if" statments but i don't like it. its too messy PHP and HTML code. Any Ideas of how this could be done better ? If someone did something similar before and has a relative link it would be good as well.
Number Of Items In A Cart
I am working with a session and a 'cart' (note that I do not really know what I am doing though). I was wondering if there is some easy way (function) to work out how many items I have in my 'basket' / 'cart', because then I could call this function from anywhere to show the user just how many items are on order
Only Allow X Number Of Items To Be Checked
I have a function that renders out tag categories, and then all the tags within said category. Each tag has a checbox beside it, i am wondering if it's possible to only allow a user to check 4 tags. Here is the function: Code:
Display Items Using Checkbox
i have a page where in it lists all job items on a table and each item has a checkbox so when i check one or more items when i click the post button it should display the job items on this post page. my problem is, my post page is not working. Code:
Count Of How Many Items Are In Database
I am wanting to create an select menu for displaying the order of the item on a page. I am guessing that I need to get the count of how many items are in the db and them put them into a select menu. Does anyone know how to do this or can point me in the right direction?
Changing Items After A Date
What I have is a table (code below) and it is for an events page. What I want is after the date has gone, it changes the whole row to grey. ( #666666 ). Code:
Deleting Items From A List
When i click one of the delete buttons, the form submits, but nothing happens. I'm pretty sure i'm doing something stupid with the form buttons, but I've been staring at it too long...any takers? Code:
Multiple Items In Foreach()
Can someone tell me what im doing wrong with the code bellow please? I get print_ticket called lots of times, with 1 as the hash,name,ticket_no responce. (i have chequed that the query is returning the right results). $return = pg_query($pg_connection, $query); $data = pg_fetch_array($return); foreach ( $data as $temp ) { echo print_ticket ($temp['hash'],$temp['name'],$temp['ticket_no']); }
Seperating Search Items
When conducting a php sql search i get some great results, however i want to expand my results so that when multiple search terms are added it will display all relevant fields. $query = "SELECT * FROM Mixes WHERE dj LIKE '%$var%' OR event LIKE '%$var%' OR tracklist LIKE '%$var%' OR date LIKE '%$var%' ORDER BY event ASC"; From the above search i can only get single results from 1 field. I want to be able to seperate the search term into individual items that can be referrenced in the database. So for example i search for a dj name and also an event they play at i get zero results, however if i search for them individually i get the results i want. How do i expand the code to display the result of both the dj and the event or any of the other fields? I presume that i need to be able to set each search item into an individual variable and then use them to search.
Adding Items To A List Or Menu
Not sure if it is a php question but since i am working in php here it is. Ho can i add items to (the item label=visual text and the value=index number) a list object on a website. I am having a list with 4 items and i would like to add the text from a textfield (textfield1.value) to the list object so it will hold 5 items.
Dynamic List Items Repeating Themselves
I'm working on this online magazine, and each page (well, other than the front page) has a menu included on the right-hand side consisting of articles divided into three sections: articles, columns, reviews. For some reason, whenever I click on one of these article links, that link takes the place of the first link in the section. You can see what I mean here: PHP for the included right_menu.php PHP Code:
Adding List Items To A Database
Not sure if this is javascript or php so i put it in both newsgroups, sorry if it's the wrong group. I wrote (with help) a code to put several items in a list object (select) and I would like to add the items in this list to a database. I know how to add a selected item to the database but how can i put al the items tot the database. I need somekind of loop wich go's through the list.
Count Number Of Items In Each Category
I'm trying to list my categories and how many items are in each category. I'm not much on sub queries. How can I combine these two items. I'd like to display the category and the corresponding number of items in each ....
Create String With Checkbox Items
I'm creating a php script to interface with a database that will contain work requests for my office. Each job needs to be assigned to a person, possibly more than one person. The database field for this is named 'assigned_to' and will contain some data similar to "dave, randy, scott" for people who worked on the job. Does that sound reasonable? Code:
How To Pull Only Unique Items From Database?
I have a table like this: date, author, title, content now I want to grab the 3 latest items from this table from 3 DIFFERENT authors. I want this: -article by jim -article by sally -article by john Not this: -article by jim -article by jim -article by sally even if the two latest articles happen to be by jim, lets only grab the first one and move on. So basically I need (in pseudo-sql/plaintext): select title from contenttable where author=unique order by date limit 3 I've got everything code-wise except the "author=unique" part, how do I do that?
Seperator Instead Of A Comma For Listed Items In DB?
I'm making a recipe database, and need to have DB fields in mySQL that will have lists of values that would get sent to an array to be worked on. I anticipate that at times a comma will need to be used in the value itself. So, what's a commonly used symbol or something that people tend to use as a separator of a list that would then be used in the split() function to send the elements into an array?
Print All Selected Items From Dropdown??
I have a program that allows users to select a 'New Graduate' membership, and for each one selected, they get a free tshirt. I've got that working using a 'is_new_grad' function that I created. So, if they select 2, they see 2 dropdowns to select the sizes of them. It then sends an email w/ the membership info and the shirt sizes selected. However, when the email is being sent, it's only returning the size of the LAST item selected in from the drop-downs. Example: if I sign up for four of these memberships and select four different tshirt sizes (1 Medium, 1 Lg, 1 XL, and 1 XXL), the info in the email is all XXL: Code:
Updating Multiple Items With One Form
I am using a do while loop to run through a list of items on my page. Say I have 5 items on the page and each has one field that the user can input information to. Is there a way to do an update where it will update all records on the page with one submit form?
Displaying Multiple Items From Database
what i have is a page that has four sections. what i want to have is when the page opens, in that page i want the lastest two items for each section from a database to be displayed. the items to be displayed are an image, a title and a description. but i also want the description to be shortend to say about 25-30 words or about 100 chars, if thats easier? so in the end i have 4 sections, each showing the lastest two items for each section. would the best way to do this be to have a seperate table in the database for each of the sections? or would i be able to do it from one table? would i have to creat a query for each of the sections? e.g: SELECT * FROM table WHERE section=section
Unable To Remove Items From A File
I am at my wits end with some code for a website I am working on. The page in question is simply for a user to add items to a list of data. The data is stored in a temp file and later added to a database. I have successfull set the page to add items to the list of data. My issue is with trying to remove a line of data from the file. The following snippet of code runs if a link has been clicked on the line of data to be removed which reloads the page running this code which is intended to remove that line... PHP Code: ....
SSL Error Pop Up - Page Contains Both Secure And Nonsecure Items
I recently took over a site written in PHP. We utilize a third party to perform a job match, search, and application. When this page loads in IE, we get a pop up that says: The Page contains both secure and nonsecure items. Do you want to display the nonsecure items? How can I get rid of this as people going to fill this application out...
PHP Scripts To Diplay Items From XYZ Date Til Today
I'm trying to work out the SQL command script to display all items from a fixed time period til the current date. Something like... $sql_query = "SELECT * FROM mytable WHERE dateAdded like 'todays date - 60 days'";
Setting Variables For Only The Selected Items In Form
when a form has a question where the response can be one or more selections either from a series of chech box inputs or a selection list, how would i set into variables only the responses that are checked or selected so that only these values are available for exporting to a mySQL database?
|