PHP Classes

mysql linked select

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  All threads  >  mysql linked select  >  (Un) Subscribe thread alerts  
Subject:mysql linked select
Summary:I wonder if there is an example of how the above class is used
Messages:5
Author:Geoff Stacey
Date:2011-12-11 15:50:07
Update:2012-02-16 16:52:57
 

 


  1. mysql linked select   Reply   Report abuse  
Picture of Geoff Stacey Geoff Stacey - 2011-12-11 15:50:07
I am a newbie at php classes. I have implemented a couple of basic forms but don't quite get how the plugins work. I want to allow selection of a tables index field so that a I can create a link between one table and another possibly using form_mysql_linked_select_class.php. I have inserted the following code into my form:

$form->AddInput(array(
"TYPE"=>"custom",
"NAME"=>"rep_code",
"ID"=>"rep_code",
"LABEL"=>"Re<u>p</u> Code",
"ACCESSKEY"=>"P",
"CustomClass"=>"form_mysql_linked_select_class",
"Connection"=>"localhost,$username,$password",
"OptionsQuery"=>"SELECT refno FROM rep"
));

I am sure there are some syntax errors in the Connection, but I don't see any specific example in the forum. I just get a totally blank field without even a label when I run this. Any help would be very much appreciated

  2. Re: mysql linked select   Reply   Report abuse  
Picture of Geoff Stacey Geoff Stacey - 2011-12-11 20:23:01 - In reply to message 1 from Geoff Stacey
I have managed to find the example and have done a bit of cut and paste to produce some code which gets me up a small bit of the way. I am trying to bring up just one table's data, rather than have a group and select data from that, but it seems you have to have a group? So I put in a dummy group and just searched for all the data in my table as follows:


$groups = array( "R"=>"Reps", "O"=>"Other" );

$form->AddInput(array(
"TYPE"=>"select",
"ID"=>"rep",
"NAME"=>"rep",
"LABEL"=>"Rep",
"VALUE"=>"",
"OPTIONS"=>$groups,
"ValidateAsNotEmpty"=>1,
"ValidationErrorMessage"=>"Invalid Rep group."
));

$form->AddInput(array(
"TYPE"=>"custom",
"ID"=>"rep_code",
"NAME"=>"rep_code",
"LABEL"=>"Re<u>p</u>. Ref. No.",
"ACCESSKEY"=>"P",
"CustomClass"=>"form_mysql_linked_select_class",
"Connection"=>$connection,
"GroupsQuery"=>"SELECT rep FROM groups",
"OptionsQuery"=>"SELECT rep_code, first, last FROM rep",
"DefaultOption"=>"",
"DefaultOptionValue"=>"Select Rep.",
"Dynamic"=>1,
"VALUE"=>"",
"SIZE"=>3,
"LinkedInput"=>"rep_code",
"AutoWidthLimit"=>0,
"AutoHeightLimit"=>0,
"ValidateAsNotEmpty"=>1,
"ValidationErrorMessage"=>"invalid rep. code"
));

As you can see I have inserted a GroupsQuery which is a dummy and do a straight OptionsQuery which is unrelated to the GroupsQuery.

Amazingly this brings up records from the "rep" table, without displaying anything of the group, but when I select one of these rows, I get an error message "invalid rep. code".
I want to select the "rep_code" field and insert that into another table as a lookup link. Is this possible?

  3. Re: mysql linked select   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-02-16 02:29:53 - In reply to message 1 from Geoff Stacey
Sorry for the delay. I just realized that I did not reply to this message. I hope it is still useful.

The Connection parameter is a database connection handle as returned by the functions mysql_connect or mysql_pconnect. Take a look at the forms.html manual file as it explains all the parameters.

  4. Re: mysql linked select   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-02-16 03:49:35 - In reply to message 2 from Geoff Stacey
Your OptionsQuery must have a parameter named {GROUP} that the plug-in will use to retrieve the names and codes of the representatives of the group of representatives defined by LinkedInput.

Your LinkedInput is wrong because it should be set to the ID of linked select input which is rep, not rep_code.

  5. Re: mysql linked select   Reply   Report abuse  
Picture of Geoff Stacey Geoff Stacey - 2012-02-16 16:52:57 - In reply to message 4 from Manuel Lemos
Eventually I used the following code:

______________________________________________________________

// Get the Rep details from the db
$query = "SELECT refno, last, first FROM rep";
$result = mysql_query($query) or die(mysql_error());

// Store the Rep details in an array (reps)
$reps = array();
while($row = mysql_fetch_array($result)){
$reps[ $row['refno'] ] = $row['first'];
}
...


$form->AddInput(array(
"TYPE"=>"select",
"ID"=>"rep_code",
"NAME"=>"rep_code",
"VALUE"=>1,
"OPTIONS"=>$reps,
"LABEL"=>"<u>R</u>ep",
"TABINDEX"=>9,
"ACCESSKEY"=>"R"
));
______________________________________________________

Thanks for your reply,

Geoff.



_______________________________________________________________