nanou Posted May 18, 2011 Share Posted May 18, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/ Share on other sites More sharing options...
anupamsaha Posted May 18, 2011 Share Posted May 18, 2011 What do you see when you do the following? print_r($theme) Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217027 Share on other sites More sharing options...
nanou Posted May 18, 2011 Author Share Posted May 18, 2011 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 :'( Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217044 Share on other sites More sharing options...
anupamsaha Posted May 18, 2011 Share Posted May 18, 2011 Put the print_r after the isset() statement to see if you are actually getting an array or not. Regarding turin goff the error, try this at the top of the PHP code: ini_set('display_errors', 0); Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217051 Share on other sites More sharing options...
nanou Posted May 18, 2011 Author Share Posted May 18, 2011 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217053 Share on other sites More sharing options...
anupamsaha Posted May 18, 2011 Share Posted May 18, 2011 Can you please paste the output enclosed in "code" tag here (click on the # button in the editor toolbar). This will help us read code and this array type output clearly. Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217059 Share on other sites More sharing options...
nanou Posted May 18, 2011 Author Share Posted May 18, 2011 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217069 Share on other sites More sharing options...
pornophobic Posted May 18, 2011 Share Posted May 18, 2011 C'ést résolu? Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217077 Share on other sites More sharing options...
nanou Posted May 18, 2011 Author Share Posted May 18, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217079 Share on other sites More sharing options...
pornophobic Posted May 18, 2011 Share Posted May 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217090 Share on other sites More sharing options...
nanou Posted May 18, 2011 Author Share Posted May 18, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217094 Share on other sites More sharing options...
nanou Posted May 18, 2011 Author Share Posted May 18, 2011 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217108 Share on other sites More sharing options...
pornophobic Posted May 18, 2011 Share Posted May 18, 2011 Are you using array()? example: $themes = array('theme1', 'theme2', 'etc...'); That's all that you would really need to be doing when you put data in the array. Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217116 Share on other sites More sharing options...
nanou Posted May 18, 2011 Author Share Posted May 18, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217127 Share on other sites More sharing options...
pornophobic Posted May 18, 2011 Share Posted May 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217147 Share on other sites More sharing options...
pornophobic Posted May 18, 2011 Share Posted May 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217174 Share on other sites More sharing options...
nanou Posted May 18, 2011 Author Share Posted May 18, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217181 Share on other sites More sharing options...
pornophobic Posted May 18, 2011 Share Posted May 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217201 Share on other sites More sharing options...
nanou Posted May 18, 2011 Author Share Posted May 18, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217216 Share on other sites More sharing options...
pornophobic Posted May 18, 2011 Share Posted May 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217224 Share on other sites More sharing options...
pornophobic Posted May 18, 2011 Share Posted May 18, 2011 or, if semantics isn't your thing add <?php error_reporting(0); to the beginning of entete.php Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217225 Share on other sites More sharing options...
nanou Posted May 18, 2011 Author Share Posted May 18, 2011 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! Bye Anne Quote Link to comment https://forums.phpfreaks.com/topic/236753-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1217244 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.