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




Merging 2 Mysql Resultant Arrays


im currently executing sql queries on two seperate mysql servers.  i take back each of these results into individual tables to display them. 

What i wanted to do was perform a merge of the two arrays, so that i could order the results by my "TimeStamp" field.

When i try to perform a basic " $mergedresult = array_merge($result, $isaresult); " i get the following.

"
Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:Program Filesxampplitehtdocsseatpub.php on line 164

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:Program Filesxampplitehtdocsseatpub.php on line 164   "

Im rather new to this and so havent delt with arrays before, but im under the impression my results from the sql queries, are Assoc arrays.  can these be merged ? do i need to use an alternate php function ?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Merging Arrays
I want to merge 2 arrays and if the key is already there add the values. PHP Code:

Merging Arrays
I need to merge each member of one array with each member of a second.

$colors = array("red", "black", "blue", "white");
$cars = array("chevy", "ford", "toyota", "honda");

I have tried using embedded while loops and I keep getting strange results. When I get results at all. I think it is getting caught in an endless loop.

Merging Unknown Arrays
Is there a better way to do this?

$command = '$array = array_merge($array['' .
implode(''],$array['',array_keys($array)) . '']);'
eval($command);

Merging Results From Two Mysql Databases
I have made two websites on seperate servers both with a database of their own.
They are identical but with different results in the databases. I want to make a page on one of the sites that will merge the information from both databases.

e.g.
site 1 has a list in date order
site 2 has a list in date order

I want site 1 to have the list merged together to form one big list but still be in date order. Also I want to be able to have the results of site 2 in a different font colour to site 1.

i.e.
Site 1 results

10th jan - something
15th jan - something else
19th jan - more

Site 2 results

11th jan - even more
13th jan - some more
16th jan - more stuff

Merged page

10th jan - something
11th jan - even more
13th jan - some more
15th jan - something else
16th jan - more stuff
19th jan - more

can anyone help with this?

Merging Mysql Table Fields
How can I merge multiple fields of a table for my query.

suppose I have 2 table

table1
=============
field1      field1
=============
Lam         20
Ld            9
Auz          3

so I want to check where does keyword "Ld9" Exisit

so what will me my query for
select * from table1 where field1+field2=$keyword

Mail Merging
I am trying to work out ways at which to perform mail merging from a msql database, using php.

My ideas so far are:

1. Creating a *.csv file and then sending it via email to the person who requested it.

2. Uploading a document (pdf) and producing documents for the person.

Merging Pdfs
I'm using PHP 4.4.4. Can anyone recommend any freeware that will
merge PDFs into one? On Google, I found this link

but the download function is giving a 404.

Anyway, most curious what your thoughts are.


Merging XML In PHP Using SimpleXML And DOM
I'm having trouble trying to merge two SimpleXML objects (user preference settings) in PHP.  It should be simple enough - the objects have the same root element, and I simply want to merge at the top child level.  However, the code I'm providing here, while it executes, does not work. At the end of the merge() function, the merged preferences are empty. Code:

Merging Two Array
I need and idea regarding how to merge two seperate data from the form. The first field form type is "textbox" and second is "file". and the two fields were in an array form like.

<form name="myform" method="post" action="action.php">
<input type="text" name="myfield[]"><input type="file" name="myimage[]">
<input type="text" name="myfield[]"><input type="file" name="myimage[]">
<input type="text" name="myfield[]"><input type="file" name="myimage[]">
<input type="text" name="myfield[]"><input type="file" name="myimage[]">
<input type="text" name="myfield[]"><input type="file" name="myimage[]">
</form>

so how can I merge and loop two data through php. I need to use the array value on my script if...else condition.

loop {
if (....both array is not blank) {
//do something
print first array;
print second array
}
}

Merging 2 Pdf Docs
I want to merge 2 pdf docs.  The only thing is I want to replace the cover page of pdf1 with the pdf that I created.  How can I accomplish this using php?

Merging Sound Files
Is it possible to merge sound files with PHP? I don't need to otherwise be able to edit the files, just merge a number of sounds.

Arrays In MySQL
Can I store an array into an SQL database and then take it back out and it would still be an array?

Arrays Into Mysql
The mysterious message: Couldn't add data to the CATLINK table:Unknown column 'Manufacturing' in 'field list' PHP Code:

Questions On Merging Two Text Files....
I will have a form field that will allow one of two text files to be uploaded to the db. This text file will have sections that are defined something liek this;

Merging Multiple Images With Imagecopy
I've been working on some code for a bit and just can't figure out my problem. My code runs through a series of variables and creates a seperate image for each, then merges them together. Code:

Merging 2 Tables With A Select Query?
I have two tables in my database. One is called 'hotfood', the other is 'coldfood'. What I want to do is have a single SELECT query for both of these tables. This is so I can then use 'mysql_num_rows' on this query, like so.

if(mysql_num_rows($id)==0)
{
print "Food type does not exsist";
}
else
{
 --
}

It basicaly to do a search type thing, the above checks that the food name exists by checking both the hot and cold food table, therefore I need to two merged into the select query so that I can search it.

Merging Two Images In An Addative Fashion
I am looking through the PHP manual and am not clear on whether it is possible to do the following with any standard function:  I want to merge one image with another, like with imagecopymerge(), but do it in an additive fashion. 

For example if a pixel in image 1 had a red value (red brightness) of 126, and the same pixel in image 2 had a red value of 20, then the red value of the pixel in the merged image would be 146, etc. As opposed to just replacing the image information in image 1 with that in image 2, or overlaying image 2 as a transparency over image 1.

MySQL Query And Arrays
I have a 'links' category on Table A and I want to retrieve the links from the Table and display them in a list-like fashion when the page is called upon. How would I go about seperating the links from one another (there a space inbetween each link.. EXAMPLE: http://asdf.com http://asdasd.com http://asdfff.com), loading them into an array (or using the best possible method to acces them easily) and then displaying them in a list like fashion..?

Arrays And MySQL Querys
I can't get an $array[key] to be used as a select query on a mySQL database.

I have a 'parts list' which displays on a page (works fine) and is a form.
At the end of each row is a input type='text' (quantity) cell with a default
0

The quantity can be altered.
At the bottom of the table (form) is a submit to basket Button

echo "<form action='basket.php' method='POST'>....

Arrays And While Mysql Functions
How can I get this array to work? I am trying to add data to an array for every row of data? This is a sellection of queries that I need to parse into an array so a function can use the arra to draw a graph. I am new to arrays how can I get this to work? Code:

Arrays Working With MySQL
How can I grab a certain field of a Multi-Dimensional Array using the ID. I have set for that Array? I just want to be able to create a simple function to do pretty much what this function does, but for an array. Code:

Passing PHP Arrays To Mysql Best Solution
I am relatively new to PHP and until now I have only needed to use relatively simple php/mysql solutions.

I am working on a problem where I need to store CD information (Artist Name, Album Name, Track Names, Catalog Number)

I am working on a solution with two tables "album" and "tracks" and I am using the catalog number as a key to link the two.

The problem I am having is coming up with the best way to populate the tracks table as there are several tracks for each release. I am assuming that an array would be the correct way and maybe a dynamic form to input the tracks where you decide the number you need to add and this then creates a form with "n" input boxes?

Insert Multiple Arrays Into Mysql
I am having problems writing the code to generate my SQL INSERT query. I have 3 arrays and one static variable ($cat_number):

$track_name[]
$music_link[]
$track_number[]
$cat_number

Should I be using a foreach command. I know how to insert multiple values but its generating the query that i'm not sure about.

INSERT INTO table (track_name, music_link, cat_number, track_number)
VALUES
(var1,var2,var3,var4),
(var5,var6,var7,var8),
(var9,var10,var11,var12);

I don't want to store the actual array in the dataabase, I am just using an array to catch the data.

Multiple Arrays And Foreach To Put Into A Mysql Db?
I created 3 arrays with data and i want to insert them i a mysql db. PHP Code:

Multiple Selections, Arrays, And MySQL
OK this place has been great with explaining things that are way over my head, now I could use a boost to get my brain working again. I have a form with a drop down menu with multiple selections. When the form is submitted it shows up in the DB field as "array", as well as the page where I how the form's info. I think I have to set up an array, and loop(?) it, or do I need to implode the array? And how and where would I put these commands on this incredible messy form page. Would someone mind helping me get started?

Here's the form: (please don't make fun of me, I used to a Dreamweaver extension to create the form using PHP, before I decided to try and write this stuff myself. I am re-doing the form but this actually works for now, so I am using it. Code:

Sorting Arrays Retrieved From A MySQL Db
I am trying to make a news system. I have done it, but the news are listed with the last on at the bottom. This makes it kind of troublesome to read the latest news when you enter the site and there are a lot of news items, cause you would have to scroll down.
PHP Code:

MySQL Field Type For Arrays
What type of field type are arrays stuffed into? VARCHAR ? TEXT?

Populating Arrays From MySQL Query
I have the following code: http://pastebin.com/746601

The field 'material' in 'is_material' contains multiple values for each
record in 'is_details'. Because of this I have used
'is_material_lookup' as a reference lookup table containing the
'style_code' and 'material_code' which refer to their full details in
the respective tables.

Currently I have got the script outputting all the details and one
material then in the next block of data, repeating the details with a
different material. What I would like to achieve is having 1 block of
data with a list of all materials in that, instead of the repeat, but
sadly I can't know exactly how to do it.

How To Insert Arrays Into Mysql Database
This is my order.php file. Now I try to make a new php-file for processing the ordered items on this page, into another table "ordered_products" in the database. I want to INPUT following values into the table "ordered_products":
'order_num', 'order_item' and 'order_ant'

I know how to insert rows in a table using the INSERT query, but I don't know how to do it while looping the arrays. I have to fetch the arrays from this page, and insert them row by row in the "ordered_products" table. Code:

Using Arrays With Mysql Query Results
im currently in the process of making a piece of code that will firstly take all the data from a table in mysql and then assign it to an array. This data will consist of several different rows of data each with different infomation for each field in the table.

i want to be able to use an array in a loop so that depending on which number of the loop is on will change the infomation that is assigned to a certain array. Code:

Pesky Checkbox Arrays And A MySQL Song Database
I'm not one who likes to ask for help, so for the last three days my brain has been turning to mush while I try to create a DJ Request Song Wish List. Anyone who can help me out will be saving me from severe insanity. :)

My goal is to:

1. Display search results for song title, artist and genre. (accomplished)
2. Allow the user to add songs to their Wish List. This is done by displaying checkboxes with the corresponding value equal to the songID. (working on it)
3. Allow the user to update their wishlist by adding/deleting songs.

So far I have a form that retrieves the song info from a database in a repeating region. In Dreamweaver:

<input name="songID[]" type="checkbox" id="songID[]" value="<b><?php echo $row_RecordsetSearchResults['Title'];?></b> by <?php echo $row_RecordsetSearchResults['Artist'];?>">

This puts the corresponding songID number into a checkbox value, which in turn is submitted by form POST action to the following page as an array.

To process this array I have:

if(isset($_POST['songID']))
{
$songID = $_POST['songID'];

print '<p>Song IDs:</p>'
// process items
$n = count($songID);
for($i = 0; $i <= $n; $i++)
{
//See if the values are being passed from POST
echo $songID[$i];
echo '<br>'
}
$songsInsert = '*'.implode('*',$_POST['songID']).'<br>'
$insertSQL = sprintf("INSERT INTO wishlist (Username, Title) VALUES (%s, %s)",
GetSQLValueString($MM_Username, "text"),
GetSQLValueString($songsInsert, "text"));

mysql_select_db($database_ToneDeaf, $ToneDeaf);

$Result1 = mysql_query($insertSQL, $ToneDeaf) or die(mysql_error());
}

The problem is, I'm using implode. It does store the songs, but only as one long block of text. So if the user picks "New York by Frank Sinatra" and "Hot In Here by Nelly" it is stored as "*New York by Frank Sinatra*Hot In Here by Nelly*" Obviously this gives me no options to make this actually readable, let alone allow the user to remove one of those songs from their list (both would be have to be removed.)

Also, referencing only the songID number as stored in the music database doesn't seem a good option, since the song database will be changing frequently and song data may be overwritten. Not sure if there's a viable workaround there.

Originally I wanted to store Title, Artist, Genre under seperate columns so I could link them to something like "See more songs from this Artist." However the more I read about arrays and multidimensional arrays, I realize I'm not ready to go there yet. (I just started learning PHP two weeks ago.)

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:

Arrays Within Arrays, How To Split
I have been stumped on this one and it is probably easier than I think it is, especially since my brain is fried.

This is what my array looks like:
array(7) { ["injuredPerson"]=> string(0) "" ["dates"]=> string(0) "" ["describe"]=> string(0) "" ["location"]=> string(0) "" ["type"]=> array(3) { [0]=> string(8) "abrasion" [1]=> string(10) "amputation" [2]=> string(12) "asphyxiation" } ["part"]=> string(0) "" ["times"]=> string(0) "" }

This is actually an array of information from a form check. I have the error handling check the form and depending on if there is an error or not, the array gets populated with "" or an actual value(s).

I am testing a checkbox area of the form (the name is type, so type can hold an array of values, thats why it currently contains abrasion, amputation, and asphyxiation).

I have had no problem going through the array until I get to the area with an array within the array. Let me give you some code so you can see how I am doing this:

Searching Arrays With Arrays
ive looked through alot of the array search functions and i dont think any of them support arrays as the "needle" to search for.

so say i had a numeric array, $array1 with say 5 elements, 0-4, each element is a single word, lowercase.

say i had another numeric array structured the same way called $array2 with say about 5 elements, 0-4. Is there a function which i could use or does anyone know of an easy way to search every element in $array1 and compair it through each of the elements of $array2? and if a duplicate is found in $array2 have that element be removed or unset? im sure this can be done probably easy with some kind of loop function, but thats my weak point right now in php and im working on it.

Add To Arrays
this is the situation. i am passing variable thru an input form to a function on the same page.
within that function, it will determine if the checkboxes are checked, if it is checked, add that value to one array. if it is not checked, add to a different array.
i do not know the line to add to an array. i am trying array_push but that is not working. array_fill will not work either (do not have php 4.20 installed)

Different Arrays, How To Tell Them Apart?
Is there a function or way to tell the difference between these two types of arrays:

array(1,2,3,4,5,6,7,8,9,0);

array(1=>"one", 2=>"two", 3=>"three", 4=>"four");

The is_array() function does not distinguish between the two as they are both arrays and is_array looks to see if its an array, so back to step 1.

Anyways, is there a function or workaround to find this out??

Arrays
Is there any way that after filling the array in a loop with values that i can go back and start filling in the same array from scratch with a different set of values.

Arrays
is it possible to have an array (or the equivalent) that allows you to say like $text['hi']; or $text['this'];?

PHP 2D Arrays
Please how do we create 2D array and make it global in PHP.

PHP And Arrays?
How can one tell if a PHP array is a simple array or a hashed array
(key/valye). The gettype returns "array", but is there a function
that will tell me the type?

Also, when you have a mixed array, some flat, some hashed, how can you
tell the type of each element?

Using Arrays For Look-ups
Just a quick sanity check...

Sometimes it's useful to use an array as a kind of reverse lookup. For
example, the indexes being productIDs and the value being it's name.

If I do something like this...

$x = array();
$x[1] = 'foo'
$x[345] = 'foo'
$x[12345] = 'foo'

.... PHP is intelligent enough only to allocate 3 data chunks for this right?
As I type this, it seems far more obvious, but if someone could just
confirm :-)

WHILE And Arrays
I appear to have the logic on this one worked out(maybe) but when it goes through the while loop, it only echos the first element of the associated array. Now as a Test I echoed what it should be using as the keys and that works fine. So I don't understand why its failing. With out further ado, heres the problem.. So I have this string in the database, lets say that this string is... PHP Code:

Two Arrays As One
How do I convert the following two arrays into one, and loop through it? Code:
$sections = array("Articles", "Bio", "Disc", "Home", "Photos");
$table_ref = array("articles", "biography", "discography", "homepage", "photos");

for ($i = 0; $i < 5; $i++) {
if ($section == $sections[$i]) {
$result = mysql_query("SELECT * FROM $table_ref$i] WHERE artist_name LIKE '$artist_name' ORDER BY artist_name", $db)
or die("<font size="4"><b>Error =(</b></font><br><br>Unable to connect to database. Please try again later.");
echo create_page($artist_name, $sections[$i], $result);}}

Arrays
when i submit this form, how can i do similar type of processing for all of them,
like the first one i want to add to database, or any other processing maybe not related to database, also .. i can do also for the rest, rather than repeating my codes again and again, i know some sort of array.. but.. how Code:

How To Use Arrays
I want to assign some values from a database into an array. I have two fields, id & name. When I am finding the values from the database, I would like to assign the id to an array and the name into another array. I can do this using the array_push() . How can I then print the array? I tried to just print the variable but it give me 'Array'. Maybe a loop?
PHP Code:

Arrays
I have problems in trying to '++' an array value.
Every time I find a city I add it in the array,
and if I find it many times I increment the value (counter)
of the city. Here's the code:

$address = "http://www.cji.co.il/bw040609.txt";
$address_local = "bw040609.txt";
$lines = file($address_local);

$heading = "Companies covered in this CJI report:";
$heading_line = 0;

$towns = array();

for($i=0; $i<count($lines); $i++) {

$pos = strpos($lines[$i], "Location: ");
if($pos !== false) {
list($loc,$town) = preg_split("/: /", $lines[$i]);
if(in_array($town, $towns)) {
$towns[$town] = 1;
echo "Town added: $town<br>";

}
else {
$towns[$town]++;
echo "Town added: $town<br>";
}
}

}

foreach($towns as $key => $value) {
print "$key => $value<br>";
}

The output is like this:

Arrays
How to create one array that will hold numbers from 3 to 50, their
square roots, and number * 10?

example: 3, 1.43, 30
4, 2, 40

More About Arrays
Is it possible to read a multi-dimensional array from a file? How would one
represent a multi-dimensional array in a flat file? Is this possible? For
example, I want to have 3 elements in the array, each of which is an array
itself:

Element 1
ARRAY (1-4)
Element 2
ARRAY (1-120)
Element 3
ARRAY (1-1460)

I'd like to store this array in a delimitated flat file - all integers.

3|84|753|2|0|349|5|0| ... and so on

perhaps I need 2 files? other options? (I know... get a database...)

Arrays
I am reading the php manual online and don't understand the way arrays work.
It says arrays take a key, value pair which is fine I guess, but how do I
get an old fashion c style array? Are the keys like the indices?
say I want an array that contains the numbers 0 through 10, what do I make
the keys or does it even matter?


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