i have a code
<div class="b4_content">
<div class="col_left3 FloatLeft">
<h3>Clients / Projects</h3>
<div id="left_menu" class="left_menu">
<?php
require("admin/Connection/connection.php");
require("admin/functions/functions.php");
$toplvl=0;
/* 1st include of linkCategory.php */
include "admin/functions/linkCategory.php";
?>
</div>
</div>
<div class="col_right3 FloatRight ">
<div class="cright_padd">
<?php
$uploader="admin/";
$catID = $_GET['catID'];
if($catID==""){
$toplvl=2;
/* 2nd include of linkCategory.php */
include "admin/functions/linkCategory.php";
} else {
$toplvl=0;
include "admin/functions/viewImages.php";
}
?>
</div>
</div>
<div class="ClearBoth"></div>
</div>
As you can see i have 2 includes (admin/functions/linkCategory.php) with same pages
My Problem is, the second include "admin/functions/linkCategory.php" does not show up.
Can you help me out
I guess $toplvl is a flag that's used within "admin/functions/linkCategory.php" to do different things. So, maybe the error isn't in this chunk, but in linkCategory.php itself.
My guess is that $catID is NOT equal to the empty string.
And btw, bolding doesn't work inside code blocks (if that's what you were trying to do).
As an alternative, wrap whatever linkCategory.php outputs in a function. Include linkCategory.php once and replace the includes with a call to the function.
if the problem still persists, you could set error reporting to show all and see if there's any output
Related
I have a requirement of showing 2 div's based on a condition like if value is '1' show one div else if value is '0' display another div. Below is my code:
<div class="csv" <?php if($campaign[0]->method != 'CSV'){ echo "style='display:none'"; } ?> >
-----------
------------
</div>
<div class="api" <?php if($campaign[0]->method != 'API'){ echo "style='display:none'"; } ?> >
----------
----------
</div>
Code is looking fine but not working properly. I am trying to achieve this in Laravel 5.4 framework. Any help would be appreciated. Thanks
you can do inline if statements like this:
<div class="csv" <?php echo ($campaign[0]->method != 'CSV' ? 'style="display: none;" : ''); ?>></div>
() - starts the if statement and closes
? - is the if condition is met
: - is the else
It is easy to drop into and out of the PHP processor which will allow you to put the logic into the html file. The following also uses PHP Alternative syntax for control structures
I removed the style="display: none"; bits as I assume that was included to hide the alternate <div>.
<?php //drop into PHP processor mode
if($campaign[0]->method != 'CSV'): //now, back to html processing mode ?>
<div class="csv">
<!-- html markup-->
</div>
<?php elseif($campaign[0]->method != 'API'): ?>
<div class="api">
<!-- html markup-->
</div>
<?php endif; ?>
This is not an exact response to your answer, but you need to have in mind that doing display: none you can always show it playing with the css a bit. In order to prevent that, you should use conditional in php to only render what you desire to show, to prevent the code to be visible. I'd do this way:
<?php if($campaign[0] == 'CSV'):?>
<div class="csv">
-----------
------------
</div>
<?php elseif($campaign[0] == 'API'):?>
<div class="api">
----------
----------
</div>
<?endif;
Or using a switch if there are more options than CSV and API
Use short form of if statement, and write it inside of curly braces as laravel blades' echo.
<div class="api" {{ $campaign[0]->method != 'API' ? "style='display:none'" : "" }}>
It may help you
I have the below section of code and I want to only show the html IF the ID is set in the url. It isn't working and I am not sure why! The same code works on other areas of the page just not here! I am editing some code that someone else built for me, I am a php noob so please bear with me!
Thanks for any help!!
<?php if(!isset($_GET['id'])) { ?>
<div class="control-group"> Show this text </div>
<? } ?>
You have your conditional the wrong way round.
<?php if(isset($_GET['id'])) { ?>
<div class="control-group"> Show this text </div>
<?php } ?>
You have to remove the not (!), obviously. As the logic you want is isset and not not isset.
Try this:
<?php if(isset($_GET['id'])) {
echo "<div class='control-group'> Show this text </div>";
}; ?>
Depending if you want to show the code or not place a ! in front of isset.
I'm finding that placing php code snippets within my website's & tags is causing a problem with the code after it's placement. I first noticed it when placing avatars on my site in a list format where it works fine up to a point and then the same image is repeated for the rest of the list. Here is the code that I'm uisng for that:
<?php
$show_user .= "
<div class=\"section\">
<div class=\"sectionInner\">
<div class=\"searchAvatar\"><img class=\"searchAvatarSize\" src=\"uploads/avatars/$member_avatar\"></div>
<div class=\"searchInformation\"><div class=\"searchInformationPrimary\">$member_name</div><div class=\"searchInformationSecondary\"><i>"$member_summary"</i></div></div>
<div class=\"searchInformation\"><div class=\"searchInformationPrimary\">$member_subtype $member_type</div><div class=\"searchInformationSecondary\">$member_city, $member_county</div><div class=\"searchInformationThird\">View Details</div></div>
<div class=\"clearLeft\"></div>
</div>
</div>
<div class=\"searchResultSplitter\"></div>
";
?>
<?php echo $show_user; ?>
I'm now noticing it when placing php within my navigation bar where it's not closing the tag. Here is my code for the bar:
<div id="pageSubNavigation" class="page<?php echo $thispage; ?>SubNavigation">
Next Page
</div>
After this, all of the other tags show the same link. Any ideas why this might be?
You need to either jump out of the HTML to add the variables or wrap them in {} so they appear correctly.
Example:
<div class=\"searchAvatar\"><img class=\"searchAvatarSize\" src=\"uploads/avatars/".$member_avatar."\"></div>
or
<div class=\"searchAvatar\"><img class=\"searchAvatarSize\" src=\"uploads/avatars/{$member_avatar}\"></div>
Check out this article about string formatting with variables in PHP.
I have a PHP page with HTML content in it. Now I run some PHP codes between HTMLs and I get some results. The fact is, when I try to get a respond from this page by AJAX it'll show me the whole page content and plus the result I was looking for. What can I do to prevent the page from writing extra content. I know whenever something get printed on page it'll go as respond to the AJAX call but I want a way to somehow fix this.
My page file (name: page.php):
<?php echo $Content->GetData('HEADER'); ?>
<div id="Content">
<div id="Page">
<?php if($Content->GetData('PAGE','IS_TRUE')) : ?>
<?php if(NULL !== $Content->GetData('PAGE','TITLE')) : ?>
<?php echo $Content->GetPlugins("Page:" . $Content->GetData('PAGE','ID') . ",BeforeTitle"); ?>
<div id="Title" dir="rtl">
<?php echo $Content->GetData('PAGE','TITLE'); ?>
</div>
<?php echo $Content->GetPlugins("Page:" . $Content->GetData('PAGE','ID') . ",AfterTitle"); ?>
<?php endif; ?>
<div id="Content" dir="rtl">
<div style="float: right; width: 966px; padding: 6px">
<?php echo $Content->GetPlugins("Page:" . $Content->GetData('PAGE','ID') . ",BeforeContent"); ?>
<?php echo $Content->GetData('PAGE','CONTENT'); ?>
<?php echo $Content->GetPlugins("Page:" . $Content->GetData('PAGE','ID') . ",AfterContent"); ?>
</div>
</div>
<?php else : ?>
<div id="Content" dir="rtl">
<div style="float: right; width: 966px; padding: 6px">
There is no page like this in our archives.
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php echo $Content->GetData('FOOTER'); ?>
If I write an address in my browser like this localhost/cload/blog?action=rate it'll go through my redirection list and show the page.php with blog plugin loaded. The problem is I want to call my blog plugin by AJAX through this address but it will first render the page data.
Sorry if this is messy.
I'd suggest modifying page.php to be some functions, primarily a data processing function, and then an output function. Then, when you load the page, put a check in for whether it's an AJAX request, and if so, echo the data you want as JSON, otherwise render the page using the output function.
Alternatively, you could create a second, separate page, but that could be more difficult to maintain than a single file.
Yes, you should check whether your request is a ajax request, if it is so you should change your response to return only the result whatever want.
This php code will give an rough idea on this.
if($request->isXmlHttpRequest()){
return new Response(json_encode($data_array));
}
Hope this will help.
QUESTION ANSWERED:
After messing around with a few things, The combination of the comma at the and of my last array element, and not having the image source path typed correctly was the problem.
Everything works great. It never ceases to amaze me at how a simple syntax error can throw everything out of whack.
Thank you Jonathan and tmsimont! The combo of you're answers fixed my problem.
Time to get a good PHP debugger, Netbeans probably, because Dreamweaver just isn't cutting it for me and I'm not versed enough to hand code YET!
EDIT:
I'm going to try and make myself a little more clear by showing my output source:
<body>
<div id="main">
<div class="container">
<div class="sponsorInner">
<a href="'.$company[1].'">
<img src="img/sponsors/'.$company[0].'.png">
</a>
</div>
</div>
'; } ?>
</div>
</body>
3 things not working:I need the first div with the class gold to render, and the $'s from the array to populate the image link and path.
ORIGINAL QUESTION:
I am trying to create multiple div arrangements on a page using a multidimentional array and a foreach loop to populate the div contents with a an image mnemonically named in a relative path folder and the image to be a hyperlink.
My output is not displaying the first correctly, and not populating the array $'s.
This seems right to me, am I missing some type of escape or syntax?
<body>
<?php
$sponsor = array(
array('Allstate','http://www.allstateagencies.com/'),
array('Arrowhead','http://www.arrowheadwater.com/'),
);
?>
<div id="main">
<div class="container">
<?php
foreach($sponsor as $company)
{
echo '
<div class="gold">
<div class="sponsorInner">
<img src="img/sponsors/'.$company[0].'.png"/>
</div>
</div>
';
}
?>
</div><!--.container-->
</div><!--#main-->
</body>
A total guess.. since that's all I can do with the way you've phrased your question... but if your problem is with the image output, try putting a "/" in beginning the src attribute of the image:
<img src="/img/sponsors/'.$company[0].'.png"/>
that way the browser looks for the img directory from the base of the site, instead of from within whatever subdirectory you're in.
Why not do your array this way
$sponsor = array(
'Allstate' => 'http://www.allstateagencies.com/',
'Arrowhead' => 'http://www.arrowheadwater.com/'
);
and later
<?php
foreach($sponsor as $company_name => $company_site)
{
?>
<div class="gold">
<div class="sponsorInner">
<img src="img/sponsors/<?php echo $company_name ?>.png"/>
</div>
</div>
<?php
}
?>
Edit
Remember, your file name is case sensitive. So the .png will need capital letters in their name. You can add the strtolower() around $company_name if you need them lowercase.
You have an comma at the end of this line which you don't need:
array('Arrowhead','http://www.arrowheadwater.com/'),
Please try to do basic debugging before posting.