I am stuck with an issue here. I am trying to read out a column (pdf) from my mysql db by php and show it on the website as a link. the column's value are pdf names of files saved on the ftp and i want to display it as a link on the page.
<?
$rs_news=mysql_query("SELECT * FROM news WHERE ueberschrift_$lang NOT LIKE '' ORDER BY id DESC");
if(mysql_num_rows($rs_news)>=1){
?>
<? for($i=0;$i<mysql_num_rows($rs_news);$i++){ ?>
<h4 <? if($i>=1){echo("style='margin-top:24px;'");} ?>>
<?= mysql_result($rs_news,$i,"ueberschrift_$lang"); ?></h4>
<img src="../news/bilder/<?= mysql_result($rs_news,$i,"userfile_1"); ?>" onerror="this.style.display='none';" style="padding-top:3px; padding-right:7px;" width="150px" height="110px" align="left"></img>
<?= mysql_result($rs_news,$i,"langtext_$lang"); ?><br><br><br>
Test
<? } ?>
<? } ?>
I know my coding might be ugly, I am very new to PHP and trying to do simple things but I guess I think too complicated.
I have a DB with rows where SOME have a PDF value and some dont.
What I want is that at displaying it only picks those which have a PDF value and displays it via echo like this:
Test
The default value in the column pdf is NULL, I tried to do it via if empty but didnt succeed.
Please let me know if you have any solution for this.
Thanks.
K.
Related
I am trying to store HTML and PHP in a MySQL text field and display it in PHP.
When it displays on site it renders as commented out tags:
<!--?php
if(isset($sp_msg) && $sp_msg != ''){
print '<div-->
This of course screws the whole page up.
How am I supposed to go about displaying this data correctly? I would like to eventually add this to a full functioning CMS so I would like to understand how to do this correctly.
page.php
<?php
require_once('library/autoload.php');
$pid = $_REQUEST['id'];
$page = $ct->get_page_info($pid);
$sp_msg = $page['special_msg'];
require_once('h.php');
?>
<div id="row">
<?php
print $page['page_content'];
?>
</div>
<?php
require_once('f.php');
?>
'page_content' stored in mysql as text
<h3>MY HEADER TEXT</h3>
<?php
if(isset($sp_msg) && $sp_msg != ''){
print '<div>'.$sp_msg.'</div>';
}
?>
<hr>
<p>paragraph text</p>
You need to eval the stored php code. When you print out the string stored in the MySQL you don't run it, you only print it.
<div id="row">
<?php
eval($page['page_content']);
?>
</div>
Warning:
I really don't recommend it. If any suspicious code can be entered into that DB it could cause really big problems. You can't check the PHP code if its not a crypto virus for example. This code will execute anything on the server.
See the PHP manual: eval
I have a MTSQL database where up to 25 images can be stored, in table fields called picture1 through to picture 25.
What i want to do is check these variables once they are pulled from the database to see whether they should be displayed or not.
currently if there isn't an images it still shows and you just get the missing image sign. And no matter what i seem to write it shows regardless off if there is an image or not, below is my current code.
<? if(!isset($picture2) || empty($picture2)){ ?
<div class="property-slide">
<a href="m/properties/<?php echo $row['picture2']; ?>" class="image-popup">
<img alt="" src="m/properties/<?php echo $row['picture2']; ?>"></a>
</div>
<? } ?>
The value of picture 2 is currently just 1.jpg which is located in a folder on the server at the path m/properties/.
I did consider storing all the images seperatley, which would be easier as i could use a query to show all relevant properties, but this was pre built by somebody else and the database is populated from a third party api.
I have a set of fields such as title, body, header, footer, signature and so on. When i fill these fields which are sections of a letter, a preview of what is being filled should show as the link given here: http://www.cvplaza.com/wp-content/uploads/2012/09/cover-letter-example.png
I will be developing this using codeigniter and want to know libraries or any other technologies to achieve this. I will also need to set predefined templates for the letter so once i loads them, i can then fill-in details and the preview fill format and show the final draft.
Something like this?
Guess some normal html would suffice, just create a html mockup, including some <address> tags etc (or whatever you want), and use some css to make it look like you want. Nothing special about it...
EDIT
reply on the comment: yes and no, ofcourse you can limit the number of characters or even words, but note that calculating dimensions based on text is nearly impossible. Except for monospace fonts every letter has it's own width, which is based on several variables, amongst others the rendering engine, which depends on the os and even the browser, the font chosen, etc. etc.
Except for if you have a lot of time and/or resources, I'd go with a practical solution. If you do have both, you can dynamically parse pdf files, using, eg. FPDF or TCPDF. Or you can look into dynamically parsing LaTeX, which gives you beautiful results with minimal effort in creating a page layout. But consider; is it worth the trouble?
In case of html and latex, you can create templates the way you would create normal html templates. An example for the template I created in the fiddle would look like this in php:
<div class="letter">
<header>
<div class="sender">
<address>
<?php echo $sender['name']; ?><br/>
<?php echo $sender['address']; ?><br/>
<?php echo $sender['city']; ?><br/>
<?php echo $sender['zip']; ?><br/>
</address>
</div>
<div class="date">
<?php echo $date; ?>
</div>
<div class="recipient">
<address>
<?php // recipient... ?>
</address>
</div>
</header>
<div class="body">
Dear <?php echo $recipient['full_name']; ?><br/>
<br/>
<strong><?php echo $subject; ?></strong><br/><br/>
<?php echo nl2br($message_body); ?>
</div>
</div>
I'm trying to Display a download link using two fields in the backend using magic fields (wordpress)
My code to display one link is.
<?php if (get('upload_file') != "") { ?> <p>Download - <?php echo get('upload_file_name'); ?></p>
<?php } ?>
This works fine and displays it as a link on the front end.
But my magic fields are in groups. So when i duplicate a group the in the back end. and add another name and file etc. It does not show in the front end. it just shows the one.
Can any one show me how to get the links showing in the front? no matter how many times i duplicate the fields?
Hope this made sense.
I've fixed this.
This is the code i used. incase anyone wants to know.
<?php $members = get_group('upload'); ?>
<?php foreach ($members as $member): ?>
<p> Download - <?php echo $member['upload_file_name'] [1] ?></p>
<?php endforeach; ?>
How can I display a certain HTML code in a php generated page.
For example, php will automatically display the name and category of an item, yet I want to add custom pictures to this generated page. Is there any way to do this without creating a separate HTML page to include into the generated page?
I'm hoping for something like a database entry where to add the html part to display. Is it possible?
ps. Sorry if I didn't express my idea in a completely understandable way.
Store the image URLs just like you are storing the names and categories. Then you would just do something like:
<span id="name"><?= $name ?></span>
<span id="category"><?= $category ?></span>
<img src="<?= $image ?>" />
Maybe you need to clarify - why do you need different HTML for each page, if the only thing changing are the images?
Keep in mind here I use <?= $foo ?> which is generally considered bad practice, and is just shorthand for <?php echo $foo; ?>.
Just wrap the PHP in your HTML:
<h1>My Test</h1>
<?= $myCategory; ?> - <?= $myItem; ?>
<img src ="mySource" alt="myImg" width="15" height="15" />
This also works for your HTML in your Database:
<p><?= $myDatabaseHTMLContent ?></p>
Cheers,
Max
<?php
//Your php code
?>
<img src="" />
<?php
//Your php code
?>
You can put html in a php file, like the example above.