Question:
html forms relating to database queries?
CuriousGIrl
2010-06-21 05:44:07 UTC
I have a web page that has a search function for a database. On loading the page, the results of an empty query are shown (i.e no parameters in query so entire database is shown).

Is there anyway to stop this initial display of the database? I only want the results to show once I have selected the search button within my HTML form
Five answers:
Abhinav
2010-06-21 06:39:29 UTC
Put a condition in your code that if a empty query parameter is encountered, the search part should be skipped
Nigel
2010-06-21 08:01:39 UTC
You should be able to detect if the page is running from a submit of itself ( i.e. am I running as a result of someone selecting a 'display results' button. You should therefore be able to say don't run the query at all if that requirement isn't met.

Another thing which is a general thing - it would be worth limiting the amount of results displayed. Most users aren't going to want even 100 results never mind thousands which can be the result of some queries. So it could be worth building that into your page anyway.
Kenneth
2010-06-21 05:47:22 UTC
Since you have to have some type of a scripting language that actually runs the query, such as PHP, you might want to try posting the SELECT statements that you are using to return results for your query.
2010-06-21 07:02:43 UTC

if(!isset($_GET['action']))

{

echo "a blank form with out a query";

}

else

{

echo "your search results";

}

?>



or you can morph this



simple class to detect the $_SERVER['REQUEST_METHOD'] and return an array() to use for other actions.



I use this so I can pass query values in the URL automatically.



Example:

This would be a hyperlink on a page. As you see it will go to the index.php or default.php with 2 query arguments.



Home


if($UserInput['app'] == "0" && $UserInput['action'] == "0"){

echo "Welcome to DzSoundNirvana.com's Home page";

}

?>


/*******************************

method.class.php

*******************************/



class Methods{

var $RM;

var $app;

var $action;

var $UserInput = array();



function Methods(){

$this->RM = $_SERVER['REQUEST_METHOD'];



if($this->RM == "GET"){

$this->GetRM();

}

else{

$this->PostRM();

}

}//End function



function GetRM(){

foreach($_GET as $key => $value){

$this->UserInput[$key] = $value;

}

return $this->UserInput;



}//End function



function PostRM(){

foreach($_POST as $key => $value){

$this->UserInput[$key] = $value;

}

return $this->UserInput;

}//End function



}

?>

This is how i call the Method and use the URL query arguments


/****************************

index.php

****************************/

require_once('method.class.php');



$Method = new Methods();

$UserInput = $Method->UserInput;



if($UserInput['app'] == "0" && $UserInput['action'] == "0"){

echo "Welcome to DzSoundNirvana.com's Home page";

}



//You can switch it too for blocking code out



switch($UserInput){

case ($UserInput['app'] == "0" && $UserInput['action'] == "0"):

echo "Welcome to DzSoundNirvana.com's Home page";

break;



case ($UserInput['app'] == "User" && $UserInput['action'] == "Login":

echo "I would build a login page right here";

break;



}

?>
2016-10-22 10:02:55 UTC
first, you will desire to get your information from the dbase elect * FROM table_name; the end result would be an array of information. 2nd, you will desire to extract the information interior the array on your form to enable the viewer of the internet site see the information they're think to work out. mysql_fetch_assoc or mysql_fetch_row


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...