Markie
Posts: 251
|
| Posted: 12/03/2008, 9:47 AM |
|
In my grid I want to show an image (the details of the image are within a different database table). At the moment I use this CCDLookup code in the BeforeShow event of the image:
global $DBConnection2;
$Container->Image1->SetValue(CCDLookup("imagename","myimages", "album=".album,$DBConnection2));
It's kind of working and an image is shown at each record. But, there are a lot of different records in my grid and the same image is shown over and over again. I suppose my CCDLookup code only selects the first image it can find within the specific database table.
I would like to show a different image with each record in my grid. Is this possible ?
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 12/03/2008, 10:05 AM |
|
1 . You need to use BeforeShowRow so it will show images for each row.
2. For each row you need to add some primary ID and get its value, the you can use it to get appropriated image from your DB using similar code like you used.
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 12/03/2008, 10:16 AM |
|
Gena, thanks for your help. Can you please give some more details with regard to:
2. For each row you need to add some primary ID and get its value, the you can use it to get appropriated image from your DB using similar code like you used.
I don't understand how to do this exactly
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
datadoit
|
| Posted: 12/03/2008, 10:30 AM |
|
Markie wrote:
> Gena, thanks for your help. Can you please give some more details with regard
> to:
>
> 2. For each row you need to add some primary ID and get its value, the you can
> use it to get appropriated image from your DB using similar code like you used.
>
>
> I don't understand how to do this exactly
What he's referring to is what is the primary key for each of your rows.
Use that primary key value in your lookup. ie:
$db = new clsDBConnection2;
$Component->SetValue(CCDLookup("imagename","myimages",
"album=".$Container->PrimaryKey->GetValue(),$db));
$db->close();
Other notes:
See how I used a different connection for this? Recommended so that the
connection values don't get confused with themselves. Usually your
method works okay, but there are times when it might not and you'll
pound your head for hours wondering why.
Also referred to your image via $Component since you're doing it in the
component's BeforeShow. Does not matter whether you do your code in
your component's BeforeShow or in the grid's BeforeShowRow. If you do
do this in the BeforeShowRow, then you'll have to refer to your
component via $Container->Image1->SetValue().
Finally, if you use the method above, make sure that
$Container->PrimaryKey->GetValue() is displayed in your grid row BEFORE
your Image1. If it is not displayed, then refer to it as
$Container->ds->f("PrimaryKey").
|
|
|
 |
Gena
Posts: 591
|
| Posted: 12/03/2008, 10:51 AM |
|
yes, as datadoit said.
I would just put some hidden PrimaryKey field somewhere at start in row so it will consists your ID and then you can get value you need using this key.
btw I don't use this method. Normally I put some Label (HTML content) for image. And in BeforeShowRow I use my own function like:
$Container->IMGstring->SetValue(CreateIMG( $Container->ProductID->GetValue() , "D", "M", "R") );
so this
1. gets ProductID unique hidden field
2. CreateIMG function returns full Image code
using parameters like
D - default image
M - medium size
R - right align
Using this way you can easy and flixible show any Images you need...
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 12/04/2008, 7:01 AM |
|
I have reached some progress, but it's a little confusing.
In my MySQL table (named "photos"), I have an ID field. This ID field (INT) is the PrimaryKey of this database table.
In CCS, I have a label (named "album") with a BeforeShow DLookup action:
Expression: album
Domain: albums
Criteria: "id=".$photos->PrimaryKey->GetValue()
Connection: Connection2
Convert result to: Text
Type of target: Control
Target: album
With this code, it's working and I get a fresh result in the "album" label. But only where the ID's of the MySQL photo table and the album table are the same.
Whatever I do, I can't get any results when I use other fields of my MySQL table. I would really like to have a code like this:
"album=".$photos->PrimaryKey->GetValue()
but because the "album" field in my MySQL table is not a PrimaryKey, it doesn't work 
Is it possible to tell CCS which field should be regarded as PrimaryKey ? If so, please help me out ...
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 12/04/2008, 10:41 AM |
|
You need to use BeforeShowRow !!
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 12/04/2008, 11:39 AM |
|
Hi Gena, I did do all possible things with BeforeShowRow (Grid) but I think I don't understand it completey. With this I got the most results:
In CCS, I have a label (named "album") with a BeforeShow DLookup action:
Expression: album
Domain: albums
Criteria: "id=".$photos->PrimaryKey->GetValue()
Connection: Connection2
Convert result to: Text
Type of target: Control
Target: album
I have to do some more research to make it work ...
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 12/04/2008, 11:44 AM |
|
I see. OK, just use BeforeShowRow - get value, then assign to your label (named "album") with SetValue() as usual.
_________________
Gena |
 |
 |
DonP
|
| Posted: 12/04/2008, 12:22 PM |
|
As others mentioned, there needs to be some relationship between each
entry on the grid you are displaying for each photo. In other words, for
example, the table with the grid data would need a field with the ID for
the image that row is supposed to bring up so that it knows which
image to get. Without any relationship it will just get the first photo
as you already saw.
Don (DonP)
Markie wrote:
> In my grid I want to show an image (the details of the image are within a
> different database table). At the moment I use this CCDLookup code in the
> BeforeShow event of the image:
>
> global $DBConnection2;
> $Container->Image1->SetValue(CCDLookup("imagename","myimages",
> "album=".album,$DBConnection2));
>
> It's kind of working and an image is shown at each record. But, there are a lot
> of different records in my grid and the same image is shown over and over again.
> I suppose my CCDLookup code only selects the first image it can find within the
> specific database table.
>
> I would like to show a different image with each record in my grid. Is this
> possible ?
> _________________
> The Netherlands, GMT+1
> Tools: CCS 4.1.00.027, Win XP, Navicat, PSPad
> Local server: XAMPP with Apache, php and MySQL
> Webserver: Ubuntu with Apache, php and MySQL
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
|
|
|
 |
Markie
Posts: 251
|
| Posted: 12/05/2008, 8:52 AM |
|
Thank you all for your answers ! It's still a little unclear for me how to solve this situation but in the meantime I have found another solution.
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
|