Login Retreive lost passwordRegister
Search

Forum Index / General / different PK with different table

[ This topic is solved ]

  Iyas 02 July 10 / 22:25  
Changed at 02 July 10 / 22:27
I am totally at lost. I think I just missing a 'very little something'.

I want to edit a data with an $id, then in the form, i need to fetch a field with different id in a different table.

Please help me. TQ for your time.

table teacher
id, name, subject.id
1, john, 2
2, lily, 1

table subject
id, name
1, math
2, science

  Iyas 02 July 10 / 23:04  
after some manual search, i think dbSelectField can do the job. haven't test it yet.

  Johan Wiegel (Admin) 03 July 10 / 08:50  
I think you are right ;)

dbSelect
OR dbRadio OR ....dbCheckBox or dbListField

  Iyas 03 July 10 / 18:36  
Changed at 03 July 10 / 18:50
i have tested all the above. only display output WHEN NOT in EnableViewMode.

<?php
$form 
-> enableViewMode();
$form -> setMask("
%title%: %field% 
<br />
<!-- %title% --> %field%
"
,false);
$form -> textField("Name""name" );
$form -> dbCheckBox("Subject Name","subjectname""subject""name""WHERE id = ".$form ->value("subject.id"), FH_NOT_EMPTY);

//there is no subjectname field in table teacher, i just create it for display purpose

$form -> flush();
?>

  Johan Wiegel (Admin) 03 July 10 / 19:29  
if the field is not there there is no value, so it's no shown.

Just teste each of the fields seems to me enableview mode is working as it should

  Iyas 04 July 10 / 03:47  
Changed at 04 July 10 / 03:58
i tried adding
<?php
$form 
-> setValue("subjectname"$form -> value("subject.id"));
?>

so that the form choose the field from the checkbox, but it shows the value.

I want it to show 'science', instead it shows '1'.

Any idea?

  Iyas 04 July 10 / 05:21  
one more thing, dbselect, dbradio and dbcheckbox are able to fetch field from another table, with different pk. why not just add another one say.. dbtextfield?

  Johan Wiegel (Admin) 04 July 10 / 08:07  
This works as expected with and without enableViewMode:

<?php
$oForm 
= new dbFormHandler("klant");
$oForm->dbInfoDB_NAME'tbl_dummy'DB_TYPE );
$oForm->dbConnectDB_HOSTDB_USERDB_PASS );
$oForm->enableViewMode();
$oForm->dbSelectField'DB Select''dbselect''tbl_test', array('id','naam'), 'ORDER BY naam ASC' );
$oForm->submitButton();
$oForm->flush();
?>

  Iyas 04 July 10 / 09:02  
Changed at 04 July 10 / 11:26
strange enough.. your code also doesn't work.

it only display the field if enableviewmode is OFF.

maybe there are some files missing when i upload the zip and extract in my host. do you have any suggestion?

is it something to do with php version?

mine 5.2.10

  Johan Wiegel (Admin) 04 July 10 / 12:02  
try these 2 links to see what happens and let me know please:

http://www.jwiegel.com/FH/dbselect.php

http://www.jwiegel.com/FH/dbselect.php?id=1

the second is in viewmode

  Iyas 04 July 10 / 12:11  
first link for edit/insert
second link for view

exactly like what i want. but why i can't produce the same? i've tried in local server too, still the same, can't see the field when in view mode.

  Iyas 04 July 10 / 12:20  
check these links:

http://sama.edp.my/os/

http://sama.edp.my/os/?id=21

  Johan Wiegel (Admin) 04 July 10 / 12:43  
Can you show us the code for your form and the table structure from the database?

  Iyas 04 July 10 / 12:53  
Changed at 04 July 10 / 13:07
For the links, I just use simple selectfield, no databases, still doesn't work.

<?php
// make a new $form object 
$form = new FormHandler(); 



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

    
$form -> enableViewMode(); 


//$form -> enableViewMode();
// the options for the checkbox 
$animals = array('dg' => 'dog''ct' => 'cat'); 

// make the checkbox 
$form -> useTablefalse );
$form ->setMask("%title% %field%"false);
$form -> SelectField("Favorite animal(s)""animal"$animalsnullfalse);

// send the form to the screen 
$form -> flush(); 
?>


i've added one line
$form -> setValue('animal', 'dg, ct');

following this discussion:
http://www.formhandler.net/topic/3254/viewmode().html

but can't even get bullet list, just simple "dg, ct" text. See again my two links.

  Johan Wiegel (Admin) 04 July 10 / 13:08  
Try this.

<?php
// make a new $form object 
$form = new FormHandler(); 



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

    
$form->SetValue'animal''cat' );
    
$form -> enableViewMode(); 


//$form -> enableViewMode();
// the options for the checkbox 
$animals = array('dg' => 'dog''ct' => 'cat'); 

// make the checkbox 
$form -> useTablefalse );
$form ->setMask("%title% %field%"false);
$form -> SelectField("Favorite animal(s)""animal"$animalsnullfalse);

// send the form to the screen 
$form -> flush(); 
?>

  Iyas 04 July 10 / 13:14  
done. and then i change
<?php
    $form
->SetValue'animal''cat' ); 
    
$form -> enableViewMode();  
?>

to
<?php
    $form
->SetValue'animal''catdog' ); 
    
$form -> enableViewMode();  
?>


which catdog is not even in the array, it still treat the field as a textfield, not selectfield.

  Johan Wiegel (Admin) 04 July 10 / 13:21  
it's not possible to set to values to a single selectfield.

Think you should read the manual.

  Iyas 04 July 10 / 13:22  
Changed at 04 July 10 / 13:39
but i've got problem even with many values.

it seems to me that i've got problem with view mode, not "dbselectfield' because even selectfield, checkbox and radio don't produce output.

in the other hand, the reason i've suggested the use of a new
"dbTextField" because when in edit mode, it acts like normal textfield,
but with the difference that it can set default text using some data from the database.

when in viewmode, i can fetch data pretty easy.

  Iyas 04 July 10 / 13:38  
Changed at 04 July 10 / 13:48
check these links:

http://www.alazhar.edp.my/forum/ostest.php?id=mibi&viewmode

http://www.alazhar.edp.my/forum/ostest.php?id=mibi

<?php
// include the dbFormHandler 
include("FH3/class.dbFormHandler.php"); 

// create a new form 
$form = new dbFormHandler("form");
$form -> dbInfo"xxx""guru""mysql" ); 
$form -> dbConnect"localhost",  "xxxx""xxxx" );

$form -> useTablefalse );

if(isset(
$_GET['viewmode']))
$form -> enableViewMode();

$form -> setMask("
%title%: %field% 
<br />
<h2>Jawatan</h2>
<h3>Guru Kelas</h3>
<!-- %value% %name% %title% --> %field%
"
,false);
$form -> textField("Nama""nama" );
$form -> dbCheckBox("Guru Kelas","gurukelas""kelas""nama","WHERE id = ".$form -> value("kelas.id"), FH_NOT_EMPTY);


$form -> flush();
?>


same if i use dbselectfield, etc..

  Iyas 04 July 10 / 13:47  
table guru
id, nama, kelas.id
mibi, muhammad iyas, 1
or, osman rashid, 2

table kelas
id, nama
1, ibnu khaldun
2, ibnu rushd

  Johan Wiegel (Admin) 04 July 10 / 13:59  
sorry we can achieve all we want with the existing fields.

I still do not understand your problem.

Can you explain in writing what you want to achieve?

  Iyas 04 July 10 / 17:23  
sorry for making your life harder.. hehe.. ;)

Basically, while using a table for my form/report, i want to be able to get value from another table with it's own key.

value() will only get the value of a field in the same table.

to use dbInfo() for the second time to connect to another table, it is easy if the primary key is the same as the first table. what to do if the PK is different?

while searching for the solution, i stumble upon dbselectfield and dbcheckbox. i think they are the solution. but i still can't figure out why there are no output when in view mode.

i even copy your code, and test the code. your result are different than mine.

even more mystery, i tried simple checkbox and selectfield, only to find out that enableviewmode print nothing for the values.

concerning my suggestion, can you solve how to populate a textfield with data from db. the data is not what the user insert, but it is there as a default value(only make sense for insert purpose, of course we want the textfield being populated with the data previously inserted by the user if it is in edit mode)

sorry, my english is not so good.

  Johan Wiegel (Admin) 04 July 10 / 19:33  
the viewmode for selecfieldm radiofield, checkbox etc will only show the values of the selected parts.

so:

<?php
$oForm 
= new FormHandler("klant");
$oForm->SetValue'checkbox', array(0,1));
$oForm->enableViewMode();
$oForm->CheckBox'CHeckbox''checkbox', array(0='cat',1='dog') );
$oForm->onCorrect'FH_RUN' );
$oForm->submitButton();
$oForm->Flush();
?>


Shows both values


<?php
$oForm 
= new FormHandler("klant");
$oForm->SetValue'checkbox', array(1));
$oForm->enableViewMode();
$oForm->CheckBox'CHeckbox''checkbox', array(0='cat',1='dog') );
$oForm->onCorrect'FH_RUN' );
$oForm->submitButton();
$oForm->Flush();
?>

shows dog

<?php
$oForm 
= new FormHandler("klant");
$oForm->enableViewMode();
$oForm->CheckBox'CHeckbox''checkbox', array(0='cat',1='dog') );
$oForm->onCorrect'FH_RUN' );
$oForm->submitButton();
$oForm->Flush();
?>


Shows no values (non value set, non checbox with checked="checked")

In order to show values in viewmode you have to make sure the values are set in the form.

This works the same voor the dbSelectField, dbRadiobutton etc etc.

Hope this helps a bit, if not I will ask my collegue to help me answering this question.

  Iyas 05 July 10 / 11:54  
Thank you very much. It now works!

  Top


powered by PHP-GLOBE   © 2004 - 2010 FormHandler. All rights reserved.   -   Open source license