SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    UK
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array merge problem

    Hi.
    I am using "The PHP Anthology" as a reference to update my old PHP script to use PEAR with some success. However I have copied the script from the archives relating to PEAR Tables and have a problem.
    Having copied the script and changed everything to access my own database I now come up with the following error, twice:-
    Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /ho*** and I do not know which part of my script will cause this.
    As it says the problem is on line 870 it has to be flagged up in the PEAR module.
    Can anyone suggest which array I am passing that might be wrong?
    Thanks.

    John.

  2. #2
    SitePoint Zealot smadeira's Avatar
    Join Date
    Oct 2003
    Location
    Pennsylvania
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We would need to see some code to help you. Based on what you say there is an array_merge command on line 870 in the file and the second parameter in your function call is not actually an array. You may want to verify that it is spelled correctly, or that if you are passing the array into the method that is having the error that you spelled everything corrctly, etc.
    Scott

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    UK
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.
    the relevant code is below from which you might see it is copied from the PHP Anthology. Clearly I substitute my own database name in the "SELECT" statement.

    // Include the PEAR Structures_DataGrid class
    require 'Structures/DataGrid.php';
    // instantiate grid for 40 records per page
    $datagrid = new Structures_DataGrid(40);
    // Define our Datasource options, in this case MDB2 MySQL
    $options = array('dsn' => "mysql://$user:$password@$db_host/$db_name");
    // Define the Query

    $sql = "SELECT * FROM MyDatabase";
    // Bind the Query to our Datagrid
    $bind = $datagrid->bind($sql, $options);
    // Test for Errors

    if (PEAR::isError($bind))
    {
    error_log('DataGrid Error: '. $bind->getMessage());

    } else {
    // Define our Column labels, using a 'column' => 'Label' format
    $columns = array(
    'fname' => 'First name',
    'lname' => 'Last name',
    'phone' => 'Phone',
    );
    $datagrid->generateColumns($columns);
    // Some more options, for our renderer
    $renderer_options = array(
    'sortIconASC' => '⇑',
    'sortIconDESC' => '⇓',
    'headerAttributes' => array('bgcolor' => '#E3E3E3'),
    'evenRowAttributes' => array('bgcolor' => '#A6A6A6'),
    );
    $datagrid->setRendererOptions($renderer_options);
    // Add some final attributes to our table
    $renderer = $datagrid->getRenderer();
    $renderer->setTableAttribute('cellspacing', 0);
    $renderer->setTableAttribute('cellpadding', 5);
    $renderer->setTableAttribute('border', 1);
    // Render the table, be sure to check for errors
    $gridbody = $datagrid->getOutput();
    if (PEAR::isError($gridbody))
    {
    error_log('DataGrid render error: ' .
    $gridbody->getMessage());
    $gridbody = '';
    echo"$gridbody";
    }
    // Finally, render the pager, again checking for errors
    $gridpager = $datagrid->getOutput(DATAGRID_RENDER_PAGER);
    if (PEAR::isError($gridpager))
    {
    error_log('DataGrid render error: ' .
    $gridpager->getMessage());
    $gridpager = '';
    }
    $gridsource = $gridbody . $gridpager;
    }
    ?>
    <!DOCTYPE html public "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Member Details</title>
    <meta http-equiv="Content-type"
    content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <h1>Member list</h1>
    <?php
    echo $gridsource
    ?>
    </body>
    </html>

  4. #4
    SitePoint Zealot smadeira's Avatar
    Join Date
    Oct 2003
    Location
    Pennsylvania
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We need to see the file that has "line 870" in it. The filename should be in the error message you get. you need to go there and work backwards to see what problem you are having in your code.

    Having not read the php anthology I don't have any inside info on "just go look here..."
    Scott

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    UK
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is the problem, if I could get at the file I might be able to diagnose it myself but I am assuming the line 870 is in the PEAR DataGrid module and that is installed on the server I use so I do not have direct access to it.

    John.

  6. #6
    SitePoint Zealot smadeira's Avatar
    Join Date
    Oct 2003
    Location
    Pennsylvania
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the filename given in the error message?

    You can download the package from pear.php.net and find that file and look for the array_merge() command that is the problem.

    You should also ask the server owner to let you know what version they are using so you download the right thing.

    Without the source code there isn't much you can do to figure out what the problem is.
    Scott

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    UK
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, looks like that is the best way forward. I am using the latest version I believe (V9) and wonder if maybe I'm passing a null array to cause this problem but it looks like I will have to delve into the PEAR module.

    Thanks again for your advice.

    John.

  8. #8
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    UK
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As suspected one of the arrays I was passing to be merged was a null array. Still not sure where the problem arose or why it didn't show in the error checking but I re-wrote the login credentials and first part of the script and up it came.
    I'm very impressed with the PEAR module but just one other question. In my "old" script I showed email addresses as clickable links in a table of names and addresses by wrapping them in an ahref=mailto: statement. Is there a way to do this using the PEAR datagrid? It doesn't seem so easy.

    John.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •