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




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:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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?

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;

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?

Timestamp Compare..
Hi there,

I've got two sets of dates,

start / end

and

start / end


If I convert my dates into timestamps - is there a quick way to
compare them & see if any of the dates overlap.. ?

Im using a MYSQL database, & the dates are in text format - eg
20060527 etc (year month day)..

Though - Im at the very start of the database - so would storing the
start/end dates in Timestamps be faster ? (use a MYSQL query command
??)

Compare Two Dates
Comparing UNIX timestamps is no biggie but i have
to compare dates like this

$expiry_date="01/22/2007 05:42 PM";

to be compared with

$now= "01/22/2006 05:42 PM";

and just want a simple TRUE/FALSE return for the condition

"If expiry date has arrived? if its expiry date today or expiry date has passed?"

Compare Images
Does anyone know a simple way to compare two images to see if they are
the same? The filenames of the images will be different, but if the
image data is the same I would like to test for that.

The files will be jpeg images.

Compare Values From CSV.....
I have a CSV file which contains data from the search engines, which includes search engine, keyword, number of applicants and number of visits.

However in some cases there is repitition however I want to merge those figures together.

An example of what I mean....

Compare Date
How do i compare two date in YYYY-MM-DD format to determine which one is earlier?


Compare 2 Arrays
$array1=[ifcfg-eth2 ifcfg-eth0:1 ifcfg-eth0:2 ifcfg-eth1:1]
$arra2=[eth0 eth1 eth2]

i am trying to compare them both using array_diff
how can change the 2nd array so as to get the result in ifcfg-eth2
cheers..

Compare Records
is it possible to write a query to compare records in 2 tables, like if the number of records in the  2 tables are equal the query should return 1 if not equal the query should return 0. this can also be done in php like, get the number of records from one table and get number of records in another table, compare it and do the operation. but i wanted to know if its possible to do the compare records using the query itself.

for example, if one table has 5 records, this should be compared with another table, if this table has 5 records, then the result of the query should be 1 else 0. if i use joints, it will return all the 5 records. so not sure how to make this in a query. anyone have any idea ?

Timestamp Compare
I want to compare a timestamp value from mysql and if it is more than 2 days old then delete. Hoq do i compare 2 timestamps with php?

How To Compare Three Strings?
Can anyone tell how i go about comparing three strings
to see if they are the same?

I'm building an Email list system, where users can upload
three of their friends Emails.

I want to check, to make sure they don't load up the same
Email three times.

I was thinking something like this, But  strcmp only compares
two strings. I need to compare three
strcmp (string $email1, string $email2, string $email3)

How Does One Compare 2 Arrays?
I'm going to have a select on two different tables, the difference i need to insert to a third, I can load the two up as arrays, but now i need compare the two arrays, and have the output entered into a third array so i can enter that one back into a table...

suggestions?

array 1 Touched files (select few from a HUGE of 5,000+ files)
array 2 all files (from same folder)
array 3 difference between the two

Date Compare
i have a db that stores a date in a table with a specific column.

db=test
table=test_date_compare
column name=date_inserted

ok i hv a php form that allows user to input date and it enters in the above column (date) as in format eg: 21/03/2007

now i wat i would like to do is i would like to compare date of today and the date in the database if it is lesser then todays date it deletes that row of data. deleting the row of data i know how but the problem comes wen coparing the date i dunno how to ...

Compare Two Word Documents Using Php
In my system I want to compare two word documents ,but my server is a
Linux one and thats y I cant create COM object .

Any othermethods to find this one .I think to connect PHP to some
other mightt be useful for this.....

Code Compare Text
For example I have a paragraph

$p1 = "bla bla bla";

And I have an array:

$a1 = array("word1","word2","word3");

How to check that:

$p1 has one or more member of array $a1?

Compare Tables To Disallow Row
I have 2 tables, the first one names "site_users" contains a list of users and their information. The second table called "user_status" contains information about whether a user is banned, etc. I am trying to get a list of the users from "site_users" that are not banned in "user_status".

I tried using a join but I did not get the results I need. How can I select results based on a certain condition in the second table? PHP Code:

How To Compare Complex Strings?
i got a DB, in mysql, with more than 12000 records, each record has some values as name, surname, city, zip code and address. My task consists to find all record with the same address. Here is the biggest problem because, while city and zip code are entered with a drop down list, and so there are no possibilities to got differences, the address is entered manually in an input text. Code:

MySql Read And Compare .
I need a small QUIZ script for my site . I could not find the right script for me, so I decided to do it myself, BUT I am not a a big php programmer . So . The quiz is supposed to have 25 questions, with 3 answers each . BUT ! the thing is that some questions can have one, two or three right anwers correct, and all the right answers have to be corect for the hole question to be corect . So that is my main problem .

The script reads from the database the question number ID, the question, the answers (A1, A2, A3) and the value for each answer. (R1, R2, R3 ) . like for A1 R1=0 , that means R1 is wrong . and so on . each question has 3 answers .

I CAN NOT get right the code that makes variables for each $_POST and the code that should compare it with the value from the database . Code:

Compare Rows After Changes And Return Changes
I have a 33 column table with information that is changed by a multitude of users. I would like to keep track of the last changes made to any one row in the table. Here is what I thought of so far but believe there has to be a better way:

Once a user clicks update, the update script grabs whats in the given row, either saves it to an array or temp table then writes the new info to the perm database, grabs it, compares the two against each other to figure out what changed and adds it to the "update_changes" table, ready to grab by whoever wants to see it.

This seems like a round about way of doing this and I have to believe php and mysql are smarter than this. Everytime I run into a problem, I find after hours of searching that there IS a built in function that does what I need Can anyone point me in the right direction?

How To Compare The First Digit Of A Number?
if($row[PurchaseNo]==$_post[firstprize]{};

the $row[PurchaseNo] is one digit , while $_post[firstprize] is four digit
how to compare $row[PurchaseNo] with the FIRST digit of $_post[firstprize] ?

Date Compare Mysql Eventcalendar
At the moment i use following code to display booked days in a different color in an eventcalendar. It works, but it's very slow. Anyone suggestions to make it work faster?
php code :

Compare Two String Dates Using An IF Statement?
How do I compare two date stored within a database with datatype 'date'?

The dates are stored within a PostgreSQL database table in the format
"Y-m-d".

PHP/MySQL Calendar Compare Question
Most of the events in the calendar are all-day affairs, but some occur at
specified times. So I have two separate fields in the event table, one for the
DATE (required) of the event and one (optional) for the TIME of the event. For
events that span multiple days, I have them enter the event once per day, but
could automate that sometime.

ANYWAY, here's my question:

When I am displaying a calendar, for each date in the month displayed, I search
the event table for events on that date. BUT, I was not able to use an = in the
where clause, I guess because a date in MySQL always has the hours, minutes, and seconds attached. I played around with trying to change the $dateToCheck so it had hours, minutes, and seconds attached, but somehow never could get it right.

I ended up with a query like this:

SELECT * FROM $thisTable where START_DATE >= '$dateToCheck' AND START_DATE <
'$dateAfterToCheck'

Is there a more elegant way for me to accomplish this?

Compare The IP Address Of A Visitor To A List.
I came across this free script on the net that compares the IP address of a
surfer to a list (1.list). If there is a match, the surfer gets the message
banned. If there is no match, the rest of the php script runs.

Is there an easy way to tweak the file so that
1. If there is a match of the surfers IP address to one in the list
(1.list), rather then get a banned message, the rest of the php script runs.
2. If the surfers IP address does not match any of the IP address in the
list (1.list), then instead of echo 'banned' the surfer is redirected to
another webpage.

<?php
$IP = $_SERVER['REMOTE_ADDR'];
$IP_array = file('../info/1.list');
$IP_array = str_replace("
", "", $IP_array);
$IP_array = str_replace("
", "", $IP_array);
foreach ($IP_array as $IP_test) {
if (substr_count($IP, $IP_test) != "0") {

Compare Two Names Based On Characters
I wasn't sure how to describe what I want in the subject line so
hopefully this post will allow me to further explain. I have a table
where I have names of people who have filed evictions against their
tenants. These plaintiffs have no mailing street addres. They have a
city, state, and zip code. In another table, I have a massive listing
of those plaintiffs who have filed evictions against their tenants but
each record includes a full mailing address; street, city, state, and
zip.

What I'm trying to figure out is how to write a little PHP program to
compare the name fields of table 1 (without address) into table 2
(with addresses) and replace the address in table 1 with the address
from table 2 based on the match. I would also like the capability to
match combined fields from table 1 into table 2, meaning, if I were to
combine name, city, state, and zip in table 1 and combine name, city,
state, zip in table 2, I will most likely have the ability to reduce
the list.

Scan Directory, Compare To Dbase
What I am trying to do is this:

1. display all photosets in a database (easy)
2. can all (sub)directories (medium level)
3. compare the results and display the sets that are not yet in the database, link them and create a way to add those as well (frustration level)What I have so far is the follwing: PHP Code:

Compare Contents Of Two Arrays And Display What DOESN'T Match
I've got two arrays that I need to compare. One is $roomNums and the other is $roomNumsBooked. The point is to compare $roomNumsBooked against $roomNums (both arrays) and then display what DOESN'T match so I can get the rooms currently available.

I've written a script that works, but it seems every-so-clumsy. I was wondering if I could somehow use preg_match to do this but my prevous experiments have failed. Here's what I've done that works:

*******************************************
$roomNums = array('A','B','H','J','K','L','M','P','T');
$roomNumsBooked = array('A','B','L','T');
for ($i = 0; $i < count($roomNumsBooked); $i++)
{
for ($j = 0; $j < count($roomNums); $j++)
{
if ($roomNums[$j] == $roomNumsBooked[$i])
{
$roomNums[$j] = &#390;'
}
}
}
print_r ($roomNums);
echo '<br>'
echo 'Available Rooms: '
for ($i = 0; $i < count($roomNums); $i++)
{
if ($roomNums[$i]!= &#390;')
{
echo $roomNums[$i] , ', '
}
}
*******************************************

The echoed result is H, J, K, M, P which is correct, but is there a better, more efficient and/or elegant way to do this?

Better Ways Compare Strings: Exact Matches
I'm creating a lot of arrays. Some of the arrays carry words
that get duplicated...

For example:
$aCities = {"Durham", "Raleigh", "Raleigh-Durham", "Salem", "Winston", "Winston-Salem" }

I've been using stristr alot but that ends up meaning that I
must take the arrays out of alphabetical order and in the
end it complicates things on my part. I'll comparing it to the
strcmp() function right at the moment but I ran into some
difficulties with strcmp() a couple nights ago, along the lines
of having to convert the strings in the array lower-case (all
my arrays are currently stored in a ucwords() format). The
dashes in the names also present a bit of a problem.

The way I'm currently doing the comparisons...

function GetCity($sSearchThis) {
$aAllCities = GetAllCitiesArray();
// make sure parameter is lowercase
$sSearchMe = strtolower($sSearchThis);
foreach ($aAllCities as $sThisCity) {
if (stristr($sSearchMe, $sThisCity) !== FALSE) {
return($sThisCity);
}
// default to raleigh
return("raleigh");
}

What's the best way to accomplish this or is there a better
way under the following conditions:

(1) The item passed in IS a string (not an array).
(2) A default string is always returned when no match is found.
(3) The alphabetical order of the array must remain alphabetized.
(4) The dashes are not required.

Compare 2 Dates Problem (select * From 2 Days Ago)
I am having a problem with comparing 2 dates with eachother. I wan't to select everything from a table from today and 2 days ago. PHP Code:

How To Compare Encrypted Password Stored In DB With Unencypted One
I need to compare the encrypted password stored in mySQL database with one which I am getting from login form submit. Scenario is as follows: There is stored password in the table users which I need to compare in login process with one which user enters into this form:

<form method=post action="mycheck.php">
<input type=text name=user>
<input type=password name test_password>
<input type=submit name="login">

The passed password value in mycheck.php is not encrypted but rather the original entry - although I do not understand this why. For sure if I compare this raw entry with one sititng in the DB there is no comparission since they are totally different. How to go over this? Where is the problem hidding.

Read / Compare Binary Password Field?
We have a program that stores passwords in a SQL database using the following SQL proceedure;

update master.dbo.sysxlogins
set password = convert(varbinary(256), pwdencrypt(@new)), xdate2 = getdate(), xstatus = xstatus & (~2048)
where name = @loginame and srvid IS NULL

Would it be possible to read and compare a password entered in an input box using php, to check the passwords match?

Compare Current Value In Loop To A Previous Looped Value
Im trying to compare a current value in a loop to all of the previous examples to assertain if a value is unique or not. Code:

Process To Compare Records For Updating, Is There Am Efficient Technique?
I have a large database where the records have many fields (80+) and have users periodically updating it by submitting uploads.

Is there a quick and efficient manner to compare the record that is being uploaded to the one that already exists in the DB before updating?

The records have over 80 fields, so stepping through every field would be painful, and why update the record if nothing has changed.

Is there some binary or boolean manner to weight both the existing record against that being offered, and if they are equal then do not go through the process of uploading and importing.

Any ideas welcome.

Is There A Quick Way To Compare The Results From Two Arrays And Note The Diffences?
is there a quick way to compare the results from two arrays and note the differences?

I have two identical tables in MySql (backup and current table) and I want to work out the differences between them (i.e. what fields are different). I could construct some long function, but I was wondering if anyone had a quick method (I am just learning PHP).

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?

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:

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;
}

REQ How Would I Compare Multiple Date Fields In One Table To Find The Latest Entry Opps
i didn't explain it correctly before
my table is like this

example fields:
ID name username outcome date1 date2 date3 (etc..) - date15 price1 price2 price3 (etc..)

I know that Mysql query order by will compare records on a specific date, but how do i compare
multiple fields within the same record. Want to find the latest date within the record..

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.


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