943,865 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 996
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 29th, 2009
0

MSqyl error

Expand Post »
U get the following error on my one page

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /usr/www/users/stealtf/components/com_aclassf/top.php on line 111

This is my coding
<?php
/**
*  This file is part of Almond Classifieds Component for Joomla! (site:http://www.almondsoft.com/j )
*  Copyright (C) 2008-2009 AlmondSoft.Com. All rights reserved.
*  http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL  
*/

include('funcs2.php');
 
function print_categories()
{ 
global $html_header, $html_footer, $categories,$ad_ind_width,$schopt,$ads_fields,$subcnmb,$javastl,$hghltcat,
$catl_width, $top_page_info,  $top_page_width, $topsearchfields, $top_leftcol,$catcols,$_REQUEST,$hdhctgrs,
$tbclr_1, $tbclr_2, $tbclr_3, $tbclr_4, $fntclr_1, $msg, $top_rightcol,$btmtophtml, $templ,
$top_bottom,$getcityval, $popctgr, $top_rightcol, $tmltads, $slctcntr, $indx_url, $use_ajax, $locations;

$top_rightcol="";

global $rmmbrloc;
if ($_REQUEST[$schopt]!=''){  

$cityhtml="&nbsp;<p class='pst1'>
<font class=stfntb> 
&nbsp; &nbsp; <b>".$ads_fields[$schopt][0].": ".$_REQUEST[$schopt]." </b></font>
&nbsp; &nbsp;&nbsp; &nbsp;  <font class='stfnt'>( <a href='{$indx_url}allc=1'>".$msg['all_cities']."</a> $rmmbrloc )</font> </font>
 
<br>
";

$citgtv1=$_REQUEST[$schopt];
$getcityval="$schopt=".checkgetfld($citgtv1)."&";
 
}

if ($_REQUEST[$schopt]!=""){$ltstcityv="&city=".checkgetfld($_REQUEST[$schopt]);}
else{$ltstcityv="";}


$grp_cnt=get_grpcnt();

$popctgr=""; $divkey1="0";  
foreach ($categories as $key => $value)
{
 
$aa1=split("_",$key);

if ($aa1[0]=='newcolumn'){$divkey1="0";   $categ[$key]="</td><td valign='top' align=left>";}
else {
if($aa1[0] == 'title')
{   

$p_val1=""; if ($divkey1=="1"){$p_val1="<p class='pst1'>";}
$categ[$key]= " 
$p_val1<p class='pst1'>
<TABLE BORDER=0 WIDTH='90%' cellspacing=0 cellpadding=0  >
<TR><td class='ct_group'><a href='{$indx_url}".$getcityval."md=browse&mds=search&gmct=".$aa1[1]."'>
<font class='ttl_grp'>".$categories[$key].":</a></font> &nbsp; (".$grp_cnt[$aa1[1]].") 
</TD></TR></table>
";

}else 
{

if (($categories[$key][2] != 'h') and ($key != 'evntcl'))
{$divkey1="1";$categ[$key]=print_cat_name($key);}

}
}

}

include ($templ['top']); 
return;
}

function get_grpcnt()
{ 
global $categories, $sql_mct1, $table_ads, $grpcnt, $gkey2, $HTTP_GET_VARS;
 
foreach ($categories as $key => $value)
{
$aa1=split("_",$key);
if($aa1[0]== 'title'){$kk1=0; 
if ($sql_mct1!=""){

get_gcnt2();
 
}
$sql_mct1="";
}
if($kk1==1 and $key!="evntcl" and  $key!="evcl_rpl" and 
$categories[$key][2]!="h" and $aa1[0]!='newcolumn'){$sql_mct1=$sql_mct1." catname='$key' or";}
if($aa1[0]== 'title'){$kk1=1; $gkey2=$aa1[1];}
}

get_gcnt2();
 
return $grpcnt;
}

function get_gcnt2()
{ 
global $sql_mct1, $table_ads, $grpcnt, $gkey2, $HTTP_GET_VARS;

if ($HTTP_GET_VARS['city']!=""){ $city_query=" and city='".$HTTP_GET_VARS['city']."' ";};
 
$sql_mct1=preg_replace ("/or$/", "", $sql_mct1);
$sql_mct1="( $sql_mct1 ) and ";
$sql_query="select count(idnum) from $table_ads where $sql_mct1 visible=1 $city_query";
$sql_res=mysql_query("$sql_query"); 
$row=mysql_fetch_row($sql_res);
$grpcnt[$gkey2]=$row[0];

}

 
function print_cat_name($key)
{
global $categories, $fntclr_1, $msg, $subcnmb, $getcityval,$popctgr, $indx_url;

# $dtupd=get_date_update($key); if ($dtupd!=''){$dtupd=$msg['updated_t'].": ".$dtupd;}

$vhtml= "
<nobr><a href='".sturl_ct_top($key,$getcityval, "1")."' >
".$categories[$key][0]."</a> <font class='ct_count'>(".get_cat_count($key).")</font></nobr> <br>
";
return $vhtml;
}




function checkgetfld($value)
{
$value=ereg_replace(' ', '+', $value);
$value=ereg_replace('@', '%40', $value);
$value=ereg_replace('!', '%21', $value);
$value=ereg_replace("'", '%27', $value);
$value=ereg_replace("\"", '%27', $value);

return $value;
}


function get_total_count()
{
global $cat_fields, $table_ads, $ct, $page, $adsonpage, $html_header, 
$html_footer; 
 
global $sqlaflcl;

$sql_query="select count(idnum) from $table_ads where $sqlaflcl
visible=1 ";
if( !($sql_res=@mysql_query("$sql_query")))
{echo $html_header;
echo "
<center>
<font FACE='ARIAL, HELVETICA'  COLOR='#bb0000' size=-1><b>
Error in connecting to ads MySQL table <font color='#000099'>'$table_ads'</font>.
<br> Seems, this table is not created, 
<a href='createtb.php'>click here </a> to create this table.
</b></font></center>
";
echo $html_footer;
return;
}

$row=mysql_fetch_row($sql_res);
$count=$row[0];
return $count;
} 



?>
Last edited by jjtao; Jul 29th, 2009 at 7:26 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jjtao is offline Offline
12 posts
since Jul 2009
Jul 29th, 2009
0

Re: MSqyl error

Hard to see which line is 111. Mark it.

Also, did you read the sticky post at the top of this forum on this topic ?
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,177 posts
since Jul 2006
Jul 29th, 2009
0

Re: MSqyl error

Sorry about that, I highlighted it, i did put the {code} deal but it still icoded it! thank you
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jjtao is offline Offline
12 posts
since Jul 2009
Jul 29th, 2009
0

Re: MSqyl error

Sorry for posting, I have actaully searched before I joined and nothing is that similar and parts that did look i was so lost cos I really am a super noob to this, hope you all forgive me
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jjtao is offline Offline
12 posts
since Jul 2009
Jul 29th, 2009
0

Re: MSqyl error

do this:

$sql_res=mysql_query("$sql_query") or die(mysql_error());

There's probably an error in your query.
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,177 posts
since Jul 2006
Jul 29th, 2009
0

Re: MSqyl error

Replace this:
php Syntax (Toggle Plain Text)
  1. $sql_res=mysql_query("$sql_query");
  2. $row=mysql_fetch_row($sql_res);

With this:
php Syntax (Toggle Plain Text)
  1. $sql_res=mysql_query($sql_query);
  2. if (!$sql_res) {
  3. echo 'Could not run query: ' . mysql_error();
  4. exit;
  5. }
  6. $row=mysql_fetch_row($sql_res);
The die method(above post) could be used instead of the if statement, its a matter of personal preference, tho the die may be milliseconds faster
Your issue could be as simple as a SQL error, when $sql_res is failing you will receive an error on mysql_fetch_row.

Perhaps add a LIMIT 1 to the end of the query. Are you sure that there aren't more than 1 result being returned by the query?
Last edited by SoN9ne; Jul 29th, 2009 at 12:05 pm.
Reputation Points: 12
Solved Threads: 6
Light Poster
SoN9ne is offline Offline
42 posts
since Jul 2009
Jul 30th, 2009
0

Re: MSqyl error

Click to Expand / Collapse  Quote originally posted by SoN9ne ...
Replace this:
php Syntax (Toggle Plain Text)
  1. $sql_res=mysql_query("$sql_query");
  2. $row=mysql_fetch_row($sql_res);

With this:
php Syntax (Toggle Plain Text)
  1. $sql_res=mysql_query($sql_query);
  2. if (!$sql_res) {
  3. echo 'Could not run query: ' . mysql_error();
  4. exit;
  5. }
  6. $row=mysql_fetch_row($sql_res);
The die method(above post) could be used instead of the if statement, its a matter of personal preference, tho the die may be milliseconds faster
Your issue could be as simple as a SQL error, when $sql_res is failing you will receive an error on mysql_fetch_row.

Perhaps add a LIMIT 1 to the end of the query. Are you sure that there aren't more than 1 result being returned by the query?
Thank you very much, I have copied the coding but am getting this error now Could not run query:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and visible=1' at line 1
when I use the die method I get this You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and visible=1' at line 1 Very new to php and I didnt make the coding, its a app. line one doesnt make sense to be incorrect since I know thats normal coding. <?php

also I know the syntax issue is with this line
PHP Syntax (Toggle Plain Text)
  1. $sql_query="select count(idnum) from $table_ads where $sql_mct1 visible=1 $city_query";
and I tried to add AND there but nothing
Last edited by jjtao; Jul 30th, 2009 at 4:48 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jjtao is offline Offline
12 posts
since Jul 2009
Jul 30th, 2009
0

Re: MSqyl error

Line 1 is referring to the first line of the query, not php. This is a MySQL error, not a php error. There is something wrong with the SQL query.

It seems that the issue is in the variable, $sql_mct1. Would you mind posting that code up?
Last edited by SoN9ne; Jul 30th, 2009 at 9:56 am.
Reputation Points: 12
Solved Threads: 6
Light Poster
SoN9ne is offline Offline
42 posts
since Jul 2009
Jul 30th, 2009
0

Re: MSqyl error

Click to Expand / Collapse  Quote originally posted by SoN9ne ...
Line 1 is referring to the first line of the query, not php. This is a MySQL error, not a php error. There is something wrong with the SQL query.

It seems that the issue is in the variable, $sql_mct1. Would you mind posting that code up?
Thank you so much, i guess I am posting on the wrong forum, but I appreciate all the help, if any of this works I will post it on the mysql pages to help others. code is below

function get_gcnt2()
{ 
global $sql_mct1, $table_ads, $grpcnt, $gkey2, $HTTP_GET_VARS;

if ($HTTP_GET_VARS['city']!=""){ $city_query=" and city='".$HTTP_GET_VARS['city']."' ";};
 
$sql_mct1=preg_replace ("/or$/", "", $sql_mct1);
$sql_mct1="( $sql_mct1 ) and ";
$sql_query="select count(idnum) from $table_ads where $sql_mct1 visible=1 $city_query";
$sql_res=mysql_query("$sql_query"); 
$row=mysql_fetch_row($sql_res);
$grpcnt[$gkey2]=$row[0];

}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jjtao is offline Offline
12 posts
since Jul 2009
Jul 30th, 2009
0

Re: MSqyl error

You should not use $HTTP_GET_VARS, use $_GET instead. You also don't need to include that in the globals, $_GET is a superglobal so you don't need to use global to use it.

The issue is still with the $sql_mct1
Perhaps echo out the $sql_mct1 before the query to see what it is. When i see the value of $sql_mct1 I can of more help.

Possibility that the preg_replace is causing your problem, not sure tho without knowing the value of $sql_mct1.

I cleaned the code a little and added in some debug for you.
php Syntax (Toggle Plain Text)
  1. function get_gcnt2()
  2. {
  3. global $sql_mct1, $table_ads, $grpcnt, $gkey2;
  4.  
  5. $city_query='';
  6. if (isset($_GET['city']) && $_GET['city']) {
  7. $city_query = " AND city='".$_GET['city']."' ";
  8. }
  9.  
  10. $sql_mct1 = preg_replace("/or$/", "", $sql_mct1);
  11. $sql_query = "SELECT COUNT(idnum) FROM $table_ads WHERE $sql_mct1 AND visible = 1 $city_query";
  12. $sql_res = mysql_query($sql_query);
  13. if (!$sql_res) {
  14. $errID = mysql_errno();
  15. $errEr = mysql_error();
  16. die('There was an error with SQL: '.(isset($errID) ? $errID.': '.$errEr : $errEr));
  17. }
  18. $row=mysql_fetch_row($sql_res);
  19.  
  20. if ($row) {
  21. $grpcnt[$gkey2]=$row[0];
  22. }
  23. }
Last edited by SoN9ne; Jul 30th, 2009 at 12:53 pm.
Reputation Points: 12
Solved Threads: 6
Light Poster
SoN9ne is offline Offline
42 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: insert data into two separate table / 2 queries in same php file
Next Thread in PHP Forum Timeline: parse error on last line (line 802)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC