Codeigniter how to retrieve base_url from database in php codeigniter - php

As I am retrieving a column of content in html form, from database as this column contain text and image which is retrieved through base url();
see example:
<p>Although the complexities, individualities and uniqueness of the human mind is beyond
imagination, let alone comprehension.</p>
<img src="<?php echo base_url(); ?>assets/uploads/guide-banner.jpg" alt="guide" />
data mentioned above is stored in database field. I can retrieve html fine but I can't access base_url() from database field, help me what i'm doing wrong calling php while we are already in php ??

You cannot execute PHP code inside PHP code !. I think we can do some trick to make PHP chunks executable.
At this point we need JavaScript capabilities , you have to put that column content into JavaScript variable , then output that variable to your page while loading. You can notice at that moment your PHP code converted to real output !
I hope this helping you !

you can use like this syntax.
<img src="' . base_url() . 'assets/uploads/guide-banner.jpg " alt="guide" />'

you can use like this syntax to retrieve image from database in codeignitor
<?php foreach($results_partners as $part) { ?>
<a href="main/partner" class="roller-item fancybox fancybox.ajax">
<img src="<?php echo base_url() .'cms/uploads/partners/thumb_290/'.$part->partner_image; ?>" style="width:264px; height:263px;">
</a>
<?php } ?>

assign your base_url() to a variable like
$base_url = base_url();
modify your code as shown
<p>Although the complexities, individualities and uniqueness of the human mind is beyond
imagination, let alone comprehension.</p>
<img src="{$base_url}assets/uploads/guide-banner.jpg" alt="guide" />
---^

it will solve this: change your base_url(); to the content of base_url : exp:http://localhost/blablabla;
through var_dump(base_url());

Related

Small help var with a country code value (number) = open jpg

I have a portal build in PHP + mysql. There's a specific field with the country code value ie "351" in number format.
Can I use the var countrycode.jpg to open the respective file?
something like
$var = "351"
<img src=$var.jpg>
ps: i have a folder with all country codes in (number).jpg format
sorry my dumb question. Thanks in advance for any help.
Cheers
To use php inside html element use echo, something like
<img src="<?php echo $var ?>.jpg">
The question is not very clear, but this is what I assume you want to achieve.
you want to show the image 351.jpg and that actually exists on your server then you can show it like this.
$var = 351;
<img src="<?php echo $var; ?>.jpg ">

Use a PHP variable to dynamically display an image in HTML

I'm trying to use a variable in a .php file to choose img src.
Here's my attempt:
<?php echo "<img src=\"$ICON\">"; ?>
or
<img src="<?php echo $ICON; ?>"/>
Neither have worked, is there anything obviously wrong? There's nothing displaying, not even the code, when I render the page.
Any guidance would be much appreciated, especially a correct implementation of the above. Sorry for poor code, only looked at these languages since yesterday.

Can i get a table name and turn it into a variable then put it in a img tag

I'm trying to make a vote thing for my Minecraft server. I want it to show
on there as in the site. The database is MySQL.
Here is my code. It's just a test; I'm just trying to turn a link into a variable.
<?php
$imageNumber = https://minotar.net/helm/GRANTSWIM4/100.png;
?>
<img src="<?php echo $imageNumber ?>.jpg">
The code you provided will work fine, assuming you fix the syntax issues and remove the double extension (you are appending .jpg after the .png).
<?php $imageNumber = 'https://minotar.net/helm/GRANTSWIM4/100.png'; ?>
<img src="<?php echo $imageNumber ?>">
If you are asking how to get a MySQL table name and reference the value in a variable, then yes. You can retrieve the table name from the result with mysql_tablename or get the full list of tables with mysql_list_tables methods.
But I wouldn't suggest you to include your table names on the client side.

How do I call in an image in php using a href?

I have a bit of code that, using php, I want it to call in an image rather than what it is currently calling in (which is 'echo bloginfo('name');). However, I am sadly PHP illiterate and have no idea how to do this with the 'a href' posted below. Could anyone help me call to /images/logo.png? Many thanks in advance!
<h1><?php echo bloginfo('name'); ?></h1>
The tag for add images is <img src=""> on the srcattribute you need to write the url of the image you want (in your case /images/logo.png) so, replacing the code you pasted
<h1><img src="/images/logo.png"></h1>
Take into account that the path to the image you are using now is a relative one (relative to the document requiring the image) so you probably want to have the absolute url instead.
...place at the beginning of you webpage, near the top with the rest of your PHP/JavaScript:
<?php
$image_name = '/images/logo.png';
?>
...In this are you place allof your HTML...
<img src='<?php echo $image_name; ?>'>
Basically, you can have a variable named 'image_name' that you can have be anything.
If you wanted the HREF link area to be a variable that could be changed as well, just do this:
<?php
$image_name = '/images/logo.png';
$image_url = 'http://www.google.com';
?>
Then...
<a href='<?php echo $image_url; ?>' border='0'><img src='<?php echo $image_name; ?>'></a>
What is the return of get_settings() function? ==> name's Image?
I think this code is OK, but you should check the return value of your function.

passing arbitrary html to a popup window

I am calling my makewindows function from a PHP file like so:
echo "Click for full description </p>";
This generates correct html, which results in a popupwindow containing the html from $html. For example(most of the html has been snipped):
Click for more
Now, I want to make an image above the link clickable, to display an image instead of html, using the same method.
I made an $imagehtml variable in php like so:
$imagehtml = "<img src='".$imageSrc."' >";
$imageSrc is the result of another method, but is always without fail a valid url for an image
passing $imageHtml to makewindows should work(the fact that it is not standards complaint html is irelivant, at least as to why what I am trying is failing. The same single line of html in a standalone html file displays in every browser fine.)
this results in the following html:
<a href="#" onclick="makewindows(<img src='removed.jpg' >); return false;">
<img src="removed.jpg" width="250" height="250"></a>
This completely fails. It has nothing to do with the image path, as no window is created at all. All I am doing is changing the variable passed, surely the window should still be created, regardless of the contents of the html?
this fails even if trying to pass about:blank, for example defining imagehtml as follows:
$imagehtml = "about:blank";
results in:
Click for full description
yet still no window.
You want something like this:
$str = '<img src="...">';
echo '<a href="#" onclick="makewindows('
. htmlspecialchars(json_encode($str))
. '); return false;">Click for full description</a></p>';
This will do the correct encoding / escaping.
You’re probably doing something wrong.
Let’s say you want to pass this HTML to a JavaScript function call inside an HTML attribute:
<img src="removed.jpg" width="250" height="250">
Then doing this is enough:
$html = '<img src="removed.jpg" width="250" height="250">';
echo 'Click for full description</p>';
The var_export function converts the value into an (PHP) equivalent expression and the htmlspecialchars function finally converts the HTML meta characters into character references.
This might not be the most elegant way, but it works.

Categories