I need help writing a php echo that checks if two cells are the same in two tables.
The cells are:
posts>id and reblogs>newid
I have the following code to start with:
<?php if(!empty($reblogDetails->newid)): ?>
<table><tr><td>
<?php echo $newid;?>
</td><tr></table>
<?php else: ?>
original upload
<?php endif ?>
which I borrowed from another snippet but isn't working.
can anyone help?
Your question is not completely clear, but I am assuming you want to show the table with an anchor tag only if the posts->id is equal to the reblogDetails->newid? If that is the case the code you would want would be more like the below.
<?php if(!empty($reblogDetails->newid) && $posts->id == $reblogDetails->newid): ?>
<table><tr><td>
<?php echo $newid;?>
</td><tr></table>
<?php else: ?>
original upload
<?php endif ?>
That being said I doubt your anchor tag is doing what you want. I would anticipate it creating an anchor that looks something like
12
Related
I see two methods but I don't know which is better, should I insert a div tag like this :
echo "<div>";
or like this ?
?> <div> <?php
There's no right answer to this.
When displaying a lot of HTML, I normally use ?> <div> <?php. This is especially true for when looping over data from a database, I would use:
<?php while ($row == $query->fetchObject() ) : ?>
<div class="row-<?php echo $row->id ?>">
//Some more of the data
</div>
<? endwhile; ?>
However, displaying only a little, I normally just echo it.
<?php echo "Hello, my name is <strong>Joe Doe<strong>"; ?>
I would encourage you to play with it and find what you like best.
The text editor i am using has the color formatting, when you are echoing things, it only all comes out the same color, so if you are outside of PHP you get the benefit of the color co-ordination.
I was referring the page.tpl.php(Drupal 7 theme) for understanding the code. I found the following code,
<?php if ($site_name || $site_slogan): ?>
<!-- !Site name and Slogan -->
<div<?php print $hgroup_attributes; ?>>
<?php if ($site_name): ?>
<h1<?php print $site_name_attributes; ?>><?php print $site_name; ?></h1>
<?php endif; ?>
<?php if ($site_slogan): ?>
<h2<?php print $site_slogan_attributes; ?>><?php print $site_slogan; ?></h2>
<?php endif; ?>
</div>
<?php endif; ?>
Can you see the code in third line, <div<?php print $hgroup_attributes; ?>> WHY the php code is inside the first div tag of html? Same thing in later part of code also, as you can see h1 and h2 code. So, what is this convention of combining the html and php in so complicated way? and how should I read that?
Combining HTML and PHP code in Drupal templates is actually a very strong feature. In this case, $hgroup_attributes will probably contain some classes that style the div. Printing it in the template results in something like
<div class="SOME_CLASSES"> ... </div>
If you're further interested in the variable $hgroup_attributes, you can inspect by pasting <?php dpm($hgroup_attributes); ?> in your template file after you've installed the Devel module.
My code spits out candidate information and I want a link next to each candidate directing to ?loadcandidate=id
The data displays fine except it doesn't add the id in the link.. it's just blank (shows as ?loadcandidate=):
<?php
foreach ($cands as $cand):
?>
<?php htmlout($cand['id']); ?>-
<?php htmlout($cand['firstname']); ?>-
<?php htmlout($cand['lastname']); ?>-
<?php htmlout($cand['email']); ?><br><br>
load candidate
<?php
endforeach;
?>
What's wrong with my syntax?
It's an HTML error. You end the href= attribute with " and then add the id.
load candidate
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.