Jump to content

Recommended Posts

I have a search form:

<form method="POST" action="<?=$_SERVER['PHP_SELF']?>" enctype="multipart/form-data">
            <div align="right">
              <input name="search" id="search" type="text"  size="9" />
              <input name="OK" id="OK" type="submit"  value="OK" />
            </div>
          </form>

 

and my code is:

 

if(in("OK"))
{    
 $search = $_POST['search'];
 $query = "SELECT * FROM pics WHERE MATCH key_words AGAINST ('$search') " ;
             $result = mysql_query($query);
             $entriesResults = getRows($result);	
} 

 

This works fine when I am on a page that displays the results (display.php), but how can I send the results of the search to the display.php from other pages.

 

Basicaly I want to have that search box on everypage and when someone searhes for something he/she will be taken to a page with the results.

Link to comment
https://forums.phpfreaks.com/topic/51439-searching/
Share on other sites

Instead of doing these things in seperate pages try using cases to do them in a single page.. something like this

 

<?php

$action = $_REQUEST['action']
switch($action) {
  default:
// would show a full list with a search box somewhere in the page...
  break;

  case search:
// your search code would be here...
  break;

}

?>

Might be an easier way of doing it -- also if you are making a complex system (such as what I am doing) you might take a look at smarty -- it is a template engine that has made my life as a programmer 110% easier than it was when I used to mix my logic and html....

Link to comment
https://forums.phpfreaks.com/topic/51439-searching/#findComment-253318
Share on other sites

The search code and the formare both on everypage.

 

When I search for something, nothing is displayed since I do not have a code to display the items, except for the display.php.

 

That is why I want to set up that when someone searches on any page the results will be displayed on the display.php page.

Link to comment
https://forums.phpfreaks.com/topic/51439-searching/#findComment-253325
Share on other sites

In the sample I gave you you would use it inside the search thing and everyting -- but one sec let me get you working code from my personal project that I am working on right now to kinda show you what I'm thinking...

 

<?php 
$_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';

switch ($_action) {

case adminact:
	$page = 'adminactivity';
	switch($act) {
		default:
			$turbo->getadminactivity();
		break;

		case delete:
			$id = $_REQUEST['id'];
			$del = "DELETE FROM adminact WHERE aact_id = '$id'";
				if (!mysql_query($del)) {
			$turbo->assign('errMsg', 'ERROR: Cannot delete selected log.  Try again later');
				} else {
			$turbo->assign('Msg', 'Selected log has been successfully deleted');
				}
			$turbo->getadminactivity();
		break;
case search:
			if ($aact_uname == '' AND $aact_ip == '') {
		 $turbo->assign('errMsg', 'ERROR: Cannot search with no information. Try again later');
		 $turbo->getadminactivity();
	 		}
	 		elseif ($aact_uname != '' AND $aact_ip == '') {
		 		$turbo->getadminactivitybyuser($aact_uname);
	  		} elseif ($aact_uname == '' AND $aact_ip != '') {
	 			$turbo->getadminactivitybyip($aact_ip);
	  		} elseif ($aact_uname != '' AND $aact_ip != '') {
				$turbo->getadminactivitybyboth($aact_uname, $aact_ip);
				}
			break;
	}
break;

}

?>

 

that is a snippet of code -- it does use classes and smarty to run -- but its awesome...  let me get you the functions i used for searching..

 

<?php
function getadminactivity() {
	$sql = "SELECT * FROM adminact";
	$sql = mysql_query($sql);
	$cnt = mysql_num_rows($sql);
	$this->assign('cnt', $cnt);
		if ($cnt > "0") {
			$this->assign_md_array($sql, $cnt, 'data');
		}
}

	function getadminactivitybyuser($user) {
	$sql = "SELECT * FROM adminact WHERE aact_admin = '$user'";
	$sql = mysql_query($sql);
	$cnt = mysql_num_rows($sql);
	$this->assign('cnt', $cnt);
		if ($cnt > "0") {
			$this->assign_md_array($sql, $cnt, 'data');
		} else {
		    $this->getadminactivity();
			$this->assign('errMsg', 'ERROR: No activity from that user');
		}
}

function getadminactivitybyip($ip) {
	$sql = "SELECT * FROM adminact WHERE aact_ip = '$ip'";
	$sql = mysql_query($sql);
	$cnt = mysql_num_rows($sql);
	$this->assign('cnt', $cnt);
		if ($cnt > "0") {
			$this->assign_md_array($sql, $cnt, 'data');
		} else {
		    $this->getadminactivity();
			$this->assign('errMsg', 'ERROR: No activity with chosen ip address.');
		}
}

function getadminactivitybyboth($user, $ip) {
	$sql = "SELECT * FROM adminact WHERE aact_admin = '$user' AND aact_ip = '$ip'";
	$sql = mysql_query($sql);
	$cnt = mysql_num_rows($sql);
	$this->assign('cnt', $cnt);
		if($cnt > "0") {
			$this->assign_md_array($sql, $cnt, 'data');
		} else {
			$this->getadminactivity();
			$this->assign('errMsg', 'ERROR: No activity with chosen user and ip address.');
		}
	}
?>

 

With smarty and classes you would have code similar to this...  where all of your logic is in 1 file, currently the index file that that was pulled from is 8746 lines of code, and i'm only about 1/4 done with my admin panel.  so all my logic is in one file, and then my template files are what make up the design of the site, makes life easier to program...  'cause you can use the same page for multiple things... 

Link to comment
https://forums.phpfreaks.com/topic/51439-searching/#findComment-253327
Share on other sites

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.