Possible to display username in slider

Hi!

I have a slider on my site and it only allows HTML code input. 

Is it possible to insert a username into it?

E.g. 

Welcome back 

$username = getNickName($ID); 

?

 

Any input appreciated! Thanks!

Embarassed

Quote · 15 Apr 2018

 

Hi!

I have a slider on my site and it only allows HTML code input. 

Is it possible to insert a username into it?

E.g. 

Welcome back 

$username = getNickName($ID); 

?

 

Any input appreciated! Thanks!

Embarassed

Not with HTML.  You need to use PHP code.  Do some research on the net for how to insert PHP code into HTML code.  Heck, here is a link to get you started. http://www.onlamp.com/pub/a/php/2001/05/03/php_foundations.html  

Then you need to search the forum here for how to get the user name, etc.

Geeks, making the world a better place
Quote · 15 Apr 2018

Thanks for the tip!

 

Tried it but didn't work...any clues on what is missing anything here?

 

<html>

<body>

<?php

require_once( '../../inc/header.inc.php' );

require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );

require_once( BX_DIRECTORY_PATH_INC . 'admin.inc.php' );

require_once( BX_DIRECTORY_PATH_INC . 'db.inc.php' );

 

$username = getNickName($ID);

check_logged();

?>

<h2>$username !</h2>

</body>

</html>

Quote · 15 Apr 2018

I'm not sure where all the code in your last post came from, but from memory, you would access the HTML for the slider and enter this line in the appropriate spot:

Html code goes here
<?php $username = getUsername($id); echo  "Welcome Back " . $username; ?>
Remaining Html code goes here

That should trigger PHP for that line only.

You can change "Welcome Back " to whatever you want but the remaining syntax is correct for 7.3.4/5

That's the theory at least.

Quote · 16 Apr 2018

Thanks Johnk42!

 

Tried your code but unfortunately it didn't work.

The username does not appear in the slider. Cry

 

<html>

<body>

<?php $username = getUsername($id); echo  "Welcome Back " . $username; ?>

</body>

</html>

Quote · 16 Apr 2018

Can you post the offending file here please? Otherwise PM me and include the code.

Quote · 16 Apr 2018

Hi johnk42,

 

Thanks again for your help!

 

There is no file involved. It's just a code snippet , i.e. a text/html box, which is provided as a tool in the slider. 

I'm using the Revolution slider. 

Just want to include in the username for logged in users in a slider. 

 

Cheers!

Quote · 16 Apr 2018

You have me totally confused, but that's not hard.

I just did a search and it seems the Revolution Slider is a Wordpress plugin. If that's the case, I'd be interested to know how you integrated it, or plan to integrate it with Dolphin?

Is it a sliding Banner that slots into the home page banner, or do you want it on profile pages?

Quote · 16 Apr 2018

You have me totally confused, but that's not hard.

I just did a search and it seems the Revolution Slider is a Wordpress plugin. If that's the case, I'd be interested to know how you integrated it, or plan to integrate it with Dolphin?

Is it a sliding Banner that slots into the home page banner, or do you want it on profile pages?

Quote · 16 Apr 2018

It's actually both a standalone slider and a plugin for wordpress.

Have already integrated it into dolphin. 

 

I'm using it as a sliding banner on the home page. So want to welcome members back with their username on one of the slides. 

 

Embarassed

Quote · 16 Apr 2018

It's possible the code contains javascript and you're trying to place the PHP inside a javascript section.

Without seeing the code I can't say.  I stopped using PHP many years ago and I now use a "hit and miss" method to get things to work.

Quote · 16 Apr 2018

sure, thanks anyway! Smile

Quote · 16 Apr 2018

Please forgive my rusty responses, but here's something I just recalled from my old PHP days. If a file is an HTML file, the PHP parser probably won't look at it, even though it contains a few lines of PHP. So name the file xxx.php instead of xxx html. That will make the parser realise there's PHP code in the file and force it to read it. If it's called by another file, you will have to change the extension in that file's code.

With your new xxx.php file, make the first line <?php then change it back to HTML with ?> Thus the first couple of lines may look like:

<?php
?>

Run the HTML code until you get to my addition and go back to PHP as shown in my code.

I'm so out of touch I'm not sure if you have to close off the php file, but I don't think you do. If it doesn't work, add

<?php
?> 

at the very end, but I really don't think that's necessary.

If that sounds messy, here's a schematic:

xxx.php

<php
// blah
?>
html code goes here
<?php $username = getUsername($id); echo  "Welcome Back " . $username; ?>
More html code goes here

Quote · 16 Apr 2018

Thanks johnk42 but I only have the option to add the html/text from the slider admin panel. It's a tool which allows you to add in html/text to certain sections of the slides. 

Hence changing the file name is not possible. 

Appreciate your time and help.

Quote · 16 Apr 2018

<h2>$username !</h2>

You can't use variables in HTML like that.  You can use PHP code to echo the value to the output.

You can grab the user ID from the session cookie and then look up the user name in the database using mysql query.  You only need the header.inc.php file in order to get the DB info.

 

//Get member ID from cookie
$iDolUserID = (int)$_COOKIE['memberID'];

mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);

//Get Nick from DB using member ID
$result = mysql_query( "SELECT * FROM `Profiles` WHERE `ID` = '$iDolUserID' " );
while($aArr = mysql_fetch_array($result))
{
    $sDolUser = $aArr['NickName'];
}

If you want the full name then grab it instead of the nick.

Geeks, making the world a better place
Quote · 16 Apr 2018

Also:

Further, we also learned how we could quickly output variables from PHP code without all of the hassle of an echo statement by doing the following:

<?=$variable?>
Geeks, making the world a better place
Quote · 16 Apr 2018

I found this on Stack Overflow. I haven't tried it, but it may just do the job. Once again, use my code because I've tested it and it works.

----------------------------

You can't run PHP in .html files because the server does not recognize that as a valid PHP extension unless you tell it to. To do this you need to create a .htaccess file in your root web directory and add this line to it:

AddType application/x-httpd-php .htm .html

This will tell Apache to process files with a .htm or .html file extension as PHP files.

---------------------------------

Try adding the line to your existing .htaccess

You can shout me a beer if it works!

Quote · 17 Apr 2018

Thanks johnk42 but I don't think that's the solution. 

Here's a beer anyway. Wink

Quote · 17 Apr 2018

For a fee I will do this for you.

Geeks, making the world a better place
Quote · 17 Apr 2018

thanks but if i wanted to pay someone, i would have already approached anton, modzzz or others. 

appreciate the offer though.

Quote · 17 Apr 2018

 

thanks but if i wanted to pay someone, i would have already approached anton, modzzz or others. 

appreciate the offer though.

 Yeah. 

Geeks, making the world a better place
Quote · 17 Apr 2018

There's nothing like a challenge! The original code I gave you worked perfectly in a PHP block, but not in a Text or HTML block. Hic!

Quote · 18 Apr 2018
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.