Jump to content

Warning: implode() [function.implode]: Invalid arguments passed in


nanou

Recommended Posts

Hello,

I'm just a beginner (and french sorry for my language) : have some pb with my little implode function.

It's Running well on my local webserver (MAMP - PHP PHP Version 5.2.17) but when tested on ovh server (PHP4) show this error :

Warning: implode() [function.implode]: Invalid arguments passed in /homez.xx/myPathHere/entete.php5 on line 6

I understand

1/ that one argument is missing but don't find the right syntax

2/ I have tried to turn this file on php5 with this extension (ovh is under php4)

Here is my code in page defining the value and where stay my query (entete.php5)

 

<?php

if (isset($theme)) {

$t = implode(',',$theme);

$lien = "aide.php5?theme=".$t;

$aide = '<a href="'.$lien.'">'.$onglet[0].'</a>';

} else {

$aide = "";

}

?>

 

 

Here is my code in page which show result (aide.php5)

 

$t = explode(',',$_GET['theme']);

$n = count($t);

if ($n == 1)  {

$where = "id = ".$t[0];

} else {

$where = "id = ".$t[0];

for ($i=1;$i<$n;$i++) {

$where .=  " OR id=".$t[$i];

}

}

Hope someone kindly help me : thanks in advance

Link to comment
Share on other sites

I'm sorry I have turn my ini config to display my errors and I don't know how desactivate this : so now your print_R  show… nothing : I'm searching now how to set ini parameters by default  :'(

Link to comment
Share on other sites

I've done it (thanks!):

here is the result :

 

Array

(

    [0] => 1

    [1] => 2

    [2] => 3

    [3] => 4

    [4] => 5

    [5] => 6

    [6] => 7

    [7] => 8

    [8] => 9

    [9] => 10

    [10] => 11

    [11] => 12

    [12] => 13

    [13] => 14

    [14] => 15

    [15] => 16

    [16] => 17

    [17] => 18

    [18] => 19

    [19] => 20

    [20] => 21

    [21] => 22

    [22] => 23

)

 

 

 

 

Link to comment
Share on other sites

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
    [6] => 7
    [7] => 8
    [8] => 9
    [9] => 10
    [10] => 11
    [11] => 12
    [12] => 13
    [13] => 14
    [14] => 15
    [15] => 16
    [16] => 17
    [17] => 18
    [18] => 19
    [19] => 20
    [20] => 21
    [21] => 22
    [22] => 23
)

Link to comment
Share on other sites

Euh non, car la requete s'execute correctement, en local et en ligne comme je vous le disais:

ce n'est pas ça le problème,

c'est le message d'erreur s'affiche toujours en ligne (pas en local)

Re: Warning: implode() [function.implode]: Invalid arguments passed in

Link to comment
Share on other sites

Je comprender.

Tu devrait actualiser à PHP5 pour le motif de PHP4 est mort pendant quatre ans.

Ce faire pour la compatibilité. C'est peut être la problème

 

English:

I understand.

You should update to PHP5 for the reason that PHP4 is dead for four years.

Do this for compatibility. It may be your problem.

Link to comment
Share on other sites

I don't think so because ,

I've tried to turn on in php5 just the concerned 2 files (with extension php5 ) but pb is the same on line:

Request is ok on both side

This error message "Re: Warning: implode() [function.implode]: Invalid arguments passed in" is only displaid online (where php 4 is running)

do you think that I have to turn more radically, the distant server (ovh) in php5 using  a . htaccess?

I thaught that it was really a question of missing argument, don't you think so?

Link to comment
Share on other sites

So I have followed your advice:

I have turned webserver (ovh) on php 5 with a .htaccess containing  just SetEnv PHP_VER 5

But same problem

I'm rather sure that my array is not correctly defined : coul'd you se how set 2 arguments

like this example found on php.net

 

<?php 
function implode_key($glue = "", $pieces = array()) { 
    $arrK = array_keys($pieces); 
    return implode($glue, $arrK); 
} 
?>

Link to comment
Share on other sites

Yes, in some of my pages, I have arrays

ex: page1.php contains

<?php
$theme = array(1,2,3);

page2.php contains

<?php
$theme = array(1,2,5,16,17,18);

These are the numeric references id to the themes records id in my help database and theorecally clicking on the link containing these arrays must display the referenced result in help.php

Link to comment
Share on other sites

To be clear, you want a different link for each item in the array, correct?

What it looks like you are trying to do is put all help topics into a string, pass the string and display several topics all at once on one page.

That is why I am asking.

 

If you could clarify that for me. I have some code to print separate links here.

 

$theme = array(1,2,4,54,3,6,97);

if (isset($theme)) {
   $n = count($theme);
   $x = 0;
   	while($x < $n) {
	$lien = "aide.php5?theme=".$theme[$x];
  		$aide = '<a href="'.$lien.'">Theme ' . $x . '</a>'; //you had $onglet here before, you can change the names to whatever you liek
	echo $aide.  '<br />';
	$x++;
}
} else {
echo 'no results';
exit;
}

 

That will print out the links in a vertical row.

 

I will post an example aide.php in a moment.

 

Link to comment
Share on other sites

Here is the aide.php that would go with what I gave you earlier.

 

//db connection
mysql_connect('localhost', 'root', '');

$dbname = 'help_db';

mysql_select_db($dbname);

$theme = $_GET['theme'];

$sql = "SELECT * FROM aider WHERE id = '$theme'";

$result = mysql_query($sql);

if ($row = mysql_fetch_array($result)) {

//contents here.

echo '<strong>Titre: ' . $row['titre'] . '</strong>';
echo '<br />Contenu: ' . $row['contenu'];

}

else {
echo 'no topic found';
exit;
}

 

 

That is using a little db that i just whipped up.

 

My table, "aider" looks like this:

 

CREATE TABLE IF NOT EXISTS `aider` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `titre` varchar(255) NOT NULL,
  `contenu` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

 

Probably not what you want, but it holds a title, contents and the auto incrementing id. If this isn't what you were going for, I have someone that can help you in proper French, if you like.

 

Link to comment
Share on other sites

Ok

I have

1/ a db, called tb_aide , containing following 3 fields (id, theme, aide) with 30 records containing each an help explanation

2/ All the pages of my website are containing (or not, but when necessary) contextual id references ($theme = array(1,2,3,4);)

3/ My link to the record is

if (isset($theme)) {

$t = implode(',',$theme);
$lien = "aide.php?theme=".$t;
$aide = '<a href="'.$lien.'">AIDE</a>';

} else {
$aide = "";//if no array in the page because not necessary
}

3/ A page aide.php containing exploding code

$t = explode(',',$_GET['theme']);
$n = count($t);
if ($n == 1)  {
$where = "id = ".$t[0];
} else {
$where = "id = ".$t[0];
	for ($i=1;$i<$n;$i++) {
	$where .=  " OR id=".$t[$i];
}
}

and request

SELECT aide, theme, id FROM tb_aide WHERE id = 1 OR id=2 OR id=17 OR id=18  OR id=23

Link to comment
Share on other sites

SELECT aide, theme, id FROM tb_aide WHERE id = 1 OR id=2 OR id=17 OR id=18  OR id=23

 

I know what the script you have does, it's what you want to do with all the results you will have after the query is run. You might not even need to implode any array.

 

"WHERE id = 1 OR id=2 OR id=17 OR id=18  OR id=23" will select ALL of them if they exist. Do you want them all displayed on the same page? If yes, then implode is needed, but if you want to list the topics, and have each topic on one page with a link to each one, you do not need to implode any array. That is why I am asking this. You might not even have to implode anything.

Link to comment
Share on other sites

I show you both results, in 2 print screen

1/ local display

2/ online display

I think it will be more clear : I need the implode function because all ma pages are not containing the same array values

It is running in both case (only pb is that error message online)

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Sorry for misunderstanding you.

 

Do you happen to include entete.php5 in aide.php5?

You must. I visited the website and the error message is displaying on aide.php but the error is caused by entete.php.

You either have to remove the include, or only include it if you need to with an if() statement.

Link to comment
Share on other sites

Hello!

I'have added your :

error_reporting(0);

And the error message do not appear anymore even if an argument is missing.

That was the goal for instance: later I'll try to understand what was the correct "semantics"!

Thank you so much for your time, your patience and help! :D

Bye

Anne

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.