Page 1 of 1

[function.implode]: Bad arguments. ???

Posted: Sun Mar 04, 2007 10:01 am
by Adamck

Code: Select all

Warning: implode() [function.implode]: Bad arguments. in /..../......./......_....../wanted.catlistings.php on line 133

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /..../......./......_....../wanted.catlistings.php on line 165

Code: Select all

<?
				// newest function 
		
				if ($_GET['start'] == "") $start = 0;
				else $start = $_GET['start'];
				$limit = 20;
				
				$croot = $_REQUEST['parent'];
				$cntr=0;
				while ($croot>0) {
					$crw = getSqlRow("SELECT * FROM probid_categories WHERE id='$croot'");
					if($cntr == 0) {
						$catname = $crw['name'];
					} else {
						if($crw['parent'] != $croot) {
							$catname = "$crw[name] : $catname";
						}
					}
					$cntr++;
					$croot = $crw['parent'];
				}
		
				$catname = trim($catname);
		
				$mysqlVersion = substr(mysql_get_server_info(),0,1);
		
				## get all subcats
				reset($cat_array);
				if ($catname!="") {
					while (list($cat_array_id, $cat_array_details)=each($cat_array)) {
						list($cat_array_name, $userid) = $cat_array_details;
						$strResult = strpos($cat_array_name,$catname);
						if (trim($strResult)=="0") $cat_id[$catcnt++] = $cat_array_id;
					}
					$all_subcats = implode (",",$cat_id);
					
					$subcatquery="(a.category IN (".$all_subcats.") OR a.addlcategory IN (".$all_subcats.")) AND ";
				} else { 
					$subcatquery = "";
				}
				
				if ($mysqlVersion>=4) {
					$additionalQuery = "SQL_CALC_FOUND_ROWS ";
				} else {
					## this is only used if the mySql is older than v4. Slower version
					$nbItems = getSqlNumber("SELECT DISTINCT a.id, a.itemname, 
					a.nrbids, a.enddate FROM probid_wanted_ads a WHERE
					".$subcatquery." 
					a.active=1 AND a.closed=0 AND a.deleted!=1 
					ORDER BY a.".$orderField." ".$orderType);
				}
		
				$getAds = mysql_query("SELECT ".$additionalQuery." DISTINCT a.id, a.itemname, 
				a.nrbids, a.enddate, a.picpath FROM probid_wanted_ads a WHERE
				".$subcatquery." 
				a.active=1 AND a.closed=0 AND a.deleted!=1 
				ORDER BY a.".$orderField." ".$orderType." LIMIT $start,$limit");
		
				if ($mysqlVersion>=4) $nbItems = mysql_result(mysql_query("Select FOUND_ROWS() AS nbr"),0,"nbr");
		
				if ($nbItems==0) {
					echo "<tr><td colspan=5 class=contentfont align=center>".$lang[nowanted]."</td></tr>";
				} else {
					if ($nbItems>($start+$limit)) $final = $start+$limit;
					else $final = $nbItems;
					
   				while ($ad = mysql_fetch_array($getads)) { ?>
						<tr class="<? echo (($count++)%2==0)?"c2":"c3"; ?>">
							<td align="center"><? 
					if ($ad['picpath']!="") {
							echo "<a href=\"wanted.details.php?id=".$ad['id']."\"><img src=\"makethumb.php?pic=".$ad['picpath']."&w=40&sq=Y&b=Y\" border=0></a>";
					} else echo "N/A"; ?>
               </td>
               <td nowrap="nowrap" class=contentfont><a href="wanted.details.php?id=<?=$ad['id'];?>">
                  <?=$ad['itemname'];?>
                  </a></td>
               <td class=contentfont align="center"><b>
                  <?=$ad['nrbids'];?>
                  </b> </td>
               <td align="center" class=contentfont><? echo timeleft($ad['enddate'],$setts['date_format']);?></td>
            </tr>
            <? } ?>
            <tr>
               <td colspan=5 class=contentfont align=center><? 
					  paginate($start,$limit,$nbItems,"wanted.categories.php","&parent=".$_REQUEST['parent']."&orderField=$orderField&orderType=$orderType"); 
					  ?></td>
            </tr>
            <? }?>
         </table></td>
   </tr>
</table>
Please help, im running phpprobid and i keep getting this error on the "wanted ads" page.
If you can see a bug/error and can help i would be very greatful!
Adam.[/syntax]

Posted: Sun Mar 04, 2007 10:10 am
by John Cartwright
Instead of using [quote] tags, use

Code: Select all

tags..

Please also only post the relevant portions of the code.. 

By the sounds of it though, without looking at the code the error originates when you pass it an invalid array. 
Using var_dump() on variables often helps us track what actually happening with our code.

Posted: Sun Mar 04, 2007 10:19 am
by Adamck
Hi sorry about the bad posting skills... edited it now.
Im not sure what you mean im a novice with php and just a little lost with how/why the errors exist.
I think the second error is just some missing SQl which i can fix but the implode error has lost me.
Ad.

Posted: Sun Mar 04, 2007 10:26 am
by John Cartwright
first thing is first, at the end of every mysql_query(..) add or die(mysql_error());

So...

Code: Select all

mysql_query(..) or die(mysql_error());
This should essentially tell us why your query isn't returning any results, and in turn isn't playing nice with implode.

As I mentioned previously, it's best ettiquette to only post the relevant php code.. I sure don't like digging through peoples code.

Posted: Sun Mar 04, 2007 10:35 am
by Adamck
as i said i am a novice with php and i did cut the code down a little,
I didnt want to remove any parts of code that where needed to find the problem.
I will try what you have said... if not please have a look at...
http://www.merseybay.com/wanted.categories.php
And click Automobiles & Bikes (1)
The errors are reported on that page.
It seems to be a problem with all installs of phpprobid and they dont seem to want to help much either.
Thanks for any help tho i really do appreciate it.
Adam.

Posted: Sun Mar 04, 2007 10:42 am
by John Cartwright
Did adding mysql_error() reveal anything? :?

Posted: Sun Mar 04, 2007 10:56 am
by Adamck
Can you please show me where exactly i put that code.
I seem to be just making things worse lol
Sorry i am a noob tho...
thanks.
ad.

Posted: Sun Mar 04, 2007 11:41 am
by Chris Corbyn
Put it everywhere you call mysql_query() in your code. It basically says "If this query is failing, tell me why..".

Now, whatever you're passing to implode() is not an array like it should be, and from looking at your code it seems that it's becuase you never create $cat_id, you just start filling it up in the loop.

Code: Select all

$cat_id = array(); //Put this just before your loop