i have a website that if fully dynamic from page building,menus etc now previously before making it dynamic i made static pages for the client and after that he told me make everything dynamic!
i am using summernote editor for dynamic editing now summernote has an option of custom html in which we can write our code so what do i do simply is i copy the code from static pages one by one and add the html to summer note custom html editor side! now everything is working fine as it should but what happens it that on the front end base_url() variable is not echoing the path as it normally should,now the data of the page is received from database the variable syntax is fine i have also autoloaded url in my config file but still it is not working here is a demo of the code.
html
<?php include "includes/header-others.php" ?>
<div id="parent_margin">
<div class="container generic generic_diagnostic">
<?php
print_r($text[0]->page_data); //this line is printing the result from database
?>
</div>
</div>
<?php include "includes/footer-others.php" ?>
An example how data is being stored in db
<img onclick="blur_image(this.id)" src="<?=base_url()?>images/ourteam_1.png" class="img-responsive"/>
i dont know what is the issue! the same html code works fine when using in static pages and on dyamic pages where datab comes from db its does not echo the value of base_url()..
Related
Problem - I've created a DB Connection, I've queried the DB, and I've turned the results into an associative array. Displaying the SQL Data using PHP is the trouble I'm having. I've managed to display it in a basic way, however my aim is for this information to display as a 'News Column' down the side of the page, and therefore I need the data to be inserted into Divs for me to be able to manipulate.
Attempt thus far - As one can see below, the presentation of this attempt to display my data is cringeworthy. However in this way I did manage to distinguish the types of headings for each piece of data.
echo "<h2>" . $row["title"]. "</h2><h3>Date: " . $row["dateTime"]. "</h3><h4>Passage: " . $row["passage"]. "</h4><br>";
HTML For Current Webpage:
http://i.imgur.com/9U1TWkd.png (What my 'News Column' looks like)
http://i.imgur.com/1tgA0sx.png (My HTML Code I want Data to be inputted into) - The aim is for someone to be able to complete this form (http://i.imgur.com/0xMnOVB.png) and the data to go into the DB (done this), and display in the column with the 'Title' appearing in the right place, same with 'Date' and finally with the 'Passage'.
What I've Found Online:
I dislike wasting people's time so I've spent a few hours searching online. Thus far I've found mostly people creating HTML Tables with their SQL Data, which is great and all, however I've not found anyone who's using Divs/Headings/Paragraphs etc...
My CSS:
I have a CSS File which I'm retrieving (or whatever the term is) via HTML Code which is working (so far).
Interestingly, you seem to have all the components you need: An example of how the markup (the HTML) needs to be outputted and the DB query and data to inject into it. Unless I'm missing something (it's always possible!), then all that remains is for you to glue the two together.
Assuming the form represented in your most recent graphic is generated within a .php file you can either pre-build a giant variable containing all the markup necessary to render your output, or write some static HTML and insert only the dynamic elements using native PHP (PHP is itself a templating language of sorts).
Using the latter method you'd do something like the following (forgive different CSS class names and tag hierarchy, I can't copy/paste from a PNG :-)
<div class="wrapper">
<?php foreach($myResult as $row): ?>
<div class="article>
<h3><?php echo $row['Title']; ?></h3>
<div class="date"><?php echo $row['Date']; ?></div>
<p><?php echo $row['Body']; ?></p>
<div>
<?php endforeach; ?>
</div>
I'm making a simple CMS thingy in PHP, and I made a simple guestbook module for it.
In my index.php I include template.php (which has HTML) and calls a function which returns the content for the specific page.
<div id="content">
<?php content(); ?>
</div>
The content function is inside functions.php which is include before template.php inside index.php.
Inside content():
print_r($_POST); // the data is displayed :)
require_once(BASE_URL_MODULES.$tempMod."/".$tempMod.".php");
Inside the PHP file I included (with require_once) all $_POST data is lost. print_r($_POST) shows a empty array.
Am I doing something wrong a.k.a. is this normal behaviour? If so, does somebody has a solution?
I'm using the ancient 4.4.9 version of PHP. Can't upgrade it because the provider doesn't want to upgrade the stuff.
Is there any way to store PHP code in a text file (for a navbar that may change) and access this text file via file_get_contents and add it into a div in a PHP/HTML document?
What you have to do is
<div class="navbar">
<?php include("nav.php"); ?>
</div>
You can use the built in include() function in PHP.
See docs here: http://www.php.net/manual/en/function.include.php
Using this means you essentially read in the contents of the file, and insert it directly where you are making the call. In your case it might be something like:
<div id="menu">
<?php include('partials/menu.php'); ?>
</div>
Whatever you have in the menu.php file (located in partials folder) will be inserted inside the menu div.
As a side note, since it's basically injecting whatever is in the file, you can also use any variables that you set in the menu.php file if need be
Use one of these
www.php.net/include
www.php.net/require
www.php.net/file_get_contents and www.php.net/eval
I'm adding some pages to default layout editor in SE4. What I do is just adding pages to core_pages table and editing core_content table to add a main container and a middle/right two columns layout. Everything works fine, but now I'm adding default Create Video page (videos_index_create) and I got some problems.
When I add this page via sql, I can obviously see and edit page layout by default layout editor. Actually, when I save changes these don't reflect to live page. If I go to the controller (Video/controllers/IndexController.php) and add
$this->_helper->content->setNoRender()
live page displays right sidebar and middle content, but with
$this->_helper->content->setEnabled()
it shows only the default video upload form.
So I edited create.tpl here
<?php if (($this->current_count >= $this->quota) && !empty($this->quota)):?>
<div class="tip">
<span>
<?php echo $this->translate('You have already uploaded the maximum number of videos allowed.');?>
<?php echo $this->translate('If you would like to upload a new video, please delete an old one first.', $this->url(array('action' => 'manage'), 'video_general'));?>
</span>
</div>
<br/>
<?php else:?>
<?php echo $this->form->render($this); ?>
<?php endif; ?>
Changing the else deleting the echo statement and adding a simple echo 'foo';. Now, live page shows properly my layout (middle+right) with default content ("foo").
I figured thus that the issue is about this line in controller:
$this->view->form = $form = new Video_Form_Video();
but I can't go further… this custom form class (Video/Form/Video.php) seems nothing special, I can't really figure out why its rendering crushes default layout render.
Any social engine expert right here to help me? :)
If its a Zend_Form I am pretty sure you should be doing:
<?php echo $this->form;?>
In your view not call render yourself.
If it is NOT a Zend_Form please post the code for the form it probably has some css or whatnot breaking your layout.
This is probably going to be quite an easy question for everyone, and I have tried following and understanding tutorials, but I just cant get my head around it!!
Ok so for University me and my peers are creating a student assesment system, my task is to create a results view page.
Basically I have been given a file called index.php which has a template background with a header and footer thats just looks like a normal web page. I need to be able to display results from a table from a database (I dont have yet but can create a test to test it) that has data into a certain position of that index.php page.
I have phpadmin installed and have tried creating a test database and table to insert in, but it just doesnt work when i follow tutorials like this one http://www.siteground.com/tutorials/php-mysql/display_table_data.htm , i just cant understand it, which im sure if my fault!!!
Someone else is writing the query's ill need, but firstly im just trying to understand how I even do this, and how i tell it to go to the index.php page, and where to place the table on that page.
This is the php code for the index.php file if i open it in notepad ++
<?php
/*use template to create pages*/
include('templates/header.html');
include('templates/topMenu.html');
?>
<div id="contentwrap">
<div id="content">
<div style="clear: both;"> </div>
</div>
<?php
require_once('templates/sidebarStudent.php');
?>
<div style="clear: both;"> </div>
</div>
<?php
include('templates/footer.html');
?>
So my question is do I just enter some code somewhere in this index.php file that tells it where to get the database and table from? and how do I tell it where to position the table in the page, or do I have to create seperate php files for this?
Please help! :(
If you were able to create some sort of test database, then you can use this basic code example to get up and running. You can put this inside one of those <div> tags to get the content to show up where you need it. Make sure you update the parameters below for your database username, password, database name, etc.
<?php
$link = mysql_connect('localhost', 'db_user_name_here', 'db_password_here');
mysql_select_db('db_name_here', $link);
$result = mysql_query('SELECT * FROM table_name_here');
while ($row = mysql_fetch_assoc($result)) {
echo $row['column_name_here'] . "<br>";
}
mysql_close($link);
?>
If you still have trouble, then you'll need to make sure you have a proper database user, a database, and a table inside that database. It might be best to look for a tutorial because it will likely walk you through the steps necessary better than I can do here.
Excellent question.
It rarely occurs when someone even bother with it.
Most of time the usual scenario for the PHP script is just to put everything into one perfect mess.
Yes, you have to always use separate files for the PHP and HTML code (business and presentation logic to be correct).
The guy who is writing queries have to put all the code into separate file which collects all the data into some variables which have to be passed into template file.
Then his code has to set the name of the file which contains the page template.
And finally call your main page template.
So, the index.php file should contain NO HTML code, but PHP only:
<?
//include settings, connect to database etc.
include dirname($_SERVER['DOCUMENT_ROOT']).'/cfg/settings.php';
//getting required data
$DATA = db::getarr("SELECT * FROM links");
// setting title for using in the main template
$pagetitle = "Links to friend sites";
//etc
//set page template filename
$tpl = "links.tpl.php";
//and then finally call a template:
include "main.tpl.php";
?>
where main.tpl.php is your main site template, including common parts, like header, footer, menu etc (there is no need to have header and footer in the separate files):
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My site. <?=$pagetitle?></title>
</head>
<body>
<div id="page">
<? include $tpl ?>
</div>
</body>
</html>
and links.tpl.php is the actual page template:
<h2><?=$pagetitle?></h2>
<ul>
<? foreach($DATA as $row): ?>
<li><?=$row['name']?></li>
<? endforeach ?>
<ul>
Eventually you may come to more complex designs, like with front controller one, but for the first site this one is both easy and powerful.