I come to you because I encounter a problem with my while loop.
I did a while loop to get the id of tickets and ticket titles.
Except that, I want to add a <br> but it does not work, it does not move.
I tried with two <br> <br> it's the same, can you help me please?
Here is my code :
<?php while ($row = $req_5->fetch()) { ?>
<?php echo $row['titre']."<br><br>"; ?>
<?php } ?>
<?php while ($row = $req_5->fetch()) { ?>
<?php echo $row['titre']?>
<br><br>
<?php } ?
just put the break tag outside of the anchor element
Related
I have a while loop and I have a HTML code inside the while loop. Inside this HTML code there is PHP code reading a variable that depends on the condition of the while loop.
This variable should be evaluated by PHP. I wrote the code below to solve this but it doesn't work.
$row[0] depends on the condition of while. My code only outputs an empty space for this variable.
<?php
while ($row = mysql_fetch_row($stt)) {
$html='<div class="data">
<?php echo nl2br($row[0]."\n"); ?>
<p>comment
like
share</p>
<p>
0 <span>likes</span>
</p>
<p>
_____________________
</p>
</div>';
echo $html;
}
?>
If you want to display something row by row, do this:
<?php
while($row = mysql_fetch_row($stt)){
$html="<div class='data'>" . nl2br($row[0]) . "\n<p>comment<a href=''>like</a><a href=''>share</a></p><p>0<span>likes</span></p><p></p></div>";
echo $html;
}
?>
> <?php echo nl2br($row[0]."\n"); ?>
this part should be outside of $html.
The interpreter on server side couldnt run.Accordin to php, this part is not a code block. It is just a text.
I found the answer of my question!!!
This is the solution:
<?php
while($row = mysql_fetch_row($stt)){ ?>
<div class="data">
<?php echo nl2br($row[0]."\n"); ?>
<p>comment
like
share</p>
<p>
0
<span>likes</span>
</p>
<p>
_____________________
</p>
</div>
<?php
}
?>
I need to add a total to the categories of an online classifieds website. These totals will dynamically change just as the categories can so it needs to update each time the page loads. I believe i need to use a getTotal command but don't know how or where to input it. Thanks in advance for any help.
The code currently looks like this:
<div class="submenu">
<?php
foreach($catList as $row){
?>
<div class="submenutxt"><?php echo $row->category_name;?> </div>
<?php
}
?>
</div>
Total number of rows in $catList:
<?php
echo "$total rows: <br />";
foreach($catList as $row) { ?>
echo (count($row))." items in this category";
...
I have a table inwhich I also use php's echo to display data inside td elements. Now I have another condition I need to apply for it as whenever the condition is satisfied the table is displayed or else it is removed/turned off.
<?php if(condition)
{
<table>
</table>
}
?>
I would like to know which way to do this best and could help me not to type in " ' " at the beginning of each element's square bracket throughout the whole table ?
UPDATE
It's very simple to geeks and all the talented coders.
if the condition is satisfied then display the table, otherwise don't
display anything in the view. Please remember also that inside my table I also use echo > $data etc to display table's data elements.
<?php
if (condition)
{
?>
<table>
</table>
<?php
}
?>
I do not understand the second part of the question (about the single quotes).
You can use any one method out of given two:
First:
<?php if(condition)
{
?>
<table>
<?php //some statement?>
</table>
<?php
}
?>
Second:
<?php if(condition) : ?>
<table>
<?php //some statement?>
</table>
<?php
endif;
?>
if this is what you mean..
<?php if(condition): ?>
<table>
...
</table>
<?php else: ?>
... do something else in html TAG
<?php endif; ?>
if you dont want to use quotes then yes the Logans answer is the best
Else you can use print or echo
All the best
I'm having trouble writing an if else statement. Considering that I've been doing so for years in ColdFusion, this make me feel very stupid.
Here's the task.
I need to pull first name, last name, email, co-chair status from a database and return the results. However not everyone has an email, so I need a statement that will include a mailto link for those that have emails, and exclude a mailto link for those that don't.
Here's the code I'm using that includes the mailto link for all.
What adjustments do I need to make?
thanks,
david
<?php do { ?>
<?php echo $row_GetMembers['BACmember_First']; ?> <?php echo $row_GetMembers['BACmember_Last']; ?>
<?php /*START_PHP_SIRFCIT*/ if ($row_GetMembers['BACmember_CoChair']=="Yes"){ ?>
<strong> Co-Chair</strong>
<?php } /*END_PHP_SIRFCIT*/ ?><br />
<?php } while ($row_GetMembers = mysql_fetch_assoc($GetMembers)); ?>
This is the line of code you want to optionally display as a link (split for readability):
<a href="mailto:<?php echo $row_GetMembers['BACmember_Email']; ?>">
<?php echo $row_GetMembers['BACmember_First']; ?>
<?php echo $row_GetMembers['BACmember_Last']; ?>
</a>
You'll want something like this instead:
<?php if (!empty($row_GetMembers['BACmember_Email'])): ?>
<a href='mailto:<?php echo $row_GetMembers['BACmember_Email']?>>
<?php echo $row_GetMembers['BACmember_First']; ?>
<?php echo $row_GetMembers['BACmember_Last']; ?>
</a>
<?php else: ?>
<?php echo $row_GetMembers['BACmember_First']; ?>
<?php echo $row_GetMembers['BACmember_Last']; ?>
<?php endif; ?>
If the email field isn't empty (the ! negates the result, so we're checking if it isn't empty), it prints the first and last name inside an anchor tag. If it is empty, it prints the name without it.
A more elegant solution may be to provide the email address as a separate field or link, as opposed to having a list of some names that are links and some that aren't.
I'm using the following section of code to display some icons on our Magento store with the idea being if there is nothing added in the icons section it shouldn't display, for some reason this isn't working...it is displaying a division as if something is there but there is actually nothing.
<?php
if($_helper->productAttribute($_product,($_product->geticons()), 'icons') !== null):
?>
<div class="product-icons">
<?php echo $_helper->productAttribute($_product,($_product->geticons()), 'icons') ?>
</div>
<?php endif; ?>
It needs to show Icons if they are coded in the attribute field and then hide the division if there is nothing added.
I've worked out that the code is returning a value of string(0) what do I need to change in my coding to get the desired effect?
Here's the thing you need, and you don't need call the same functionality twice to get the empty result. Define your variable and check if it is empty (null, undefined or false) or not
<?php $icons = $_helper->productAttribute($_product,($_product->getIcons()), 'icons');?>
<?php if(!empty($icons)):?>
<div class="product-icons">
<?php echo $icons;?>
</div>
<?php endif;?>
this could be even better solution as it wont call the helper unless there are icons defined but you first have to try it out on your codebase.
<?php if($_product->getIcons()):?>
<div class="product-icons">
<?php echo $_helper->productAttribute($_product,($_product->getIcons()), 'icons') ?>
</div>
<?php endif; ?>
and please check if it isn't a typo and it really is:
$_product->geticons()
or should it be
$_product->getIcons()
Something like:
<?php
if($_helper->productAttribute($_product,($_product->geticons()), 'icons'))
{
echo "<div class=\"product-icons\">";
echo $_helper->productAttribute($_product,($_product->geticons()), 'icons');
echo "</div>";
}
?>
would be better!
try
<?php
if(!empty($_helper->productAttribute($_product,($_product->geticons()), 'icons')))
{
echo "<div class=\"product-icons\">";
echo $_helper->productAttribute($_product,($_product->geticons()), 'icons');
echo "</div>";
}
?>