DB
|
| Posted: 05/10/2003, 1:11 AM |
|
As no one responded to my last plea for help, I was able to make some progress by looking at previous threads. But I am still stuck at 1 point. The PHP4/MySql code appears below. This works except that the 2nd page of results begins to repeat the values from the 1st page, as though the query is made for each page. How do you cause succeeding pages to display their own values?
//CODE FOR GRID FORM (BEFORE SHOW EVENT):
global $db;
$db = new clsDBConnectionMySql();
$sql="select M.MiddleInitial from MiddleInitials M, GuestData G where M.MiddleInitialID=G.MiddleInitial";
$db->query($sql);
unset($db);
//CODE FOR LABEL WITHIN GRID FORM (BEFORE SHOW EVENT):
global $GuestData, $db;
if($Result = $db->next_record())
{
$mi = $db->f("MiddleInitial");
$GuestData->MiddleInitial->SetValue($mi);
}
|
|
|
 |
RonB
|
| Posted: 05/10/2003, 6:39 AM |
|
Because your label query contains no reference to the original grid the result is two distinct resulsets. You will have to make sure there is a connection between the two resultsets for exampleAssuming g.middleinitial is already present in some label in the grid):
global $GuestData;
$db = new clsDBConnectionMySql();
$sql="select M.MiddleInitial from MiddleInitials M, GuestData G where M.MiddleInitialID=" .CCToSQL($GuestData->somelabel->Getvalue(),"ccsInteger");
$GuestData->MiddleInitial->setvalue(CCGetDBValue($sql,$db));
Now for each new row the database will get the value for that row. If you now go to the second page the values you get with the query will be the correct ones, corresponding with the rows.
Ron
|
|
|
 |
DB
|
| Posted: 05/11/2003, 2:01 PM |
|
Ron,
Can you explain in a little more detail for me? Do you mean that I do not need the first select statement in the grid form and only need a select statement in the label?
|
|
|
 |
RonB
|
| Posted: 05/13/2003, 12:18 PM |
|
The first query in your example isn't needed at all. If I understand you correctly you already have a grid that contains the data you would get by executing this query.
The second query will get information from the database. You want it to correspond to data shown in the grid and to fill an aditional label in that grid.
There are two ways to go about this:
1. The easy way is just to use the query qizzard in ccs to construct a query that includes both tables using a join. I recommend doing that because it's easy as can be.
2. use a beforeshow event to get the data for the label
in the grid make sure MiddleInitialID is present. You need it to change it to the desired data later.
global $GuestData;
$db=new clsDBConnectionMySQL;
$GuestData->MiddleInitial->setvalue(CCGetDBValue("select MiddleInitial from MiddleInitials where MiddleInitialID=".$GuestData->MIddleInitial->GetValue(),$db));
unset($db);
The only reason I can think of to use method 2 is when the data you are getting in this way comes from a second database. In that case you can not create a join so you would have to resort to method2. In all other cases I recommend you create the connection between the two tables in SQL. That way you only need to acces the database once so you save resources and most database servers can do this a lot faster then php can.
RonB
|
|
|
 |
|