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
Related
Im trying to send the patient ID through a hyperlink, tho while it redirects to the correct page it is not sending the information.
<a href="./patientrecord.php?patient_id="<?php $row["patient_id"]?>><?php echo $row["surname"];?></a>
Please make sure you are going to echo the variable
Echoing a variable:
<?= $echoable_variable_here ?> // Use <?= ?> tags
or
<?php echo $echoable_variable_here ?> // Use echo inside <?php ?> tags
Edit: You have placed echo outside the href attribute tag
Therefore,
Change this:
<a href="./patientrecord.php?patient_id="<?php $row["patient_id"]?>><?php echo $row["surname"];?></a>
to:
<?php echo $row["surname"];?>
or to:
<?php echo $row["surname"];?>
I've created a simple query to create a list of dates and descriptions from my calendar database.
The idea is that I have a PHP webpage that show a text list that I can quickly copy and paste into an email or text message.
My problem is that, although the text shows up correctly on the web page, when I paste the info into a text editor (Word, email, whatever) I'm getting tabs between each column.
How can I format the text in PHP so that it pastes correctly?
This is my code:-
if(mysql_num_rows($AvDates) > 0){
?>
<ul>
<?php
while ($row_AvDates = mysql_fetch_assoc($AvDates)){
?>
<li>
<?php echo htmlentities($row_AvDates['Month']);?>
<?php echo "-";?>
<?php echo htmlentities ($row_AvDates['the_days']);?>
</li>
<?php
}
?>
</ul>
<?php
}
?>
This gives me output that looks correct, but pastes like this...
(Month[tab]"-"[tab] Dates)
How do I loose the tabs?
You're closing php and letting the HTML output be rendered. See tab chars below:
[tab]<li><?php echo htmlentities($row_AvDates['Month']);?>
[tab]<?php echo "-";?>
[tab]<?php echo htmlentities ($row_AvDates['the_days']);?></li>
Solution:
<?php echo htmlentities($row_AvDates['Month']) . '-' . htmlentities ($row_AvDates['the_days']); ?>
Darren.
Try to use this code, it should solve your problem:
<?php if (mysql_num_rows($AvDates) > 0) : ?>
<ul>
<?php while ($row_AvDates = mysql_fetch_assoc($AvDates)) : ?>
<li><?php echo htmlentities($row_AvDates['Month'])."-".htmlentities ($row_AvDates['the_days']);?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
Hope it helps.
you can have the whole output in one single like this
<?php echo htmlentities($row_AvDates['Month']) . '-' . htmlentities($row_AvDates['the_days']);?>
instead of separate php tags
If you want to separate code across multiple lines, not all code in one line:
if(mysql_num_rows($AvDates) > 0){
?>
<ul>
<?php
while ($row_AvDates = mysql_fetch_assoc($AvDates)){
?>
<li><?php
echo htmlentities($row_AvDates['Month']);
echo "-";
echo htmlentities($row_AvDates['the_days']);
?></li>
<?php
}
?>
</ul>
<?php
}
?>
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
I'm very newbie regarding PHP, I'm trying to configure my wordpress Loop.
I figured out how to display my customfield in my template, I manually added a title before my taxonomy and custom fields, but I'd like it doesn't show if the taxonomy is empty.
Here is the code:
<div class="customfields">
<h2 class="widgettitle">My Title</h2>
<?php echo do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?>
<?php echo do_shortcode('[custom_fields_block]'); ?>
</div>
I would very much appreciate your help!
Thanks a ton,
T.
So code should be
<?php $taxonomy = do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?>
<div class="customfields">
<?php if(!empty($taxonomy)) : ?>
<h2 class="widgettitle">My Title</h2>
<?php echo $taxonomy; ?>
<?php endif; ?>
<?php echo do_shortcode('[custom_fields_block]'); ?>
</div>
If you want to show content in HTML only if certain variables contain a value then you can create a simple if statement that uses PHP's isset function to determine whether or not the variables are set, and if true place some HTML on the page. You can read more about isset here.
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.