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:
View Complete Forum Thread with Replies
Related Forum Messages:
Item In Array
I have an array, set up like this: $this->navigation_array['Home'] = array('text' => 'Home', 'act' => 'Home', 'redirect' => 'No', 'active' => 'Home', 'link' => 'index.php?act=home', 'default' => 'Info'); $this->navigation_array['Forums'] = array('text' => 'Forums', 'act' => 'Forums', 'redirect' => 'No', 'active' => 'Forums', 'link' => 'index.php?act=forums', 'default' => 'Info'); $this->navigation_array['Users'] = array('text' => 'Users', 'act' => 'Users', 'redirect' => 'No', 'active' => 'Users', 'link' => 'index.php?act=users'); $this->navigation_array['Config'] = array('text' => 'Configuration', 'act' => 'Config', 'redirect' => 'No', 'active' => 'Config', 'link' => 'index.php?act=config'); I want to find the first item inserted into the array, namely "Home". What is the fastest way to just call the first entry? You cant use $this->navigation_array[0] in this case because the keys are text not numbers.
View Replies !
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?
View Replies !
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.
View Replies !
Modify Array Item
I'm building a shopping cart and need to add the function so if an item is selected twice, the 'quantity' counter increments. I can't get the syntax right for modifying the array value. I have this: foreach ($_SESSION['basket'] as $key => $row) { if ( $row['gnsz']==$gnsz) { $newqty=$row['qty'] ; $newqty++; $row['qty']= $newqty; } } it picks up the first qty value but I can't seem to modify it in the array. I'm making a dumb mistake somewhere .
View Replies !
Put The Itemid Of An Item Into An Array.
$count = 1; foreach($trade as $val) { $val = checkinput($val); $sel=mysql_query("SELECT * FROM `inventory` WHERE `ID` = '$val' AND `userid` = '$userid2'") or die(mysql_error()); $n=mysql_num_rows($sel); if($n == 0) { $input = "You do not own this item."; error($input); } $g=mysql_fetch_array($sel); $itemid = $g['itemid']; $itemid[$count] = $itemid; $count++; } Basically, my script is trying to put the itemid of an item into an array. The problem i'm getting is that, it's not saving the values in the array. For example, if i have 3 items and it puts them into the array, it will only save the 3rd item in the array $itemid[3] and 1 and 2 will be blank.
View Replies !
Current Item From An Array
i have an include file with many arrays that look like this: Code: $event[] = array ('stuff' => 'bla'); $times[] = mktime(0,0,0,6,9,2007); as of right now, I am using asort to sort all of these by date and display them as a list.
View Replies !
Find Item In Array
I have the following array $array = array('k1' => 'v1','k2' => 'v2','k3' => 'v3','k4' => 'v4'); how do i select the value that is provided BEFORE the key i provide ex: $mykey = "k2"; $array = array('k1' => 'v1','k2' => 'v2','k3' => 'v3','k4' => 'v4'); $value = somefunctions(); // gives the value v1 ex: $mykey = "k4"; $array = array('k1' => 'v1','k2' => 'v2','k3' => 'v3','k4' => 'v4'); $value = somefunctions(); // gives the value v3.
View Replies !
Item In A Multidimensional Array
I have a multidimensional array (I think). It is an array that has arrays inside it. The inside arrays all have the same structure, (qty, product, color, size). How do I count how many items are 'White' * qty? I looked into the php manual and found array_count_values but others say it doesn't work with MD arrays.:confused: array( [0] array([0]qty, [1]product, [2] color, [3] size) [1] array([0]qty, [1]product, [2] color, [3] size) [2] array([0]qty, [1]product, [2] color, [3] size) [3] array([0]qty, [1]product, [2] color, [3] size) [4] array([0]qty, [1]product, [2] color, [3] size) [5] array([0]qty, [1]product, [2] color, [3] size) [6] array([0]qty, [1]product, [2] color, [3] size) ...)
View Replies !
Extra Item In My Array
Why is my code. $urlarray = explode("/", "/about/new/index.php"); print_r($urlarray); returning this Array ( [0] => [1] => about [2] => new [3] => index.php ). Perhaps I am being dense but why do I have an extra empty value at the beginning of the array. Is there any way I can make it return the ones I want (ie only those containing an actual value) or do I simply have to work around this.
View Replies !
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:
View Replies !
Select One Row Of An Array Where Item Number Is ..?
When I call the Ebays XML API I get an array or something similar back (see the code sample), is it possible to "select item_id where item_id = 123123" or something similar as in MySQL? If, How can I do that? Also, I need to attach a PHP variables to the row I selected as for example $starttime, $endtime and so on. Here is the code sample (the end of the scritpt); PHP Code: ....
View Replies !
Retrieving Previous Array Item
I have an array. The array key is the id of the item (for example categories[91], 91 is the ID of the category) all ID are not exactly in date order, but they're added to the array in date order, how do I find the previous (in the sense of when it was added) array entry of, for example category[ྗ']?
View Replies !
Array Explode Problem Result In A 6 Item Array
I have the following: $BB_Basket = "basket=¦APL6007,2.00¦AVX8900,1.00¦ARCAV500,1.00"; $basket_containers = explode('¦', $BB_Basket); unset($basket_containers[0]); print_r($basket_containers); This results in Array ( [1] => APL6007,2.00 [2] => AVX8900,1.00 [3] => ARCAV500,1.00 ) Now when I try to explode further with $basket_items = explode(',', $basket_containers); print_r($basket_items); This results in Array ( [0] => Array ) This should result in a 6 item array. Any ideas what I'm doing wrong?
View Replies !
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
View Replies !
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 } } }}
View Replies !
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.
View Replies !
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:
View Replies !
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
View Replies !
Most Recent Item
I have a table with every post in - which has a column for the time the post was created and a column for the thread that this post is located in. My threads table has a column for which forum this thread is in and a column for whether the thread is a sticky or not. On the forum display page, I'd like to display every thread that is in that forum, but ordering them so that any Sticky threads show first (ordered by date created), and then the non-sticky threads are displayed after those ordered according to the time of the most recent post within that thread.
View Replies !
Help With Featured Item
if its possible to display a featured item from mysql table. Table , links (id, item, hits) How i could i display 5 links which have bigest numbers ? Is this possible ? I only need query sample, not the entire code.
View Replies !
Pulling One Item
I have a MySQL database with info stored in it (speakers at a weekly seminar). I want to display the seminar's speaker info on my webpage every week. I need it to roll over to the next week's speaker every Thursday at 1:00. I have no clue about where to even get started with this. any ideas?
View Replies !
Activate An Item
I have a table with some items in it. Only one of them is active. On a page I display them all and you can click to activate one, the id of that one to activates is posted. What's the best way to activate that one and to deactivate the current active one? Now I use three queries: look up the current active one, deactivate it, activate the new one. I think there is a better way to do this.
View Replies !
Return Last Item
How can I return just the last item of an array? For example: PHP Code: $mytest = explode(",", $example); In one case: PHP Code: $example = "milk,eggs"; PHP Code: $example = "eggs,shampoo,batteries";
View Replies !
How To Make Url Links To An Item
Hi i was wondering if anybody could tell me how to make url links to an item in my site from a list of search results. Here is a piece of my code: <?php $Name = $HTTP_POST_VARS["query2"]; $Eventtype = $HTTP_POST_VARS["query2"]; $EventStart = $HTTP_POST_VARS["query2"]; $EventEnd = $HTTP_POST_VARS["query2"]; $VenueName = $HTTP_POST_VARS["query2"]; if($Name or $Eventtype or $EventStart or $EventEnd or $VenueName) { $conn=@mysql_connect("mysql", "u0rr") or die("Sorry can't connect to database"); $rs = @mysql_select_db("u0rr", $conn) or die("Sorry can't connect to database"); $sql="select * from event left join venue on (event.VenueID = venue.VenueID) where (Name like '%$Name%' or VenueName like '%$VenueName%') AND Eventtype = 'Comedy' "; $result=mysql_query($sql,$conn); while( $row = mysql_fetch_array($result) ) { echo("<b>"." Event Name: "."</b>".$row["Name"]."<br>"); echo("<b>"." Event Type: "."</b>".$row["Eventtype"]."<br>"); echo("<b>"." Venue Name: "."</b>".$row["VenueName"]."<br>"); echo("<b>"." Event Start: "."</b>".$row["EventStart"]."<br>"); echo("<b>"." Event End: "."</b>".$row["EventEnd"]."<br>"); echo("<b>"." Availability: "."</b>".$row["Availability"]."<br>"); echo("<b>"." Description: "."</b>".$row["Description"]."<br><hr>"); } } ?> For example if i enter an event type as 'comedy', a list of search results will come up from the form input displaying comedy events. Now from these results i would like to be able to click on Venue Name and this would link to that page in another part of my site. I hope this explanation is o.k, if not post a thread & i'll try and explain a bit better. Thanks for any help
View Replies !
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:
View Replies !
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?
View Replies !
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?
View Replies !
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.
View Replies !
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 = Ƈ' AND `Catalog`.item_type ='R' AND > `Catalog`.item like '%A-%' > ORDER BY `Catalog`.item_type[/color] And will not work without the Like part
View Replies !
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:
View Replies !
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?
View Replies !
Select ONE Radio Box For Each Item,
I have a long list of items, and beside each item, there's a radio box under several options. Players should be able to select ONE radio box for each item, and the item ID needs to be stored in the array delMsg[]. Here's my code:
View Replies !
Displaying Item By Brand?
I am designing a review site and im still learning PHP, I have been able to make my own mini CMS system to keep it up to date and each product is displayed by querying a database like: review.php?reviewid=34 What i want to do is make a page like called brand.php which when given a query such as brand.php?brandid=1 would return a page with a table of all products which are made by the same brand? Code:
View Replies !
Number Count Beside Each Item
i need to list something which will be driven from mysql database and the output that i want to have is something like this. 1. item1 2. item 2 3. item3 4. item5 how can i generate the numbers 1. - 4. ..?
View Replies !
Selected List Item Value
I know that the value for each element of my form is available through $_POST 'element_name'] but this doesn't work for lists. Can anyone tell me how I refer to the item selected in a list (combo box)?
View Replies !
Item Positioning On The Site
I have a problem with item position on my site. I have about 300 items that I need to keep in order. Puting up/down arrows will not work cause I'll kill myself before I get newly added item to positon 5. What I wanted to have is the text box next to the item where I can change its position. I don't care if I have to do it one item at a time with a button next to each item, the only requirement is that the numbers have to be unique from 1 to 300.
View Replies !
Get The Data For The Selected Item And Not The First It Comes Across?
I use the GROUP BY command in one of my queries, the trouble is although they share a common field sometimes the data differs in other fields for an individual record. Is it possible with the command to get the data for the selected item and not the first it comes across? For instance if the data is this ID, Cat ID, Name, Data 1, 1, Name 1, bla bl1 2, 1, Name 2, bla bl2 when grouping by cat id and group concat the name, irrespective of the id that is input to the database the query will deliver. Cat ID: 1 Name: Name 1,Name 2 Data: bla bl1 What I want is for the query to output 'bla bl1' when the id on the php page is 1 and 'bla bl2' when the id on the php page is 2. Is this possible? If the way I've explained it is confusing let me know and I'll try to make it clearer.
View Replies !
Index Of Inserted Item
is there an easy way of getting the index of a INSERT command? I have an auto-increment field in DB and have just inserted a record and need to know what the value of that auto-increment is.
View Replies !
Selecting Newest Item
I have a news page that I want to have it select the most current items by the day of the week. So if today is Tuesday, I only want all articles from last Wednesday to today. When the article is entered into the database, I use the Date and TIME stamp, ie (2006-08-11 09:11:43) and I let the administrator assign the listing order and set the article to active. Note, some days there may be one article that day others 5, so I cant use a LIMIT 7 (the # of days in a week) approach, since that would list the last 7 article and there may be 18 that week. I can check the day by the following... PHP Code: $dayoftheweek = date("l"); echo '<br> The day is ' . $dayoftheweek; I know this is farily straight forward, but my searchs have not shown anything similar for me to apply.
View Replies !
|