Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Delete Item From Array


How do I search for an item within an array, then delete it?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Delete An Item From An Index Array?
How can I delete an Item from an index array in php4?

Array_unique - How-to Get First Item Value In Repeated Array Item
I would like to know how-to get the first value of repeated items too in an array using something like array_unique. Code:

Delete Item From Database
I still can't figure out how to delete an item from my shoppingcart. I have tried different ways to do this, but its impossible.

-a button or link that deletes a item from my database
-the php script that deletes it

here is a suggestion:

$slett = "DELETE ID, VARE, MODELL, STR, ANTALL, PRIS,
TOTALPRIS FROM USER_TRACK
WHERE USER_ID = "$user_id"";

But how can i assign this to a button?

Listing Table Data With An Option To Delete Each Individual Item.
Was wondering if anyone could help me with a PHP, MySQL problem. I am
completely new to PHP and MySQL. I have been trying to find a way to
list data from a table on a web page and after each individual item
have a hyperlink to allow users to delete the information listed. Can
anyone help?

i.e.
Name Age Sex
------------------------------------------
Adam 21 M delete
Betty 22 F delete
Chris 23 M delete
Daisy 24 F delete

------------------------------------------------------------------------------------------------------------------------------
(delete after 'Sex' would be the hyperlink to delete that entire line
(row) from the table).

Deleting An Array Item
I have a standard array:
$foo = array(
0 => 'abc'
1 => 'def'
2 => 'ghi');

and I have a variable, $bar, which equals 'def' ... and I want to check
my array to see if the value of $bar exists in the array, and if it
does, delete it from the array.

if (in_array($bar, $foo)) {
// what goes here???
}

I've done this before, but for the life of me, I'm drawing a blank now.
Help a bruthah out?

Random Item Of An Array
What is the best way of picking out a random item of an array, regarding speed and CPU-usage ? I need a super fast way of picking out an ID from my MySQL db.

Remove An Item From And Array Entirely
How do you remove an item from an array...

Shopping Cart Item Array
Trying to build a small simple shopping cart and I am having difficulty getting the solution. The cart is displaying each product, but it is overwriting the values. So if I have added 10 products, it shows ten items, but each item has the values of the last product I added.

I think that this may be due to me trying to use a key to store both an array and string at once, but Iam not sure. I have looked at other examples but due to different methods, syntax is throwing me off. Code:

Remove A Single Item From An Array
I have gathered an array of ID's. I need to go throught the array and find a specific ID and remove it from the array. Because we want to keep that ID. Any suggestion of how to do that.

Preg_split First Item In Array Is Blank
could someone please explain to my why using the code below generates a blank item in $array[0] please. The 'x' from xbox360 is in $array[1]?

Arrays : Returning A Reference To An Array Item ??
I am currently storing a set of objects inside an array,

$itemlist = array();
$itemlist[] = new item("myitem");
//...

and I am looking to develop a search function, which returns a
reference to the found item.

function &search_item($itemlist,"myitem") {
//...
}

I am trying to figure out how to obtain a reference to a given item in
an array.
Indeed, foreach() and each() seem to work on copies of the data in the
array.
For example:

$array = array("a","b","c","d");
print_r($array);
foreach($array as $v) $v="xxx";
print_r($array); // $array is unchanged

reset($array) ; while(list(,$v)=each($array)) $v="xxx";
print_r($array); // $array is unchanged, again

Deleting A Single Item From The Middle Of An Array?
I have an array that contain objects, I want to be able to test against the id of that object and remove it from the array. In it's simplest for I want to go from this:

$people = array('Tom', 'Dick', 'Harriet', 'Brenda', 'Jo');

...to this...

$people = array('Tom', 'Dick', 'Brenda', 'Jo');

The fact that the items in the array are objects should not matter right? Plus I've already written my loops and conditionals to check which item i need to remove.

function removeItem ( $item ) {
   $len = count ( $_SESSION['basket_arr'] ) ;
   if ( $len == 1 ) {
      emptyBasket ( ) ;
   } else {
      for ( $i = 0 ; $i < $len ; $i++ ) {
         if ( $item->id == $_SESSION['basket_arr'][$i]->id ) {
            //$_SESSION['basket_arr'][$i] must go
         } } }}


Removing Item From Array Then Overwriting File
I have a bookings.txt file which has a list of dates each on a new line, for example: -

21/06/07
22/06/07
29/06/07
25/12/07
01/01/08

I also have a variable $event_dd_mm_yy which I want to remove from this file if found. Code:

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

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;

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

How To Walk Array And Delete Matched Elements?
I'm kind of lost on this one - I need to modify 2 files based on user input:

Iterator First Item?
Let's say I have the code:

foreach($data as $row)
{
do something with each $row
}

Is there a way to do something specific to the first item iterated?
Pseudocode:

foreach($data as $row)
{
if first time through iteration do something with $row
else do something which each remaining $row
}

Is this possible? I think I could use a regular 'for' loop, using the
length of the $data array as a guide, and then an 'if..else' structure
to see if it is the first time through the 'for' loop, but I was
looking for a more elegant solution.

Get One Row, One Item From Database
I was trying to grab just one row and one field in that row from MySQL, but couldn't find a way other than: PHP Code:

Trying To Split The Item...
I'm trying to make a search thru my mySQL database, so it any keywords are found then I'm adding the details to the next item in an array that I create. I've tested the array and it is storing the information into the array properly because it echoes out all of the information correctly. My problem is that, at the beginning of each item in the array I have information that tells me what part of the database it was pulled from and the id number and also how many times the a keyword was found in that specific database entry. So you have something like this.. Code:

Get Last Item In URL String
I realize how elementary this is, I apologize. Maybe that's why I can't find the right answer. I've tried everything from EXPLODEing the string to SUBSTR_REPLACE.

Can anyone tell me how to just get the last item in a URL string? Like turn this:

/mydirectory/myimg.jpg

into this:

myimg.jpg

Search Item In Database
I made a function that does a case insensitive search. This works fine.
But i'd like to improve that script so that it also returns items from the database that are partly similar to the search string.

this is the script atm:

Updating Item Numbers (or IDs)
After a while of deleting records in a MySQL db, there gets to be the
gaps in the id numbering system. i.e. 1, 2, 3, 6, 7, 12, and so on.
Is there a way to renumber the id system in a table for 1, 2, 3, 4, 5,
6, etc without manually going in and changing those numbers?

Returning Autogenerated ID On New Item
Lets say you have a form that when saved to the mysql database creates
a unique incremental id. The form is just the first part of a series
of things the user can do, so once the ID is created, the page would
need to know immediately what this ID is. Is there a way to grab this
ID instantly once it is created? Obviously if this were a sign-up for
and a new user name and password are involved, you can have the user
login after the initial set up and this select statement would bring
back the ID. But the situation I have doesn't work like that.

The way I have been dealing with this is simply to have a select
statement after the initial insert that requests the record based on a
couple of other fields that are likely unique. But this seems like a
rather kludgy way of doing it. Is there some other solution.

What Does `Catalog`.item Like '%A-%' Mean? -MySQL?
I am looking at an old query and I cannot remember or figure out what this
part of the query means:

`Catalog`.item like '%A-%'
It is the like '%A-%'

I cannot figure out.

Then entire query is:[color=blue]
> SELECT *
> FROM `Catalog`
> WHERE `Catalog`.img_status = &#391;' AND `Catalog`.item_type ='R' AND
> `Catalog`.item like '%A-%'
> ORDER BY `Catalog`.item_type[/color]

And will not work without the Like part

Pulling In One Item Of Four Categories
Ive got an offers table which contains name, category_id

I want to display all offers, however the first page will only display four offers (one of each category). My query is as follows so how do I do this part? Code:

Finding # Of Item From Query
I have a query that goes "SELECT item_name FROM products WHERE products.drink = 'juice'" . If I get back 12 results from this query I can make a list using a simple loop, that is fine . If I click on one of these list items I want to go to a detail page, again I can do this no probs.

How do I carry over to the detail page the number that the item appeared in the original list, for example if a result was "orange" and it was the 5th one in the list, how do I carry over the number 5 to the detail page?

Populating Form Item From SQL Enum Set Rev#2
$sql = "SHOW COLUMNS FROM table LIKE 'subject' ";
$qry = mysql_query($sql) or die("Query not valid: " . mysql_error());
$res = mysql_fetch_object($qry);
// This returns a row with a field 'Type' containing 'enum(...)'

$res->Type = str_replace('enum('', '', $res->Type);
$res->Type = str_replace('')', '', $res->Type);
//now the string is something like this: one','two','three

$temp = explode('','',$res->Type);
//temp is an array with as much elements as the enum

while ($temp)
print array_pop($temp);


This way is much more easier using the elements since they are elements
of an array. Cleaver isn't it?

How To Replace An Item In The Url Search String
Using PHP 4, what is the most elegant way to replace a parameter
value in a url query string? I want to replace the "Order" parameter,
but it could occur anywhere in the query string.

myfile.php?Param1=Hi+there&Order=ColumnA&Param3=Bye+Bye
myfile.php?Order=ColumnA
myfile.php?Param1=Anotehr+example&Order=ColumnA

after applying this function, I'd like the result of the above examples
to be

myfile.php?Param1=Hi+there&Order=ColumnB&Param3=Bye+Bye
myfile.php?Order=ColumnB
myfile.php?Param1=Anotehr+example&Order=ColumnB

Add Item To Shopping Cart Problem
i have a cart link in all of my listed products on the site. when i
press this link i will generate a url like this

http://www.mysite.com/index.htm?loc...art&productid=3

after i press this link the site cart.php will be included and add the
wanted product to the cart, and show the cart.

my problem now is after the cart is showed with the new product in it,
when i press the F5 key in the browser to refresh the site, the same
product will added to the cart once more, because the previous generated
url is unchanged in the browser.

have anyone a idea how to fix this problem?

How To Apply Css To A Table That Is The Only Item In A Php File Please
How to apply css to a table that is the only item in a php file please

In the page that has just the one table that is to
be included in the other 2 pages, there's some
heavy css going on, plus the text in the table
gets changed quite a lot on a daily basis.
Usually, in my program, I can highlught the text
that needs a different css applied to it and click
on the css style that applies to it, but because
the page only has the one table and nothing else,
there's no mention of the link to the styles page?

Language Depending Item Url's
I'm using a little newsflash item on my webpage, which is some text in an iframe. I have one newsflash item in English and one in another language, newsflash-english.html and newsflash-other.html How can I serve newsflash-english.html to english surfers and newsflash-other.html to not english users ? depending on the browser language ?

Redirecting To The ID Of Newest Item Created
I have a form that a user submits which creates a product. I want the user to be redirected to product.php?product_i=(the new product id)

The problem i'm having is that i dont know the ID of the new product created because the table is set to auto increment. How would i go about finding out the new ID and redirecting to that new product after it has just been created?

Selected Item To Use For Multiple Variables
I've got a list of 'items' and those 'items' have unique 'categories'.
I have 1 table for 'categories' that contains a list of category_ids and their 'category_names'. The other table is the 'item' list. And here's where I'm running into difficulty, I'd like to have the 'item' table contain the category_id from my 'categories' table as a Foreign Key and that category_id's 'category_name' in a 'category' field. I'm getting the Foreign Key, but I can't seem to grab the 'category_name' and assign it to my $category variable in the 'item' table.

I've got a page to insert items and a page to update these items. I was working with the update first. And I'm able to grab the list of categories and select the correct one, but I'm not seeing where to assign the category_name to the $category variable. Here's dropdown list: Code:

Explicit Numeric Keys Vs Item Position
Say if I have a mixed array:

$array = array("item1", "2"=>"item2", "5", "item4key"=>"item4")

Is it possible while looping through the array (foreach ($array as
$key=>$val)) to check if an item has an explicit key specified instead
of its automatically assigned position key?

Choose Random Item From List But With Different Weighting
I want to choose an item at random, but have different probabilities for each item. One easy way is just to create an array like

$a[]=1
$a[]=2
$a[]=3
$a[]=3

That way a random number between 1 and 4 would give the weighting I want, but it seems like there has to be a much smarter way to do this. I've seen some algorithms for random distributions, but they don't quite do what I want. Oh yeah - must not require a DB; this should work with values from a CSV or similar ...

Creating A Form For An Item Tracking Website
I'm having trouble processing the html form, especially the "date found" portion. I also don't really know how to set up my tables in my database so that they work efficiently.  The information I an requesting with the form is: item_number, found_by, date_found, city, state, country.  I'm assuming that I will have to have more than one table in order for people to search by item_number or found_by etc.

I know these are kind of broad questions, but let me know if you'd like me to post what code I have, or stick the files on my FTP for download. I am using SQL Manager for a mysql client and Dreamweaver CS3 for design.

How To Remove Unwanted Words/characters From Database Item
currently i dump some data into our database from another database. now, i found some wierd characters  at the end of each of those items. and there are like 500 items in my database table which has those.

is there a way that i can remove it using mysql query to be run in mysql or phpmyadmin
something like
update * from table where field name item has  and replace it with just blank?

hope you could help me with this.

Test If An Item Is An Object Or A Reference To An Object
Using php 4.4.4, let's say I have an array of objects or references to
objects. If I picked out an arbitrary element, $n, how would I know
if that was an object or a reference to an object?

Delete From $var
Is it not possilbe to have a variable for the table name in a delete statement (mysql database). inside an if this button is hit statement I have:

$sql = "delete from $type where id_num='$number'";
mysql_query($sql);
echo "$sql";

when it echos $sql it doesnt have the $type var where the table name should be, it just leaves that blank.

Delete A Row
This should be simple enough but for some reason it's not working. The $name is a number which is being posted across when the user clicks submit. I want the PHP to then access the Database with this number and use it to delete the staff ID (which is a PK).

With this code I get the error:

Warning: ociparse(): supplied argument is not a valid OCI8-Connection resource in /homedir/ilex-s01/jmsuther/public_html/DeleteStaff.php on line 16

Warning: ociexecute(): supplied argument is not a valid OCI8-Statement resource in /homedir/ilex-s01/jmsuther/public_html/DeleteStaff.php on line 17
;

The code is:

$name = $_POST["staffnodelete"];
IF ($staffnodelete=="" )
{print "You selected $name - for deletion ";}

putenv("TNS_ADMIN=/u1/oracle/Products/shu10g/network/admin");
$con = OCILogon("username","password","10g");

$query = "DELETE FROM staff WHERE staffno = $name";
$query = $query_post [$name];
$stmt = ociparse($conn, $query);
ociexecute ($stmt);

How To Delete Fields
I would delete with php, all record of a table mysql where the seven left chars of the field is equal to the data in input($seven_chars).

I have used the the belowe istrucrion but it do not work.how can I do?

mysql_query ("DELETE FROM my_table WHERE substr(myfield,0,7)=$seven_chars");

Delete A Line In PHP
What i want to do is to open a file read the file Select a particular line from the file and delete that line and close the file. How to do it in PHP.

Can't Delete Cookie
Right I am quite new to php but have managed to create a simple log in/log out thing with cookies. All was working fine and as expected until I added a new section of the site. The new section stores another cookie (latest message user has read) so that next time they visit the site it will highlight the 'new' messages.
However since adding this I can no longer log out.

Can't Delete Cookie, Help Please~
Page1: <? setcookie("book_id", $book_id ); ?>

Page2: <? setcookie ("book_id", $book_id, time() - 3600); ?>

Can't delete cookie at once but reload page 2 two times
how to delete $book_id cookie without reload?

Cookie Won't Delete
I'm trying to setup a simple user authenication for my site. I'm using cookies to pass the credentials between pages. But the function header() is giving me problems logging in and logging out. As you can see in the code below, I try to redirect the user to a page after setting or deleting the cookies. The scripts redirect okay, but the user never logs in and never logs out correctly. The scripts works correctly (logging in & logging out) only if I comment out the header() function.

Here's my code for setting the cookie (login.php):


Copyright © 2005-08 www.BigResource.com, All rights reserved