This topic is locked
[SOLVED]

 Custom View

12/30/2019 3:19:47 PM
PHPRunner General questions
M
mhollibush author

Being a novice, I am not getting this to work...

Can someone help?



if (!empty($values["thumbpic"])) {

echo "<img src='images/no_image.png'>";

}

else {

$value ="<img src='". $data["thumbpic"] ."'>";

}


Not giving errors, but also not working as desired...

As long as there is a image, it will display the image...

if the field is empty the "no_image" isn't displayed.

M
mhollibush author 12/30/2019

I thought I had it, but still not working



if (!empty($values["thumbpic"])) {

$value ="<img src='images/no_image.png'>";

}

else {

$value ="<img src='". $data["thumbpic"] ."'>";

}
W
WilliamBDevClub member 12/30/2019

I think this should work.

if ($values["thumbpic"]=="") {

$value ="<img src='images/no_image.png'>";

}

else {

$value ="<img src='". $data["thumbpic"] ."'>";

}
M
mhollibush author 12/30/2019



I think this should work.

if ($values["thumbpic"]=="") {

$value ="<img src='images/no_image.png'>";

}

else {

$value ="<img src='". $data["thumbpic"] ."'>";

}



Thank You!!!

That did the trick...

M
mhollibush author 12/30/2019

I was wrong...
It isn't working....
Now it displays the "no image" when there is valid data in the field
????

A
acpan 12/30/2019

Read the help, it states that:
$value - a value to be displayed on the page.
Example:

$value = strtoupper($value);
$data - array with all field values.

Example:

$value = $data["FirstName"].$data["LastName"];

where FirstName and LastName are actual field names.
So your $values is NOT DEFINED. Only $value and $data array variebles available.


// Check what do you have in $data array

// print_r($data);
// Check what is your current data in thumbpic field:

// echo $value;
// check if current field to display ($value), is empty, can also use if (empty($data["thumbpic"]))
if (empty($value) ) {

$value ="<img src='images/no_image.png'>";

}

else {

$value ="<img src='". $data["thumbpic"] ."'>";

}


ACP

M
mhollibush author 12/30/2019



Read the help, it states that:
$value - a value to be displayed on the page.
Example:

$value = strtoupper($value);
$data - array with all field values.

Example:

$value = $data["FirstName"].$data["LastName"];

where FirstName and LastName are actual field names.
So your $values is NOT DEFINED. Only $value and $data array variebles available.


// Check what do you have in $data array

// print_r($data);
// Check what is your current data in thumbpic field:

// echo $value;
// check if current field to display ($value), is empty, can also use if (empty($data["thumbpic"]))
if (empty($value) ) {

$value ="<img src='images/no_image.png'>";

}

else {

$value ="<img src='". $data["thumbpic"] ."'>";

}


ACP


Still not working... does it make a difference if the default value of the field is "NULL"?
Looking at the table column in phpmyadmin - it shows all the fields as "NULL" if there is no data

A
acpan 12/31/2019

>Still not working... does it make a difference if the default value of the field is "NULL"?
Google: "php empty function" - it will be faster to find the answer.
>Looking at the table column in phpmyadmin - it shows all the fields as "NULL" if there is no data
Learn how to read the info properly, it shows you how to verify the values. No one can see what you see on your screen.
// Check what do you have in $data array

// print_r($data);
// Check what is your current data in thumbpic field:

// echo $value;
// check if current field to display ($value), is empty, can also use if (empty($data["thumbpic"]))
ACP

M
mhollibush author 12/31/2019

ACP,

I appreciate your help with this, I understand that some people get this like a first language.

This is a little tougher for me as I am a older person that is just trying to learn as I go.

When I post a question, it's because I have tried everything that I have read, and even tried some sample scripts ( changing them to my needs )
There are times where I am stumped and I look for help from more advanced people. This forum is a great tool, as I can search through it and get most of my questions answered or issues resolved.
I am sorry if I struck a nerve with my question or the fact that I wasn't grasping what you were trying to explain....
I was able to get it to work, but I am having an issue with the way it affects the layout of the page ( I will figure it out )
Mark

A
acpan 12/31/2019

No worries, mark. Glad you figure out.
Don't get me wrong, that is how to pick up the skill fast (at least how i learn when i was a novice like you) - to google the function name given, and demo what you found and your understanding (and be corrected if wrong understanding or discuss other options) and feedback what you see (echo the values) to the helper who can't see what the values you have.
It will also be beneficial to tell people how you fix it.
Age is only a number, wish you a good year in 2020.
ACP

M
mhollibush author 12/31/2019

It's not completely fixed at this point...

for some strange reason - it throws the "no_image" in the upper left corner of the site instead of the assigned field.

Also the font of the site gets extremely large..
Working on that - Will post the script once I get that resolved..

A
acpan 12/31/2019

Likely you have echo command somewhere in the events or wrong place. Because of that echo, it interrupts the page loading and cause the fonts to be big, this is common behavior when you echo at the place you should'nt.



It's not completely fixed at this point...

for some strange reason - it throws the "no_image" in the upper left corner of the site instead of the assigned field.
Also the font of the site gets extremely large..

M
mhollibush author 12/31/2019





Thank you for the pointer - will check it out tomorrow