filtering a database by client selection
Moderator: General Moderators
filtering a database by client selection
Hi All,
Newbie to PHP but slowly getting there, hopefully someone could clarify the following:
I have created a database to hold business records, reviews etc.
I can access the database and display its contents.
I would now like to provide the viewer with options for filtering the data.
I was assuming that i can construct a form with the filter fields on it and then submit this back to the server with the selected values.
Then my PHP would use these to pick out what is required from the database and display it?
Is this the correct way to do this?
I am not 100% sure if the PHP code is unique to each user, or would all users / viewers end up with the same results - still not got my head around this one???
Should i use session variables for this approach?
Looking forward to clarification
Regards, J
Newbie to PHP but slowly getting there, hopefully someone could clarify the following:
I have created a database to hold business records, reviews etc.
I can access the database and display its contents.
I would now like to provide the viewer with options for filtering the data.
I was assuming that i can construct a form with the filter fields on it and then submit this back to the server with the selected values.
Then my PHP would use these to pick out what is required from the database and display it?
Is this the correct way to do this?
I am not 100% sure if the PHP code is unique to each user, or would all users / viewers end up with the same results - still not got my head around this one???
Should i use session variables for this approach?
Looking forward to clarification
Regards, J
Re: filtering a database by client selection
You'd need to create a search form. Is the data you store unique to each user? If that's the case then you'll need a way of identifying them from one another ie a login/password form prior to gaining access to the search form.
You would use PHP to generate the SQL query run by the database and your filters would be determined by the values they filled in on the form: http://www.tutorialized.com/view/tutori ... search/416
You would use PHP to generate the SQL query run by the database and your filters would be determined by the values they filled in on the form: http://www.tutorialized.com/view/tutori ... search/416
Re: filtering a database by client selection
Hi Jade,
Thanks for the reply, i will read through your link very soon.
I can confirm that the database does not need to be unique to each user, only the filtered results.
Its this bit im struggling to understand, but hopefully your link will help.
Just out of interest, is the php code unique to each viewer (ie any variables set up, are they unique or would they be the same value to everyone?)
Kind regards, J
Thanks for the reply, i will read through your link very soon.
I can confirm that the database does not need to be unique to each user, only the filtered results.
Its this bit im struggling to understand, but hopefully your link will help.
Just out of interest, is the php code unique to each viewer (ie any variables set up, are they unique or would they be the same value to everyone?)
Kind regards, J
Re: filtering a database by client selection
The PHP code will be the same for all users, however the selections they make will differ. Take google for instance. There is only one search field on the page but if both you and I go to Google we'll end up getting different results based on the criteria we've entered. The same concept applies to what you're trying to do.
Re: filtering a database by client selection
Hi Jade, anyone who can help...
I have set up my search form (this is designed on the same page where the results will be printed).
The form 'action' calls a php file that processes the results.
This is working fine, however it calls up a new page rather than the one i want my results in.
Is there anyway that the action can return to the original page?
If so, do i copy my results script contents into this page?
Is there any example code / Tutorial available on this?
Kind regards, J
I have set up my search form (this is designed on the same page where the results will be printed).
The form 'action' calls a php file that processes the results.
This is working fine, however it calls up a new page rather than the one i want my results in.
Is there anyway that the action can return to the original page?
If so, do i copy my results script contents into this page?
Is there any example code / Tutorial available on this?
Kind regards, J
Re: filtering a database by client selection
There are a few ways you can do it.
1. Have the form post back to itself. Let's say you have a file called test.php.
2. Store your result in a session then have the second page redirect back to the first page (not really an optimum solution).
Here's your test.php file:
This would be in test2.php:
3. Include a your second file on your first file.
Here is test.php:
Here is test2.php:
1. Have the form post back to itself. Let's say you have a file called test.php.
Code: Select all
<?php
if ($_POST['mybutton'])
echo "I entered " . $_POST['myvalue'];
?>
<form action=test.php method=post>
Enter a value: <input type="text" name="myvalue" value="<?php echo $_POST['myvalue']; ?>" />
<input type="submit" name="mybutton" value="Submit My Value" />
</form>
Here's your test.php file:
Code: Select all
<?php
session_start();
if ($_SESSION['myvalue'])
echo "I entered " . $_SESSION['myvalue'];
?>
<form action=test2.php method=post>
Enter a value: <input type="text" value="<?php echo $_SESSION['myvalue']; ?>" />
<input type="submit" name="mybutton" value="Submit My Value" />
</form>
Code: Select all
<?php
session_start();
if ($_POST['mybutton'])
$_SESSION['myvalue'] = $_POST['myvalue'];
header("Location: test.php");
exit;
?>
Here is test.php:
Code: Select all
<?php
include('test2.php');
?>
<form action=test.php method=post>
Enter a value: <input type="text" name="myvalue" value="<?php echo $myvalue; ?>" />
<input type="submit" name="mybutton" value="Submit My Value" />
</form>
Code: Select all
<?php
if ($_POST['mybutton'])
{
echo "I entered " . $_POST['myvalue'];
$myvalue = $_POST['myvalue'];
}
?>
Re: filtering a database by client selection
Re: filtering a database by client selection
Thanks Jade,
I played about with this prior to you posting, and ended up simply removing my script name from the actions field (action ="").
As far as i am aware, this will return to the same page?
I am then using issset function to determine what submit button was used.
So far, its all working ok...hope this method is acceptable
Regards, J
I played about with this prior to you posting, and ended up simply removing my script name from the actions field (action ="").
As far as i am aware, this will return to the same page?
I am then using issset function to determine what submit button was used.
So far, its all working ok...hope this method is acceptable
Regards, J