Jump to content

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');
} 
?>

 

 

anyways before your first "elseif" you have an extra } i dont think you meant to have that there...

 

Maybe he did. There are two if blocks open at that point... but yeah... this might be the reason the next one doesn't work :P

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.