This topic is locked

WHERE in a drop down field

1/23/2009 12:08:29 AM
PHPRunner General questions
D
debiso author

This may be basic but I can't figure it out. I have a table called selections with a drop down field called badges. I only want to show the records in the badges fiels where sessionid is equal to sessionid in the table scouts. I can't figure the syntax for this. Please help!!
THanks!

Joe

J
Jane 1/23/2009

Joe,
I'm not sure that I understand your question.

What is sessionid? PLease give me more detailed description of what you want to achieve.

D
debiso author 1/23/2009

Joe,

I'm not sure that I understand your question.

What is sessionid? PLease give me more detailed description of what you want to achieve.


Sorry i was tire when i posted that. I have 3 tables.
Scouts (scoutid, name, sessionid)

badges (badgeid, sessionid, badgename)

badgeselection (badgeid, scoutid)
the badgeselection table is subordinate to the scout table

I have a drop down on the add for for badge selection on the badgeid field which is a list from the badges table

I want that drop down to only list badgename for records where sessionid in badges matches sessionid in scouts
I think that is clearer.
Thanks~!

Joe

T
thesofa 1/26/2009

OK, I am a scout leader too, so I may understand a bit

are you trying to keep a record of which scouts attended which "session", ie meeting?

also record what badgework was done at each meeting?

hence you can then see if a scout has done a badge, or part thereof?

I do quite a bit of database work so I may be able to come up with a working model for you.

D
debiso author 1/26/2009

OK, I am a scout leader too, so I may understand a bit

are you trying to keep a record of which scouts attended which "session", ie meeting?

also record what badgework was done at each meeting?

hence you can then see if a scout has done a badge, or part thereof?

I do quite a bit of database work so I may be able to come up with a working model for you.



I would appreciate any help you could give me. Here is what I am trying to do in "Scout Terms".
I am the director of a boy scout camp. I am trying to create an on line Merit Badge pre-registration system. The leader registers and creates all the scouts for his unit. The for each scout he selects the classes they will be taking from a drop down list. This created registration records in the DB. I would like this list to be dynamic so when classes are full or scouts don't meet age requirements they will not see the classes they don't qualify for.
I have this setup and working but the issue is the dynamic drop down lists. Thats is what I can't get to work.
Thanks so much!!

Joe

J
Jane 1/27/2009

Joe,
here are some tips:

  1. select sessionid value from Scouts table on the List page: Before process event for badgeselection table on the Events tab and save sessionid value in the session variable.
  2. use this variable in the where clause on the"Edit as" settings dialog on the Visual Editor tab for badgeid field in the badgeselection table.

    Here is a sample:
    "sessionid=".$_SESION["sessionid"]

D
debiso author 1/30/2009

How do I set the session variable?
Thanks!

Joe

J
Jane 2/2/2009

Joe,

select sessionid value from Scouts table on the List page: Before process event for badgeselection table on the Events tab and save sessionid value in the session variable.



Here is a sample:

global $conn, $strTableName;

if ($_SESSION[$strTableName."_masterkey1"])

{

$str = "select Field1from MasterTable where Key=".$_SESSION[$strTableName."_masterkey1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

$_SESSION["Field1"] = $data["Field1"];

}

D
debiso author 2/2/2009

Joe,

Here is a sample:


What does _masterkey1 represent?

D
debiso author 2/2/2009

OK this is kinda making me crazy!! I will gladly pay for someone to interactively assist me with this so I can get it done. If anyone can do this, please contact me ASAP.
Thanks!

Joe

D
debiso author 2/2/2009



What does _masterkey1 represent?


I put the following code in the Before Process:
global $conn, $strTableName;

if ($_SESSION[$strTableName."_masterkey1"])

{

$str = "select Field1from MasterTable where Key=".$_SESSION[$strTableName."_masterkey1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

$_SESSION["Field1"] = $data["Field1"];

}
I put the following code in the where of the list box on the badge selection add:
"sessionid=".$_SESSION["sessionid"]
I get the following error when I click add on the badge selection
PHP error happened
Technical information

Error type 256

Error description You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

URL www.campmerz.org/preregister/Class_Selection_list.php?mastertable=Scouts&masterkey1=2

Error file D:\home\hnt23a136\preregister\include\dbconnection.php

Error line 34

SQL query SELECT `BadgeName` FROM `Classes` WHERE `BadgeID` = 1045 and (sessionid=)

Solution

This is a general error. It occurs when there is an error in event code or in SQL.
Any suggestions???

J
Jane 2/3/2009

Hi,
this error means that $_SESSION["sessionid"] is empty.

Please make sure you have replaced Field1 with sessionid in your event.
If it doesn't help publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.