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




Comparing IDs In Both Arrays


What I have is a SELECT statement which gets the qsids and plonks them into an array..
PHP Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Comparing Two Arrays
What i need to do is compare two arrays and return an array that only
has those that are not in the main table.It's similar to what you could
do with SQL.

Array 1 - List of Everything
Array 2 - List of Some of Array 1

What i want to obtain is Those of Array 1 that are not in Array 2. I
would prefer not to do the following:

function getUnique($array1, $array2) {

foreach ($array1, $key => $value) {
$array2_key = array_search($array2,$value)

if ($array2_key === false)
$result_array[] = $value;

}

return $result_array;
}

Is there any simplier way of doing this...any predefined function in
php that could do this?


Comparing Arrays
I've got two uploaded files which I need to find out the diffrencies between. So I read them into two arrays and though I could compare them. And when I looked at the files, the problem arose. Coz the files looks like this: Code:

Comparing Arrays
My program has 2 sets of data. One is the id column from a tab delimited file and it needs to be compared with the id column returned from a mySql query. The program needs to start with the data in the tab file id column and then compare ONE of the tab file ids to ALL of the ids in the user table. If a match is found, an Update query is run. If a match is not found, an Insert query is run. Code:

Comparing Arrays
I have a MySQL database which has a load of musicians on it. Each musician has a field that stores their influences, which are separated by commas, e.g: The Beatles, The Beach Boys, Kiss etc etc.

Now, what I would like to do is start with the influences of one musician, and then compare it to all the others to find the closest matches - i.e find the musicians that have (say) more than three influences i common. This would then allow you to see which musicians had the most influences in common with the primary one, the one you started with.

Here's what I have in mind, it seems a little laborious - load the influences of the primary musician into an array using the explode command. Then step through each of the other musicians in a loop, each time putting their influences in to an array and checking to see how many matches there are between the two arrays. Whenever there is at least one match, the name of the musician and the number of matches would be put into a third array. This array would then be sorted at the end, so that the musicians with the most matches would be at the top, and the script could then display them.

This would probably work, but if looking at several hundred or several thousand musicians, it would surely be quite slow - is there a better way? I don't particularly want to use a separate, normalised table at this point - I know it would be the quickest way but it would involve a lot of restructuring for me. I know that PHP has several clever inbuilt routines that might do this job for me, so if anyone can suggest anything I'd appreciate it.

Comparing 2 Arrays In A Loop
I have 2 arrays:

$array1[] = 'hello';
$array1[] = 'how';
$array1[] = 'are';
$array1[] = 'you';
$array1[] = 'bob';

$array2[] = 'hello how';
$array2[] = 'are you steve';

I want to compare $array1 with $array2, and if any value of $array1 is found in $array2 I want to perform an action I know this has to be in a loop, i'm confused about how to set it up.

Searching Two Arrays Fully And Comparing
I'm trying to find matching pages by searching two arrays against each other. The arrays get the keywords from the current page and others stored in a database.  I'm not very good with PHP but what I'm doing at the moment is actually working, except it's only printing one found keyword when there are more. Code:

Comparing Values Of 2 Arrays Combined With Mysql Field Names
I am trying to create an edithistory table that has a text column into which I will put a string that can be read using strtok later to revert changes if necessary. I want to build this function so that it's dynamic enough to be applied to every table so that I don't have to write one for each table that might be updated.

When a row is added to any table (a new entry), it retrieves the next available editid # from the edithistory table and assigns it to that item in the "edits" column for its row in its own table. Every edit made is a new entry in the edithistory table (entryid auto_increment primary key), and the editid is a reference back to the object being edited. Code:

Comparing A String
I'm making a function to make a page using fasttemplates. The problem is that when the function is called it's got to check the value of $content if it's signup.htm it's got to make the sign up page. And if it contains .htm use that as page and if none of those just print the content of the string. This what i have so far but it doesn't work the way i want it to. What's wrong?

Comparing Dates
Is it possible to compare dates? For example: I have a site that displays releases dates (in MySQL format) for upcoming CDs. However, I need to compare the current date with the release date to decide whether or not to display a release date at all.

Comparing Two Dates
I need to compare two dates, first one being when the page is loaded (e.g. now()) and a date in the future (an event). then to do a count of this eg.

$startdate="05/07/03";
$eventdate="08/07/03";

so....in the case above there would be 3 days remaining...

can anyone help, or give me a few pointers how to acheive this....??

Comparing A Url String
Hi i'm no php programmer but a big part of my site now uses it after i payed someone to automate alot of it.

However, now ive spotted a problem. I have a link exchange script which searches another sites url to make sure my link is present before it automatically adds their link. I've noticed though that if the url they use is a level deeper than the one it looks for, the script cant find it. I need to make it more flexible. Can anyone help?

This is the script part that i *think* looks for my url on their page:

function check_link($str)
{
$lookup = <<<ERT
<a href="http://www.mydomain.com/">
ERT;
if (strpos(@implode("
",@file($str)),$lookup)){
return 1;
} else {
return 0;
}
}

------------------
If the link they use is e.g http://www.mydomain.com/keyword/
the script wont find it. Does anyone know how i can make it accept a url aslong is it contains my domain in part of it?

Comparing Timestamps
I would like to know how to take 2 timestamps and compare them to see if the difference is greater than 24 hours. I tried just using the huge numbers and doing the math, but it doesn't work.

Comparing A PHP, CFM, And ASP Script
Just because I thought it would be fun, and I just recently installed these things on my computer, I wrote a little script that reaches into a little database table and outputs a list of the things in there. I did this in PHP, ColdFusion(.cfm), and ASP. Here are the scripts.

PHP:
<?php
mysql_connect("adam", "root", "");
mysql_select_db("test");

$query = mysql_query("SELECT * FROM first ORDER BY fname ASC;");
while($fetch = mysql_fetch_row($query))
echo $fetch[0] . " " . $fetch[1] . "<BR>";
?>

Alternate PHP using objects:
<?php
mysql_connect("adam", "root", "");
mysql_select_db("test");

$query = mysql_query("SELECT * FROM first ORDER BY fname ASC;");
while($fetch = mysql_fetch_object($query))
echo $fetch->fname . " " . $fetch->lname . "<BR>";
?>

ASP: (using VBscript)
<%
DIM cn, rs, sql
SET cn = Server.CreateObject("ADODB.Connection")
cn.Open "MySQL"
SET rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT * FROM first ORDER BY fname ASC"
rs.open sql, cn

DO WHILE NOT rs.EOF
Response.Write rs("fname") & " " & rs("lname") & "<br>"
rs.MoveNext
LOOP
%>

CFM:
<CFQUERY name="name" datasource="MySQL">
SELECT * FROM first ORDER BY lname ASC
</CFQUERY>

<CFLOOP QUERY="name">
<CFOUTPUT>
#name.fname# #name.lname#<br>
</CFOUTPUT>
</CFLOOP>


Well, since I've been coding in PHP straight for the past 6 or 7 months, the PHP code took me about 10 seconds at most to write. The CFM code, while definitely simpler, took me a little more time to perfect. I'm pretty new to the language, but it is mostly pretty simple and easy. The ASP code took the longest. I'm pretty new to ASP as well, but it was a bit more complicated than the other two.

Let me just say I'm not a fan of the ASP method of doing things. PHP is possibly the best server side scripting language out there. I'm just learning these others to "expand my horizons" so to speak. Perl is coming soon.

Comparing Day And Time
i want that if the user tries to login with incorrect password more
than 3 times, then he should not be allowed to login for 24 hours.
i m trying to save the current day and time and then comparing the
same when the user logs in.
My problem is how to compare current date and time.
Is there some alternate way to do the same?

Comparing Variables?
I have a problem. I,m trying to check the value of a variable. This variable is being set by radio buttons in a form. The form variable is being posted to another page. $salutation is the var in question. PHP Code:

Comparing Hh:mm:ss (Duration)
I have LOGIN and LOGOUT time of the visitors of my homepage. Right now I want to know the duration between those two range of time. I have the data in TIME field format (MySQL) as follow hh:mm:ss. So, for example I'd like to know the duration of this login session:

LOGIN: 14:45:32
LGOUT: 15:03:24

How can I compare that ?

Comparing Dates
In my database, the Valid_end column is formated with the date datatype. My question is, after getting the values from the database, is it possible to compare them just like normal numbers in PHP. Or is there a much efficient way to do this. PHP Code:

Comparing Problem
The problem is like this, There are a number of $rows resulting from the
query described below. There is a variable named payment, this has for
example the vualue 2. lets say the query had 5 results, the i want to do a
compare that it shows only 2, depending on the value of $payment

$query = "SELECT a.oproep,b.oproep, a.react, b.react, a.logid, b.logid,
a.persid,b.persid, a.logemail, b.logemail,a.persemail,b.persemail

FROM reactie a, reactie b
WHERE a.logid = b.persid AND b.logid = a.persid AND a.logid='$logid' ";

$result = mysql_query($query); ......

Url Comparing Not Working With GET
I'm trying to write a function which takes a given url, runs it through a database and verifies whether it is in the 'allowed' list, 'banned' list or neither. This is my function (I've added quotes to make it easier for you to understand): Code:

Comparing Dates
I have this database with lots of info all time stamped with this format "May 15 2007  9:44AM".  What I would like to be able to specify a date range and have only entries that are in that date range be pulled from the table so that I can post the results. I know this must be possible but I have no idea host to even start.

Comparing Dates
In my db table, my date field uses YYYY-MM-DD, but if you compared 2007-6-1 to 2007-06-01 you would get FALSE. What can I do about this? I'm passing days using the GET method and then populating an events div with events from a db table that match the D M and Y. I would like it to work for both numbers with and without leading zeros.

Comparing Date
i have requested the selected date from another page and the current date is taken from session. now i want to check one condition that if the selected date is greater than the todays date then open a form else do not open. but the date comparison code is not working. here is my code:

$user_sel_date=$_REQUEST['myseldate'];
$mycurrentdate=$_SESSION['mycurrdate'];
if ($user_sel_date >= $mycurrentdate) {
echo "inside the if";
}
else
echo "outside the if";

Comparing Objects
I've got an array of objects that are instantiated based on an ID, but it's possible that multiple objects of the same ID may be added to an array.  I've tried using array_unique to get rid of duplicates, but if the object contains a null data field, it throws some error messages.

How do I get PHP to compare objects by a certain field rather than every variable (null or set) declared in an object?

Comparing 2 Tables
SELECT userid from userstable Then check a table named Hospital... for userid

Then what i need to do is a while loop which will "only" while loop through users that are not in the hospital table but are in the user table..... meaning only people out of hospital will be queried but "all" out of hospital users must be ran through the while loop..

is this possible in one query?

Comparing Dates
I am attempting to make a way so that my users have to be 13 years old in order to register, is there any easy way to do this, or am i coding 3 if else statements to compare current day and current month, and current year to the posted y/m/d?

Comparing Array Values
I'm developing a database that holds information about crew members. There are 7 categories of service types. Crew members can be associated with any number of categories.

I'm working on an update form to add or delete categories for a crew member. I first issued a query to find the member's categories. I issued a second query to list all possible categories. I want to show a checkbox for any possible categories that aren't in the member's individual category list. If the member is in categories 1 and 2, but not in 3 or 4, I want to show a checkbox for categories 3 and 4.

I can get the two category lists to print, but I can't figure out how to compare them.

Here is the code I have for the select statements:

Generates the list of member categories:
$cat_query = "SELECT crew_category.crew_id, crew_category.category_id, category.category_desc
FROM crew_category, category
WHERE crew_category.crew_id = "$crew_id" and crew_category.category_id = category.category_id";

$cat_result = mysql_query($cat_query);


Generates the list of all possible categories:
$all_cat_query = "SELECT category_id
FROM category";

$all_cat_result = mysql_query($all_cat_query);


I'm just developing my programming skills (as I'm sure you can tell), so I apologize for my ignorance! Thanks in advance to anyone who can help!

Comparing Variable Problem
Is this the correct php code that will retrieve a variable from a form and turn it into a variable in the script.

For instance, the user types in an address in a form, I want to use that address to compare against known addresses in a database, would I use the code below to take the address entered in the form and make it the variable 'formaddress'?

Comparing Array Contents
i'm having a small problem with getting information into a database. Basically, i've got a form with some elements in it, such as:

name phone address

for example. I pass these values to a function which finds out whether the action is associateds with the form is to insert, update or delete info from/to the database (using an HTML "hidden" field.)

The field names in my database are the same as in my form. (name, phone etc...). Using mysql_fetch-field, I have an array with the field names in it. I read the values passed from the form into an array called $values with the form fields as keys ? I would like to set the entry as 'NULL' for each field in which there is no data to enter. I thought the best way to do this was by comparing the contents of both arrays, and where there was a key in $values corresponding to the fieldname, somehow assign the contents of $values to that fieldname in the query.



Creating Two Dates And Comparing Them
I need to create Date A from form fields and then subtract that from Date B (also created from form fields). That will give me the difference in time so I can apply an hourly rate to that result.

The dates will be year, month, day, hour, minute (30 min increments). I can handle the majority of the program's logic, but the time part has me a little stymied. I pretty sure I'm going to need to build a date from the form inputs, but I can't really find anything similar to compare to.

This is for a reservation script where a person can specify a start and end date and from that a total cost will be generated. No database is involved here.

Comparing String Lengths
I was wondering if anyone had any ideas on how I would go about determining which of 4 values grabbed from a database had the largest string length. My situation is that I have a link to a pop-up window which has dynamic content in a table. I am trying to have the "height" of the pop-up window, that is stated in the link determined by what will show in the pop-up window that day by looking at the database.

I have already built a simple algorithm for the height based on how many rows will show in the table in the pop-up window, but since I wan't the width of the pop-up window to be constant, each row height can vary a bit depending on how long the strings are for certain (up to 4) columns in each row and this can mess up the simple algorithm I have now which just looks at how many rows will display to determine the height.

Of course I could just go overboard with my calculations for each row, but sometimes I would end up with a lot of white space at the bottom of the pop-up which I don't want. So I figured if I can determine which value (column) in each row has the longest string, then I could determine how many lines (height) that row took up in order to get a more accurate overall height for my pop-up window. *Confused? Yes, I am a bit crazy So basically all I need though, as I said above is an effecient way to compare 4 string lengths to find out which is the longest.

Comparing A Text File
I was wondering if this is possible: Compare a row from a table to a row from a text file, and if that row is not in that text file, then delete it from that table, and move it to another one. Say for example I read in a text file and assign the following variables: PHP Code:

Comparing/Convert Dates
I need to convert two dates to text. For example i have:

2007-06-05 11:57:00.000 and 2007-06-08 03:12:00.000.

I need to compare these two dates and tell the difference in text such as "3 days and 3 hours and 15 minutes" OR such as "3 days and 3 hours" how would I go about doing this?

Comparing Results From Two Tables
I am having some major trouble comparing information from 2 tables. I am attempting to verify the information in similar columns, so that I can come up with a number.  The columns are setup as varchar(30). The basic idea of the program is to obtain the Qualifying results for a race, and then add them to the table with Race results. Code:

Comparing Utf-8 Encoded Text
I don't know if you would classify "mysql" as a program but mysql and php are two seperate entities, call them whatever you like, but i'm trying to make a point that I THINK that they treat strings differently, and have different methods of parsing strings.

I am storying text from many different languages in my mysql with charset utf-8, and collation utf8_bin all the text being parsed in the php script is also encoded in utf-8, as the script is saved in utf-8 charset.

now i am wanting to allow users to sign up or register with my website, and be able to choose usernames in foreign alphabets if I am going to do this, i need to be positive that I can successfully compare usernames from any language encoded in utf-8, and test for their uniqueness.

for example fredrico who is from spain signs up at my website, when he chooses his spanish username I will query the mysql db for WHERE username='$fredrico' I need to be positive that $fredrico compared to any other utf-8 encoded string can successfully find a match with only the same spanish characters.

in other words for this to work, I need to know if the letter aleph in hebrew encoded in utf-8 is unique and will never equal another character from another alphabet Is this true?

Comparing Dates With Strtotime()
I'm building a schedule script--well, modifying one I built last year--to add an event every second and third Sunday of the month.  However, when I try to find that Sunday, and compare to my timestamp, I run into trouble: $myDays = getMyDays(); Code:

Comparing Time Stamps
As the title of the topic suggests in trying to compare to sets of time stamps for a 24 hour or more difference

I have a database with a Timestamp field set to CURRENT_TIMESTAMP (so when anything is updated or inserted the timestamp is set to the time that happens)

I couldn't find anything relevant either with a google attempt.

Comparing Street Addresses (abbreviations And Such)
I have a database table that contains street addresses in the following
format:

123 Any St.
456 Some Rd.
7789 That Blvd.
etc.

I.e. Street number, street name, standard abbriviation of road type.

Now, I have a web form where people will type in an address. The
problem is for what I have in the database (123 Any St.) a person might
type in:

123 Any St.
123 Any Street
123 Any
123 Any Street Apt. 4D
123 Any St. # 4D
#4D 123 Any St
etc.

What would be my best bet here? What I need is a sort of "best match"
ability (I'm assuming), but I'm unsure how to do it. Anyone have any
really good ideas?

Note: I'm not interested in Apartment numbers. They should be ignored.
I'm only concerned with building locations.

Comparing Strings To Show Differences
I would like to have a feature that displays the changes/differences made to a body of text after someone edits something.

ie: I go to edit Entry1, this is what I have...
Quote: Hello, this is the entry.

I make some changes and then hit preview, and this is what it shows:
Quote: Hello, this is not the entry.

Therefore you can visually see the differences/what you changed. Any ideas?

Comparing Two Times Using Unix Timestamps
I want to use the unix timestamp to select a time like this code displayed below. Currently its using the strftime function of php but its not accurate because its comparing two string values and I want it in timestamp interger format. PHP Code:

Neglecting Spaces When Comparing Variables
i hve a code that retrieves data from a database..after the retrieval, i then nid to compare the values if they are the same..i can do that but there is still a problem..for example, if value1 would be 'roz' and value2 would be 'roz ', php would treat them as different variables because of the space after value2 which is not present in value1..

another problem is that my query would sort the results in an ascending order so that i can compare the values row by row..but, there are cases also that the values retrieved would be: Code:

Comparing Data From A .txt File To DB Info.
I have a txt file that stores separate lines of information. Here is an example of one of the lines. Western Pleasure || height:>= 15, discipline:== 'western'

That is just telling me the qualifications of the "Western Pleasure" show type, which is that the height has to be greater than 15 and the discipline has to be western.

Now I am trying to take these qualification statements and compare them to values in the database, if  both qualifications match up, I would like to add the word "western pleasure" to an array. Here is my current code:

Comparing Two Numbers, Function Not Working.
I am trying to compare two numbers. In a previous post Frost told me that comparing two numbers like this would always return true: Code:

Comparing PHP Array From Checkbox To MySQL Table
My problem involves updating a MySQL table using checkbox input. I'm relatively new to both PHP and MySQL so I'm looking for a little direction on the smartest way to accomplish my goal.

When a user goes to a project page, they are able to categorize their project by area. The user checks a series of checkboxes and the results are stored in an arrays called $category_ids. I'll called the project id $project_id.

What I want to do is compare the array $category_ids to entries in a MySQL table for $project_id. Then I want to add the links that aren't already in the table and delete the ones that need to be deleted. The table has these fields:

projects_cat_link (table)
----------------------
category_id ¦ project_id (fields)

Does anyone have any tips on how to do this? I've gathered that maybe there's a way to get the MySQL data into a similarly formed array and then use functions like array_diff to compare. But then I'm not sure how to use the comparison in a MySQL query to add/edit/delete the links.

Reading/comparing Vars In A Flat File
I am trying to read info that has been written to a flat file, search for a particular variable, and then compare it to existing ones to make sure there isn't a duplicate entry written to it.Ex.

1. Users fill out a form (including username and password)
2. Upon submission they are taken to another page which displays info they just entered so they can verify.
3. After they okay the info and click, they are taken to page four which emails them and writes the info to a flat file.

What I want is a way to be able to iterate through the info written to the file and compare the 'username' that the person picked to existing ones. If there is a duplicate, then force them to choose another. This is what I came up with. I get no errors, but it doesn't work... PHP Code:

PHP Comparing Time For Custom Session Timeouts
Wondered the function that i would use to compare time, i am going to get the time at session start and then compare it with the time at the end of the session, if that is over 30 minutes then the session is ended. What you recon? breaking the time down into year/month/day/minute/hours/seconds and save the infomation into the database... what you guys recon?

Disregarding Case Sensitivity When Comparing Strings
I recently rewrote my a login script so that the possibility of an SQL injection is diminished. However, I now have a new issue that I have come across.

Since I now compare the username in php rather than in a query, how can I make it so that it compares 2 strings regardless of case and returns true if they match?

Expired Article - Comparing Today To Expire Date
On my front page I have a list of articles that are pulled from my database. I have just added a column (expires) to the db in order to remove outdated articles.

I'd like to compare today's date to the expires date in my WHERE statement to exlude all articles where the expires date is older than today. But I'm at a loss right now on getting it to work.

Comparing Pages And Returning Differences As Regular Expressions
The concept - a HTML file changes regularly. However, only certain
parts of the page change. I want to find a regular expression that
describes that changed area.

Can anyone here think of a rough way to go about this? I'm thinking
grab the page once a day, put it in a table with a date stamp, and
then do something.

FYI: Test Results Comparing Different Methods Of Resizing Images
I posted this in alt.php, but as a reply, so now I'm posting it here for
people
who might have missed it but still could find it useful.

I compared the smooth image resampling used in PHP to create good quality
thumbnails of large images, used commonly in image galleries. i compared
ImageMagick and PHP (with GD2) and compiled some statistics below.
I ran two test. Both used a set of 10 photos around 3MP in size. On the
first
test, I created two thumbnails for each photo, one 700 pixels in width and
another at 120 pixels in width. On the second test, I created just one
thumbnail, 120 pixels in width. Time was counted in "minutes.seconds."

TEST#1 -- IMAGEMAGICK*
-----------------------------------------------------------
METHOD TIME IMAGE QUALITY
thumbnail 1.33 good
sample 0.24 bad
resize 1.33 good
size/geometry 0.42 good

TEST #1 -- GD2 (PHP)
-----------------------------------------------------------
METHOD TIME IMAGE QUALITY
Imagecopyresampled 1.57 good

TEST#2 -- IMAGEMAGICK*
-----------------------------------------------------------
METHOD TIME IMAGE QUALITY
thumbnail 0.26 good
sample 0.19 bad
resize 1.13 good
size/geometry 0.06 good

TEST #2 -- GD2 (PHP)
-----------------------------------------------------------
METHOD TIME IMAGE QUALITY
Imagecopyresampled 0.56 good

*ImageMagick Command Methods:
thumbnail : convert -thumbnail $destSize $sourceFile $targetFile
sample : convert -sample $destSize $sourceFile $targetFile
resize : convert -resize $destSize $sourceFile $targetFile
size/geometry : convert -size $destSize $sourceFile -geometry $destSize
$targetFile

CONCLUSIONS:
-----------------------------------------------------------
There were four different imagemagick commands I tried out in all. Overall,
the winner came out to be the imagemagick command. This
method beat out PHP by a good margin, creating thumbnails in about 1/3 the
time it took PHP with similar quality in the first test, and then taking the
cake
in the second test by creating thumbnails in about 1/10 the time as PHP.

Imagemagick seems to increase in performance compared to PHP when creating
a smaller thumbnail versus a relatively large thumbnail, as seen by test #2
versus test #1. This means that a site creating small thumbnails will see
even more of an advantage by using Imagemagick.


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