This topic is locked

Adding a filter button

6/10/2008 8:13:54 AM
PHPRunner General questions
W
wypman author

I have only just started to use this product for Family History based information - and I can't believe how rapidly its developing. I have searched through the forum, but I can't find an answer to the some slight problems I am facing.
On selecting view on the list page I am presented with a record from my database. I would like to add a button or hyperlink on this view page, that would take the user to a list page, but viewing only those records matching two fields from the current record being displayed.
To put this into context. I produce a list of people for a Census return. When you select someone from the list and view their record I want to be able to click on a button called 'view page' which would then show everyone who has the same 'reference number' and 'page number' in a list view. Is this possible?.
To complicate matters further I only want to be able to do this if a reference number exists.
Regards

J
Jane 6/10/2008

Hi,
use custom event (Insert PHP code snippet on the Visual Editor tab) to add button.

Here is a sample:

$str = "<imput type=button class=button value=NewButton onclick=\"windiw.location.href='your url here'\">";

echo $str;


Replace url with your acxtual URL. To construct correct URL use Advanced search:

http://www.asprunner.com/forums/index.php?showtopic=5704
To select values from view page use this code:

global $conn;

if (@$_REQUEST["editid1"])

{

$rs = db_query("select * from TableName where RecordID=".$_REQUEST["editid1"]);

$data = db_fetch_array($rs);
echo $data["FieldName"];

}

W
wypman author 6/10/2008

I have edited the view page and added button as per your code. The only problem is it shows all the records, instead on only being based on two values from the current record being displayed. In the insert below I'm trying to get it to display using data from the current 'iFamily' field, ideally I would like it to display from the 'Piece' field as well. At the moment its just showing me all the records. It appears to be doing a blank search showing all records and not getting to the second part. Am I missing something obvious?

$str = "<input type=button class=button value='View Household' onclick=\"window.location.href='http://localhost/Yorkshire%20Indexers/census_1841_list.php?a=advsearch&type=and&asearchfield%5B%5D=Surname&asearchopt_Surname=Contains&value_Surname=&value1_Surname=&asearchfield%5B%5D=Forenames&asearchopt_Forenames=Contains&value_Forenames=&value1_Forenames=&asearchfield%5B%5D=Age&asearchopt_Age=Contains&value_Age=&value1_Age=&asearchfield%5B%5D=Born&asearchopt_Born=Contains&value_Born=&value1_Born=&asearchfield%5B%5D=Piece&asearchopt_Piece=Contains&value_Piece=&value1_Piece=&asearchfield%5B%5D=ED&asearchopt_ED=Contains&value_ED=&value1_ED=&asearchfield%5B%5D=Folio&asearchopt_Folio=Contains&value_Folio=&value1_Folio=&asearchfield%5B%5D=Page&asearchopt_Page=Contains&value_Page=&value1_Page=&asearchfield%5B%5D=Schedule&asearchopt_Schedule=Equals&value_Schedule=&value1_Schedule=&asearchfield%5B%5D=Street&asearchopt_Street=Contains&value_Street=&value1_Street=&asearchfield%5B%5D=Place&asearchopt_Place=Contains&value_Place=&value1_Place=&asearchfield%5B%5D=iFamily&asearchopt_iFamily=Contains&value_iFamily=&value1_iFamily='\">";;

echo $str;
global $conn;

if (@$_REQUEST["iFamily"])

{

$rs = db_query("select * from census1841 where iFamily=".$_REQUEST["iFamily"]);

$data = db_fetch_array($rs);
echo $data["FieldName"];

}


Thanks for your assistance so far, this is all very new to me.
Regards

W
wypman author 6/10/2008

I'm not a PHP coder, but looking at you code further I presume the idea is to requery the table again using the primary key to retrive one record then use the results to get the variables that can be embedded into the URL?
With that in mind I altered my code to the following...

global $conn;

if (@$_REQUEST["editid1"])

{

$rs = db_query("select * from census1841 where Ref=".$_REQUEST["editid1"]);

$data = db_fetch_array($rs);

$Family = $data["iFamily"];

$Piece = $data["Piece"];

$str = "<input type=button class=button value='View Household' onclick=\"window.location.href='http://localhost/Yorkshire%20Indexers/census_1841_list.php?a=advsearch&type=and&asearchfield%5B%5D=Surname&asearchopt_Surname=Contains&value_Surname=&value1_Surname=&asearchfield%5B%5D=Forenames&asearchopt_Forenames=Contains&value_Forenames=&value1_Forenames=&asearchfield%5B%5D=Age&asearchopt_Age=Contains&value_Age=&value1_Age=&asearchfield%5B%5D=Born&asearchopt_Born=Contains&value_Born=&value1_Born=&asearchfield%5B%5D=Piece&asearchopt_Piece=Equals&value_Piece=".$Piece."&value1_Piece=&asearchfield%5B%5D=ED&asearchopt_ED=Contains&value_ED=&value1_ED=&asearchfield%5B%5D=Folio&asearchopt_Folio=Contains&value_Folio=&value1_Folio=&asearchfield%5B%5D=Page&asearchopt_Page=Contains&value_Page=&value1_Page=&asearchfield%5B%5D=Schedule&asearchopt_Schedule=Contains&value_Schedule=&value1_Schedule=&asearchfield%5B%5D=Street&asearchopt_Street=Contains&value_Street=&value1_Street=&asearchfield%5B%5D=Place&asearchopt_Place=Contains&value_Place=&value1_Place=&asearchfield%5B%5D=iFamily&asearchopt_iFamily=Equals&value_iFamily=".$Family."&value1_iFamily='\">";

echo $str;

}


This returns an error as soon as you enter the view.
Technical information Error type 2 Error description Missing argument 2 for db_query(), called in C:\PHPRunnerProjects\Yorkshire Indexers\output\include\census_1841_events.php on line 44 and defined URL localhost/Yorkshire Indexers/census_1841_view.php?editid1=2 Error file C:\PHPRunnerProjects\Yorkshire Indexers\output\include\dbconnection.php Error line 22 SQL query SELECT `Ref`, Schedule, Forenames, Surname, Age, Page, Folio, Piece, ED, Place, Street, iFamily, iPageCount, Notes, Born FROM `census 1841` where `Ref`=2
Any ideas?

W
wypman author 6/11/2008

Thanks for the update. Still had a problem viewing the records I wanted, but once I turned AJAX off it work perfectly!. I think its due to the volume of data, but this is an excellent program.
With a few tweaks I should be able to have a site up and running. This would not have been possible without your kind help and program.
Regards

W
wypman author 6/12/2008

I've been playing with the code on another database again dealing with Family History.
This time, I only wanted the button to appear if there was a 'Grave' reference. Also, I wanted to put a count on the button of how many people had the same reference. Due to all the help I've received regarding this, I wanted to feed something back into the system. Hope someone finds it useful.
There is probably an easier way, but it works!

global $conn;

if (@$_REQUEST["editid1"])

{

$rs = db_query("select * from burialsbsc where BurialID=".$_REQUEST["editid1"],$conn);

$data = db_fetch_array($rs);

$Grave = $data["Grave"];
If ($Grave > 0)

{

$rsc = db_query("SELECT COUNT(*) as CANT from burialsbsc WHERE Grave='".$Grave."'",$conn);

$fetched = db_fetch_array($rsc);

$members = $fetched["CANT"];

$str = "<input type=button class=button value='List $members Grave Members' onclick=\"window.location.href='http://localhost/members/burialsbsc_list.php?a=advsearch&type=and&asearchfield%5B%5D=Grave&asearchopt_Grave=Equals&value_Grave=".$Grave."&value1_Grave='\">";

echo $str;

}

}


Also, I didn't include the full URL generated by the Advanced Search button, I only included the parts that related to the data being searched. This has cut the length of the string down.