Forums

If "image" Display "image" else "no-image"

BigStef 01 Mar, 2013
Hi, i'm trying to display the user's image in row of my CC table. As I 'm really not good in php, i have copy the code from another topic (topic about editing image in a form to modify or erase), wich is this one :

<?php
if ( isset($form->data['eleve_portrait']) && $form->data['eleve_portrait'] ) {
  echo "<img src='".JURI::root()."images/elevemid_{eleve_portrait}' style='max-width:120px' />";
} else {
  echo "<img src='".JURI::root()."images/00_no_image.jpg' style='max-width:120px' />";
}
?>

This one work really good in my form, but I can't make it run in my CC table. I just get the "No-image" picture, even if user has uploaded an image...

I have paste it in the cell where i want it display. Max said in another topic I read "Don't do an extra query, actually you are doing a query per row, which is wrong". SO I think this the error i do here, but i just don't know how to do this in a better way...

Does anybody have a suggestion ?
GreyHead 02 Mar, 2013
Hi BigStef,

In ChronoConnectivity (the current version) the row data is in $row. Also you usually can't use the curly bracket syntax in PHP. So please try:
<?php
if ( isset($row['eleve_portrait']) && $row['eleve_portrait'] ) {
  echo "<img src='".JURI::root()."images/elevemid_{$row['eleve_portrait']}' style='max-width:120px' />";
} else {
  echo "<img src='".JURI::root()."images/00_no_image.jpg' style='max-width:120px' />";
}
?>

Bob
BigStef 02 Mar, 2013
Hi Bob, this is saturday evening and give me the right solution...
Thanks a lot for that! :-) Works great !
BigStef 07 Mar, 2013
Hi Bob, I have a new case with this topic. I have activated a Multi Tables on this connection, and the code stop working, showing only the "no-image" picture. I have tried to put the MODEL_ID (here : Eleve) before the name of field, like this :

<?php
if ( isset($row['Eleve.eleve_portrait']) && $row['Eleve.eleve_portrait'] ) {
  echo "<img src='".JURI::root()."images/formulaire/elevemid_{$row['Eleve.eleve_portrait']}' style='max-width:120px' />";
} else {
  echo "<img src='".JURI::root()."images/formulaire/00_no_image.jpg' style='max-width:120px' />";
}
?>


But nothing changed, still the "No-Image" picture...

Other fields works great (i.e. : {Eleve.eleve_nom}, {Eleve.eleve_prenom}, etc), but this one a "normal" datas...

After several others tests, I found that Pictures stopped working when I give a MODEL_ID to the main connection (here "Eleve"). When I erase that Model ID, the pictures are back, but of course, the data from second tables are not loaded...

Have any idea ?
GreyHead 07 Mar, 2013
Hi BigStef,

The 'dot' will work with the curly brackets: {Eleve.eleve_portrait} where you can use them.

In PHP it's a sub-array: $row['Eleve']['eleve_portrait']

Bob

Note: the curly brackets that ChronoForms uses to let you insert values are similar to but not functionally the same as the curly brackets that PHP uses to let you include a variable in a string.
BigStef 07 Mar, 2013
Hi Bob,
Thanks a lot... Works great ! I was asking myself two things :

1/ Is it better to write a MODEL_ID in lowercase ? (strangely, i found it work better on my multi table)
2/ Do you share the beers we can offer here with Max ? ;-)
GreyHead 08 Mar, 2013
Hi BigStef,

1) I don't think it should make any difference. I tend to use all lower case automatically so haven't done any real comparisons.

2) No we don't usually share. If you buy me a beer, I keep that. If you buy a subscription Max keeps that and from time to time he pays me a 'royalty' on the subscription sales income.

Bob
BionicNelly 13 Apr, 2013

In ChronoConnectivity (the current version) the row data is in $row. Also you usually can't use the curly bracket syntax in PHP. So please try:

<?php
if ( isset($row['eleve_portrait']) && $row['eleve_portrait'] ) {
  echo "<img src='".JURI::root()."images/elevemid_{$row['eleve_portrait']}' style='max-width:120px' />";
} else {
  echo "<img src='".JURI::root()."images/00_no_image.jpg' style='max-width:120px' />";
}
?>



Forgive me for being thick - where does the above "If" else" go in chronoconnectivity?
GreyHead 13 Apr, 2013
Hi BionicNelly,

In the Body section of a Custom Listing.

Bob
This topic is locked and no more replies can be posted.