Help on iterating 2 arrays and also comparing the values?
Moderator: General Moderators
Help on iterating 2 arrays and also comparing the values?
Hi all,
I can get my head round how to go about this - Basically, I have got two query resultset from two tables which I am trying to compare their results and also update one of the tables from which these results came from.
For example, if result A is 1,2,3,4 and result B is 1,2,5,4 the output of result be at the end of the comparison should be 1,2,3,4.
Cheers
I can get my head round how to go about this - Basically, I have got two query resultset from two tables which I am trying to compare their results and also update one of the tables from which these results came from.
For example, if result A is 1,2,3,4 and result B is 1,2,5,4 the output of result be at the end of the comparison should be 1,2,3,4.
Cheers
Re: Help on iterating 2 arrays and also comparing the values?
Hello,
So you want a final array as a result of the comparison between the first two arrays?
Not fully sure what your trying to achieve sorry, im leaning towards a couple of array functions that exist but im not sure if that is exactly what you are going to need.
So you want a final array as a result of the comparison between the first two arrays?
Not fully sure what your trying to achieve sorry, im leaning towards a couple of array functions that exist but im not sure if that is exactly what you are going to need.
Re: Help on iterating 2 arrays and also comparing the values?
Hi juma929,
yes I want an array as a result of the comparison so that I can update that row in the database.
cheers
yes I want an array as a result of the comparison so that I can update that row in the database.
cheers
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: Help on iterating 2 arrays and also comparing the values?
have you looked at the array_diff() and array_intersect() functions?
Re: Help on iterating 2 arrays and also comparing the values?
To be honest, I have but I don't really get how to apply it here.
Re: Help on iterating 2 arrays and also comparing the values?
I know array_diff() only returns the difference in the two array which isn't really applicable here cos not only do I want to find out which row is not equal between the two resultset I also need to update that row. Or maybe I am just confusing my self?
Re: Help on iterating 2 arrays and also comparing the values?
Hello,
Take a look at array_diff or array_intersect and see if thats what your looking for.
http://us2.php.net/manual/en/function.a ... ersect.php
http://us2.php.net/manual/en/function.array-diff.php
Hope that helps, if not, get back in touch
Take a look at array_diff or array_intersect and see if thats what your looking for.
http://us2.php.net/manual/en/function.a ... ersect.php
http://us2.php.net/manual/en/function.array-diff.php
Hope that helps, if not, get back in touch
Re: Help on iterating 2 arrays and also comparing the values?
DOH
Just noticed other people are talking to you too and they have already mentioned those functions ha-ha.
Sorry, I gotta get in the habit of catching up instead of just replying!
Just noticed other people are talking to you too and they have already mentioned those functions ha-ha.
Sorry, I gotta get in the habit of catching up instead of just replying!
Re: Help on iterating 2 arrays and also comparing the values?
Re: Help on iterating 2 arrays and also comparing the values?
The problem is, in this other situation - take for example if the age of tom changes from 5 to 6 in table A I need to update tom's age in table B and these two tables are on different databases. Or maybe my question should be, how do you think I can go about it?
Thanks a lot.
Thanks a lot.
Re: Help on iterating 2 arrays and also comparing the values?
Hello,
What database are you using? Is this MySQL?
Thanks
What database are you using? Is this MySQL?
Thanks
Re: Help on iterating 2 arrays and also comparing the values?
No, I am using Apache Derby.
- mrvijayakumar
- Forum Commoner
- Posts: 58
- Joined: Tue Aug 18, 2009 12:39 am
- Location: Chennai city, India
- Contact:
Re: Help on iterating 2 arrays and also comparing the values?
Hi all,
I written coding to solve this issue, i hope this link will help or this will tune some brains to come out with better output. Please tell me your feedback's about this link ,
http://www.vijayakumar.org/index.php/20 ... ay-on-php/
I written coding to solve this issue, i hope this link will help or this will tune some brains to come out with better output. Please tell me your feedback's about this link ,
http://www.vijayakumar.org/index.php/20 ... ay-on-php/
Last edited by mrvijayakumar on Fri Aug 28, 2009 9:40 pm, edited 2 times in total.
Re: Help on iterating 2 arrays and also comparing the values?
Hello,
I honestly think if you take a look at JOINs, Sub Queries and Unions, you can solve this problem with no processing on PHP's side. BUT, I dont know Derby, I dont know what it's capable of.
Thanks
I honestly think if you take a look at JOINs, Sub Queries and Unions, you can solve this problem with no processing on PHP's side. BUT, I dont know Derby, I dont know what it's capable of.
Thanks
Re: Help on iterating 2 arrays and also comparing the values?
Wow mrvijayakumar that's brilliant!!!
What happens if table two had more than one row with the same value in it? For example if the age of Tom in Table one has been changed from 5 to 6 and it is still 5 in table two, will it update just that single Tom's age in table two or will it update every record that has 5 in it to 6?
Cheers
What happens if table two had more than one row with the same value in it? For example if the age of Tom in Table one has been changed from 5 to 6 and it is still 5 in table two, will it update just that single Tom's age in table two or will it update every record that has 5 in it to 6?
Cheers