i'm working with k2, the joomla content module.
i'm using extra fields and i have a particular need.
i associated some link type extra fields to a k2 category:
i need them to be invisible to users while they create items from frontend,
but then come back visible after i (administrator) filled those fields from backend.
so i just need to hide those extrafields (all the link type) from the itemform view: below is the code where i should add something like
IF
THEN
ELSE
END
but i don't know nothing about php code compiling... can any body suggest something???
CODE:
<table class="admintable" id="extraFields">
<?php foreach($this->extraFields as $extraField): ?>
<tr>
<td align="right" class="key">
<?php echo $extraField->name; ?>
</td>
<td>
<?php echo $extraField->element; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
Change that code to this -
<table class="admintable" id="extraFields">
<?php foreach($this->extraFields as $extraField): ?>
<?php if ($extrafield->name !="name of field you want to hide") { ?>
<tr>
<td align="right" class="key">
<?php echo $extraField->name; ?>
</td>
<td>
<?php echo $extraField->element; ?>
</td>
</tr>
<?php } ?>
<?php endforeach; ?>
</table>
Be sure to do it as a template override so it doesn't get killed when you update.
Related
So I have some code that looks like this
<tr>
<td>
<?php echo "text_". $textnum ?>
</td>
</tr>
And I want the code to function the same as
<tr>
<td>
<?php echo $text_x ?>
</td>
</tr>
Where X is the value of $textnum. I cannot just use <?php echo $text_1 ?> because I dont know which text variable i am going to be echoing
Use <?=${'text_'.$textnum};?> or <?php echo ${'text_'.$textnum} ?>
I have created a simple Business Management setup for office work. First I fetch all information from database. All is going well except the quantity input.
i creat a simple client-Payment System in php. in this first Add any client it's doing simple and all client show at a simple page when click a client name then this page go on the project page when add new project name then all project are show on this page. I want the perticualr client name to pericular project show
<?php session_start(); include("sidebar.php"); include "config.php"; $sel="select * from new_project"; $rs=mysql_query($sel); ?>
<div class="h_right">
<h1> +ADD New Project </h1>
</div>
<div class="h_left">
<table border="2px" cellpadding="10px">
<tr>
<td>Id</td>
<td>Project Name</td>
</tr>
<?php while($rec=mysql_fetch_assoc($rs)) { ?>
<tr>
<td><?php echo $rec['id'] ?></td>
<td><a href="projectdetail.php?><?php echo $rec['project_name'] ?></a></td>
<?php } ?>
</table>
</div>
Use a foreach loop:
<?php session_start(); include("sidebar.php"); include "config.php"; $sel="select * from new_project"; $rs=mysql_query($sel); ?>
<div class="h_right">
<h1> +ADD New Project </h1>
</div>
<div class="h_left">
<table border="2px" cellpadding="10px">
<tr>
<td>Id</td>
<td>Project Name</td>
</tr>
<?php foreach($rec=mysql_fetch_assoc($rs) as $project) { ?>
<tr>
<td><?php echo $rec['id'] ?></td>
<td><?php echo $project['project_name'] ?></td>
<?php } ?>
</table>
</div>
new_project.php doesn't need a project id
projectdetail.php will display project based on the project id passed
I am new to PHP and am running into a small problem with this code. I am trying to make a layout for a page that uses more PHP to fill in the blanks.
When I view the source <? include $navbar ?> is commented out but <?=$pagetitle?> works, why is that?
For reference:
$navbar = "navbar.php";
and navbar.php:
<?php echo "Select Car Change Profile"; ?>
Layout.php:
<?php
echo "
<html>
<head>
<title>Race Data. <?=$pagetitle?></title>
</head>
<body>
<div id='page'>
<table border='1'>
<tbody>
<tr>
<td colspan='3'>Banner goes here.<?=$pagetitle?></td>
</tr>
<tr>
<td rowspan='2'>Left menu</td>
<td colspan='2'><? include $navbar; ?></td>
</tr>
<tr>
<td>Content</td>
<td>Right menu</td>
</tr>
<tr>
<td colspan='3'>Footer</td>
</tr>
</tbody>
</table>
</div>
</html>
";
?>
I'm sure knowing this will help amny future problems I run into.
Also, what are the diferences in using <? ?> vs <?php ?>?
In php, you always need to use <?php /*code*/ ?>
The shorthand version to echo something is <?= /*string*/ ?>, but to run code, such as an include you would need to start with <?php. In your example, this would be:
<tr>
<td rowspan='2'>Left menu</td>
<td colspan='2'><?php include $navbar; ?></td>
</tr>
Correction
I only just noticed that you placed the PHP tags inside another set of PHP tags. You're kind of doing it the hard way. In a PHP file, anything is regarded as an echo, except for content inside <?php ?> tags. So this should work perfectly for you:
<html>
<head>
<title>Race Data. <?=$pagetitle?></title>
</head>
<body>
<div id='page'>
<table border='1'>
<tbody>
<tr>
<td colspan='3'>Banner goes here.<?=$pagetitle?></td>
</tr>
<tr>
<td rowspan='2'>Left menu</td>
<td colspan='2'><?php include $navbar; ?></td>
</tr>
<tr>
<td>Content</td>
<td>Right menu</td>
</tr>
<tr>
<td colspan='3'>Footer</td>
</tr>
</tbody>
</table>
</div>
</html>
The difference is that I didn't put <?php ?> tags around the whole thing.
Try
short_open_tag=On;
in php.ini
And restart your Apache server.
Here's my div and my iframe:
<div class="divMinorView">
<!-- Selected order-->
<iframe id="ifMinor" src="#"></iframe>
</div>
Also inside the iframe I have this table, it populates rows of data, sometimes 10 rows, maybe 50 to 100 at times.:
<table id="slot_table">
<thead>
<tr>
<th> </th>
</tr>
</thead>
<tbody id="slot_rows">
<?php if (count($slots) == 0): ?>
<tr class="none">
<td colspan=9>No slots found in that minor code.</td>
</tr>
<?php else: ?>
<?php foreach ($slots as $slot): ?>
<tr <?php if ($slot->is_expired($end_db_fmt)) { echo 'class="expired"'; } ?>>
<td class="actions">
<?php if (!$slot->is_expired($end_db_fmt)): ?>
<span class="expire_slot">X</span>
<span class="expire_error faux_links tip" data-tip="There has been an error"><img src="/images/thumbs_down_ico.png" width="13" height="13"></span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
<tr>
<td> </td>
<td>
<select id="new_style" name="style">
<?php foreach ($style_list as $style): ?>
<option value="<?php echo $style->get_id(); ?>"><?php echo $style->get_desc(); ?></option>
<?php endforeach; ?>
</select>
</td>
<td class="ints"><input id="new_price" type="text" name="price_point" value=""></td>
<td><input type="submit" name="add_slot" id="add_slot" value="Add slot"></td>
</tr>
</table>
I've tried setting the css to height:100%; as well as setting body{ margin:0; }
I've tried setting the iframe id to scrolling="no".
I'm not sure why I can't get the data to populate to the bottom of the screen. It shouldn't need to scroll, unless maybe the data being populated fills up all the real estate on the page than scroll.
Any help would be greatly appreciated. Should i be using some jquery to fix the height issues?
$("iframe").height($("#divMinorView").height());
$(window).resize(function() {
$("iframe").height($("#divMinorView").height());
});
I have table with variables in it. I want to hide whole table if the first variable is empty. I want to hide id="con_industry (whole table) if $list_primary_industry variable is empty. Here is my code:
<table class="admintable" id="con_industry">
<tr id="con_id_industry1">
<td class="key"><?php echo JText::_('PRIMARY_INDUSTRY');
?></td<td>echo $list_primary_industry; ?></td></tr>
</table>
Set a check before your table:
<?php if(isset($list_primary_industry) && !empty($list_primary_industry)): ?>
<table class="admintable" id="con_industry">
<tr id="con_id_industry1">
<td class="key"><?php echo JText::_('PRIMARY_INDUSTRY'); ?></td>
<td>echo $list_primary_industry; ?></td>
</tr>
</table>
<?php endif; ?>
Like this: (fixed your code a bit)
<? if($list_primary_industry) {?>
<table class="admintable" id="con_industry">
<tr id="con_id_industry1">
<td class="key"><?php echo JText::_('PRIMARY_INDUSTRY');
?></td><td><? echo $list_primary_industry; ?></td></tr>
</table>
<?}?>