Jump to content

Please for the love of god! HELP ME!


paulman888888

Recommended Posts

Please help me.

 

<?php if(in_array($search_where2,$search_where3)){//check if allowed search

if($search_where==$search_allowed[1]){//this works if i search for$search_allowed[1] 
$query = "SELECT * FROM ";
$query.='chess_events';
$query.=" WHERE ";
$query.='event_name';
$query.=" LIKE \"%$trimmed%\" ";
$query.=" ORDER BY ";
$query.=$order_by;
}

}elseif($search_where==$search_allowed[2]){//this doesnt work
$query = "SELECT * FROM ";
$query.='chess_location';
$query.=" WHERE ";
$query.='name';
$query.=" LIKE \"%$trimmed%\" ";
$query.=" ORDER BY ";
$query.=$order_by;

}elseif($search_where==$search_allowed[3]){not tested yet
$search_table='chess_news';
$search_where4='title';
$query = "SELECT * FROM ";
$query.='chess_news';
$query.=" WHERE ";
$query.='title';
$query.=" LIKE \"%$trimmed%\" ";
$query.=" ORDER BY ";
$query.=$order_by;
}else{echo'Error on Line 129: Error Matching Location to Search';}

// Build SQL Query  
$numresults=mysql_query($query)or exit('Error on Line: 144');
$numrows=mysql_num_rows($numresults);

// If we have no results, offer a google search as an alternative

if ($numrows == 0)
  {
  echo "Sorry, your search: "" . $trimmed . "" returned zero results";
  $search_error=665;
  echo'Error on Line: 145';
  }

// next determine if s has been passed to script, if not use 0
  if (empty($_REQUEST['s'])) {
  $s=0;
  }elseif($_REQUEST['s']>=0){$s=$_REQUEST['s'];}else{$s=0;}

// POST results
  $query .= " LIMIT $s,$limit";
  $result = mysql_query($query) or die('Error on Line: 158');
} ?>

What have i done wrong? I dont understand#

 

Please Help me

Thankyou in advance

Paul Hutchinson

 

Link to comment
https://forums.phpfreaks.com/topic/136840-please-for-the-love-of-god-help-me/
Share on other sites

You should probably write your queries out on one line, because the way you have done it, it can quickly get confusing and messed up. When inside php, your query can have line breaks in it if you need to keep it organized that way. Theres no need to concatenate the query the way you have done it.

I agree with the above responses...also learn to format your code and indent...it makes it easier to read, and spot errors...get a syntax highlighting editor like ConTEXT, or programers notepad, if at all possible Zend Studio is phenomenal!

 

anyways before your first "elseif" you have an extra } i dont think you meant to have that there....and also one of your comments isnt escaped with //.... anyways here the "fixed" code...hope this helps you solve your issue....


<?php 
if(in_array($search_where2,$search_where3)){//check if allowed search
if($search_where==$search_allowed[1]){
	//this works if i search for$search_allowed[1] 
	$query = "SELECT * FROM ";
	$query.='chess_events';
	$query.=" WHERE ";
	$query.='event_name';
	$query.=" LIKE \"%$trimmed%\" ";
	$query.=" ORDER BY ";
	$query.=$order_by;
}
elseif($search_where==$search_allowed[2]){//this doesnt work
	$query = "SELECT * FROM ";
	$query.='chess_location';
	$query.=" WHERE ";
	$query.='name';
	$query.=" LIKE \"%$trimmed%\" ";
	$query.=" ORDER BY ";
	$query.=$order_by;
}
elseif($search_where==$search_allowed[3]){//not tested yet
	$search_table='chess_news';
	$search_where4='title';
	$query = "SELECT * FROM ";
	$query.='chess_news';
	$query.=" WHERE ";
	$query.='title';
	$query.=" LIKE \"%$trimmed%\" ";
	$query.=" ORDER BY ";
	$query.=$order_by;
}
else{
	echo'Error on Line 129: Error Matching Location to Search';
}

// Build SQL Query  
$numresults=mysql_query($query)or exit('Error on Line: 144');
$numrows=mysql_num_rows($numresults);


// If we have no results, offer a google search as an alternative
if ($numrows == 0){
  echo "Sorry, your search: "" . $trimmed . "" returned zero results";
  $search_error=665;
  echo'Error on Line: 145';
}

// next determine if s has been passed to script, if not use 0
if (empty($_REQUEST['s'])) {
  		$s=0;
}
elseif($_REQUEST['s']>=0){
  		$s=$_REQUEST['s'];}else{$s=0;
}

// POST results
$query .= " LIMIT $s,$limit";
$result = mysql_query($query) or die('Error on Line: 158');
} 
?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.