How to display an image on a header value line using a blob myql field

Hi. This SC eval is really going great!!! I have made so much progress on my testing I am super happy.

I am stumbling a little on how to pull an image from a mysql blob field and put it into one of the header lines. I want to get rid of the static image from the file system, and have a dynamic logo based on a siteID field from a table. Here is what I am trying:

  1. on script initial load for the menu app, get the siteID… $var_siteID = $_GET[‘siteID’];

  2. also put this in to capture the blob contents into a variable:
    $sql_command = “SELECT site_logo FROM tb_sites WHERE site_id = '”.$var_siteID."’ ";
    sc_lookup(sitelogo, $sql_command);
    $thesitelogo = {sitelogo[0][0]};

  3. In the menu - header & footer - Lin1_Col2 - set it to value: <img src=’[thesitelogo]’ />

I can’t test this till tonight, but if you see any glaring errors please advise.

Only other way I can think of is to echo out the blob right in the field itself, something like: <img alt=‘Embedded Image’ src='data:image/png;base64,<?php echo $image->blob_data; ?> '/>
BUT I am not sure if you can put php on those value lines in the header - I know it takes html and the global variables OK.
Thanks,
Jamie

Re: How to display an image on a header value line using a blob myql field

You will need to inform the page that you are displaying an image if you are coming direct from the field, or you could dump it to a file and display that.,

many results from:
google: php display image database

Regards,
Scott

Re: How to display an image on a header value line using a blob myql field

Thanks, that helped. Just to make this post helpful to others behind me…

After lots of experimentation, there are 2 ways depending on what you want:

  1. In the php code for an event, do this to display the image stored in a DB and retrieved into a global var - however, all other html will not be rendered following the image, due to the header…

header(“Content-type: image/jpeg”);
echo [glo_diningLogo];

  1. Putting this line in the event code displays the image and then all the rest of the app renders correct html.

echo ‘<img src="data:image/jpeg;base64,’ . base64_encode( [glo_diningLogo] ) . ‘" />’;
echo ‘Hello world.’;

peace,
Jamie

Re: How to display an image on a header value line using a blob myql field

Jamie, which event are you using? I’d like to customize the top of the screen with the site’s logo and other user information…

thanks,
Chris

Re: How to display an image on a header value line using a blob myql field

Hi Chris,
This is what I have found works to change the logo in the menu header:

First, I have a SC session global variable called [glo_siteid]. This gets set based on the user login, which site they belong to , etc. Whatever scheme fits your system…

Second, I have a regular menu (could be horizontal or vertical). In that menu app I use the onLoad event to basically preload a global variable for use later. In my case, I want to load the valiable called [glo_logo] using the following code:

// site_table has a blob field called mylogo loaded with an image
$sql_command = “SELECT mylogo from site_table WHERE id = '”.[glo_siteid]."’ "; // using the session variable set elsewhere (or could be passed into this app)
sc_lookup(my_data, $sql_command); // make sure this app has the connection to your DB setup in one of the settings

if ({my_data} == false)
{
echo “Access error Message=”.{my_data_erro}; // haven’t tested this but I want to not crash later
[glo_logo] = NULL;
}
elseif (empty({my_data})) // same, not tested but should prevent later crash if no value in table
{
[glo_logo] = NULL;
}
else
{
// this loads the variable with the html AND the blob image data, so it works in the header later
[glo_logo] = ‘<img src="data:image/jpeg;base64,’ . base64_encode( {my_data[0][0]} ) . ‘" />’;
}

Now that the onLoad event has loaded that variable, I go to the Layout - Header + Footer settings.
Changed the NM_LOGOTIPO (or whatever SC had called the built-in logo) to use Value, then put the global variable in teh next field [glo_logo]

That should put your logo from the DB blob field in where the hard coded default SC image was. This I have working with no problems so far.

The other fields can use variables to display other info, using html and global variable values set somewhere else as well. It actually let me get just the effect I wanted. The headers on all the apps, I believe, can be modified in this same way.

Note - if you put stuff like echo [glo_logo] into the onLoad event, you can put all sorts of other stuff BEFORE the SC header. I was looking at doing that before I fgigured out ther above scheme. One approach could be to use the onLoad event to make a new header, matching the layout and colors etc of the whole app, then just don’t use the built-in header. I would consider that if you have a very complicated thing up there, like with javascript and stuff. But so far, I haven’t had to do that except in tests.

BTW Merry Christmas (80F here in Tampa).
Jamie

Re: How to display an image on a header value line using a blob myql field

Ok, sounds good. I was playing with templates this morning for a few minutes and realized that’s how I can make a consistant header across the top. I’ll tweak the code you provided and see if I can make it all work.

I’m not requiring login at first to access the sites, so my site id will be determined by the URL… Appreciate your help!

Merry Christmas to you also! We are very warm up here actually, around 60-70 yesterday… I want snow! lol

Chris