I am building a website which will be used for posting tables in each post. For this purpose I have written a custom post code which enables the user to create tables simply by using ACF and data from database.
The thing is I would like to show the table also in the excerpt of the each post but I only get the post text written in the WP Post, written by the end user.
For now i have set it this way:
<!-- Blog Content -->
<?php echo $current_post['content'];
//Start my custom table code (HTML + PHP)?>
<table style="undefined;table-layout: fixed; width: 100%">
.
.
.
.
.
.
</table>
<?php
//End my custom table code
?>
Right now, only the content which is written by the end user ($current_post['content']) is showing in the excerpt, while in full post preview my custom table is showed normally.
What is the best way to solve this?
Thanks in advance!
$head1Title = $_POST['postTitle'];
$text = $_POST['postText'];
<table>
<tr> <th><?php echo $head1Title; ?> </th> </tr>
<tr> <td> <?php echo $text; ?></td></tr>
</table>
maybe try this one example?
Related
I'm trying to make a filter in functions.php of my website in Wordpress, to show some information on the customer's invoice:
echo get_post_meta($order_id,'bairro',true) . get_post_meta($order_id,'billing_complemento',true);
I've tried the following, it's retrieving the information all together, I wanted to divide it into lines. I tried it this way:
<tr class=“bairro”>
<td><b>Bairro: </b> R$ <?php echo get_post_meta($order_id,'bairro',true) ?></td>
</tr>
<tr class=“billing_complemento”>
<td><b>Complemento: </b> <?php echo get_post_meta($order_id,'billing_complemento',true) ?></td>
</tr>
<?php
but it’s giving a fatal error on the site, I believe it’s just some kind of closure. Someone to save me there?
I'm trying to solve this current problem which I could use some help with:
From the database using php, the page must load an X number of sections, every section has some content on top, a table and some content on the bottom, the table can have 0 to any number of rows, depending on what was previously in the database.
Aside from the table the rest of the content doesn't vary in size.
I cannot know beforehand what will be the size of each section because of the table, and there is usually at least 30 sections.
This page must be print friendly, and aside from the page-breaks everything is already working.
I need to find a way to dynamically add page-breaks to fit the sections into the page without cutting them between pages.
The code is about 400 lines so it wouldn't be practical to post it here, but the section structure is something like this:
<section class="row">
<section>
<section class="col-md-2"></section>
<section class="col-md-8 printcenter">
<p class="docenteheader" >
<span class="tabspaceright">NAME: <strong>name</strong></span>
<span class="tabspaceleft">ID: <strong>number</strong></span>
</p>
<table>
<tr>
<th><strong>1:</strong></th>
<th><strong>2:</strong></th>
<th><strong>3:</strong></th>
<th><strong>4:</strong></th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</table>
<p><strong>Something1:</strong> Something</p>
<p>
<span><strong>Something2: number</strong></span>
<span ><strong>Something3: number</strong></span>
</p>
<section class="rel_endline"></section>
</section>
<section class="col-md-2"></section>
</section>
</section>
I removed the css classes and original names and PHP code to facilitate viewing
Here is sample PHP code, let me know if anything is unclear. I tried to use self-explaining variable names.
<?php
$PAGEBREAK_LENGTH = 1000; // Add a page break every 1000 characters.
$lengthTracker = '';
while ($row = odbc_fetch_array($res)){
$lengthTracker .= $row['article'];
$lengthSize = strlen($lengthTracker);
if ($lengthSize > $PAGEBREAK_LENGTH) {
echo '<div class="page-break">This is a page break</div>';
$lengthTracker = ''; // Reset length tracker since we just added a break
}
echo '<div class="article">';
echo $row['article'];
echo '</div>';
}
?>
If you include the if ($lengthSize > $PAGEBREAK_LENGTH) before echoing the article, you will tend to include page-breaks "more often." If you include the if statement after the article is echod, you will have page-breaks less often (so you'd have potentially bigger blocks of text).
Experiment with both ways to see which style you prefer, since you (presumably) can't include page breaks mid-article.
I found out that my problem was caused not by the faulty page breaks, but I had negative margins in an element, that messed the entire way page breaks work, by removing that, it worked normally.
I'm very new to PHP and database queries.
I have a WordPress site with the Genesis framework installed and I'm creating a child theme from it and adding some template pages to insert data from my database. I'm creating a category page and a product page.
I'm having issues on some of the queried data on the category page, if there is anyone out there that can point me in the right direction, I'd be extremely grateful.
I have all the database rows outputting individually in a table format, which is exactly how I want it, but I can't get a heading to output above the displayed products, I've tried lots of solutions but none so far have done the job. Here is my code:
function child_product_data_loop() {
global $wpdb;
$category = $wpdb->get_results("SELECT * FROM product_data WHERE prod_cat_1='Retractable Plastic Pens';");
echo "<main class='content'>
<article class='page type-page status-publish entry' itemscope='' itemtype='http://schema.org/CreativeWork'>
<header class='entry-header'>
<h1 class='entry-title' itemprop='headline'>".$category->prod_cat_1."</h1>
</header>
<div class='entry-content' itemprop='text'>
<p>For more information on any product within our ".$category->prod_cat_1." range please click on "details and prices".</p>";
foreach($category as $product){
echo "<table width='100%' border='0' cellpadding='2' cellspacing='0'>
<tbody>
<tr valign='top'>
<td><h3><a href='' style='color: rgb(51, 102, 153); text-decoration: none;'>".$product->prod_name."</a></h3></td>
<td style='color: #ff0000; text-align: right;'>From: £".$product->prod_price_5."</td>
</tr>
<tr valign='top'>
<td colspan='2'><a href='' style='color: #CC6600; text-decoration: none;'>Click here for details and prices</a></td>
</tr>
<tr align='center' valign='middle'>
<td height='75' colspan='2'><a href='' title='".$product->prod_name."'><img width='100%' height='auto' src='http://thepensite.co.uk/wp-content/uploads/media-clic.jpg' class='prod-image' alt='".$product->prod_name."' srcset='http://thepensite.co.uk/wp-content/uploads/media-clic-300x33.jpg 300w, http://thepensite.co.uk/wp-content/uploads/media-clic.jpg 420w' sizes='(max-width: 420px) 100vw, 420px' /></a></td>
</tr>
</tbody>
</table>";
}
echo "</div>
</article>
</main>";
}
My issue is within these lines of code:
echo "<main class='content'>
<article class='page type-page status-publish entry' itemscope='' itemtype='http://schema.org/CreativeWork'>
<header class='entry-header'>
<h1 class='entry-title' itemprop='headline'>".$category->prod_cat_1."</h1>
</header>
<div class='entry-content' itemprop='text'>
<p>For more information on any product within our ".$category->prod_cat_1." range please click on "details and prices".</p>";
For some reason the category name is not been outputted, as I said before I have tried quite a few solutions I've found but they haven't worked, so I'm obviously doing some thing totally wrong.
Can any of you out there help?
Many thanks in advance.
Use $category[0]->prod_cat_1 you are not accessing the array value correctly. [0] is key here
EDIT:
Do print("<pre>".print_r($category,true)."</pre>"); after your query and look how are you getting the results.
In all likelihood, you are not accessing what you got back from the query properly. I have to guess a bit because you have not posted enough information to be certain.
Suggestion #1:
Add your table definition to the question so I can see what columns you have.
Suggestion #2: dump the data
foreach($category as $product){
var_dump($category); // <--- add this
Edit your question and post the output.
I am assuming that you are looking for html structure that is a table with all your rows inside the table. The way you have made your loop, you will end up with a table for each product.
Is this what you want?
table
product
product
product
This is what your code will produce:
table
product
table
product
table
product
I am creating a diabetes management system for a university project. One of the features of this system is for the patient to be able to send latest glucose readings and for the nurse to be able to login and comment on those readings.
I have been able to code the patient feature, however I wish to add a comment button in the comments column, which when clicked, brings up a popup window or a textbox for the nurse to be able to comment on that specific record. If a comment has not already been entered, an empty box should come up, however if there has been a previously entered comment, it should be displayed in the box to be updated and sent back to the mysql database. I would like to ask if someone could give me a way to include this comment box and code for the existing value to be displayed in the box and if there is no existing comment, then a new comment can be entered and stored in the database.
Below is my php code.
<?php//run query
$result = mysql_query($GetReadings);
?>
<table>
<tr>
<th>Date</th>
<th>Time</th>
<th>Glucose Level</th>
<th>SBP</th>
<th>DBP</th>
<th>Comments</th>
</tr>
<?php
//display results
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<tr>
<td><?php echo $row["Date"]; ?> </td>
<td><?php echo $row["Time"]; ?> </td>
<td><?php echo $row["GlucoseLevel"]; ?> </td>
<td><?php echo $row["SBP"]; ?> </td>
<td><?php echo $row["DBP"]; ?> </td>
<td><?php echo $row["Comments"];
<?php
//if statement to add comment link if user is a nurse
if ($_SESSION['User_level'] == 2)
{
//code for comments
}
?> </td>
</tr>
<?php
//end of while loop
}
?>
Hope I haven't missed out any crucial information.
Use the javascript function :
window.open(URL, windowName[, windowFeatures])
Where, URL - desired URL to display a page containing Textbox, use any window name you want.
Echo <a> or button with a onclick event eg:
Add Comment
Edit
The most basic way to achieve is, echo a <div></div> containing the past comments, the text box for new comments and Send/Cancel buttons. The trick is to set the display:none style property of that div. You the following code a guideline :
Echo the following code if the User has right user level.
Show Comments
<div id="comment-<?php echo $row['id']?>" style="display:none">
//display previous comments
<form method="post" action="addComment.php?id=<?php echo $row['id']?>">
<textarea name="comment"></textarea>
<input type="submit" value="Add Comment" /><input type="button" onclick="hideComment('<?php echo $row['id']?>')">
</form>
</div>
<script type="text/javascript">
function hideComment(id) {
document.getElementById('comment-' + id).style.display = 'none';
}
function showComment(id) {
document.getElementById('comment-' + id).style.display = 'block';
}
</script>
I am using this fantastic example of a jQuery editable invoice as a template for creating dynamic invoices for my users.
It's working quite well and I am successfully generating the items but I now need to save the values entered into the various text fields and enter them into the MySQL database.
I am confident in doing the MySQL entering with PHP but what makes this trickier is that the amount of 'invoice items' is completely dynamic and I am unsure how I can get PHP to 'check' through the pages text fields and find new ones, group them and then add them to my DB.
Here is an example of my code that I am using to generate the items:
<?php if($invoice_items->result_array()) { ?>
<?php foreach($invoice_items->result_array() as $invoice_Row): ?>
<tr class="item-row">
<td class="item-name">
<div class="delete-wpr">
<textarea><?php echo $invoice_Row['item_name']; ?> Facility Booking</textarea>
<a class="delete" href="javascript:;" title="Remove row">X</a>
</div>
</td>
<td class="description">
<textarea><?php echo $invoice_Row['description']; ?></textarea>
</td>
<td><textarea class="cost">$<?php echo $invoice_Row['hourly_cost']; ?>.00</textarea></td>
<td><textarea class="qty"><?php echo $total_time_hours; ?></textarea></td>
<td><span class="price">$<?php $unit_total = $invoice_Row['hourly_cost']* $total_time_hours; echo $unit_total;?>.00</span></td>
</tr>
<?php endforeach; ?>
<?php } ?>
I am thinking that I need to perhaps generate unique ID's for each invoice items text field, ie item-1-desc, item-1-cost etc, but that involves writing javascript which I know almost nothing about. Also I would still have to get PHP to loop through the ID's somehow until it reached the end...
If anyone has attempted something similar before or you can see a solution to my problem I would greatly appreciate your help.
Thanks,
Tim
Use the php form array syntax name="item-desc[<?php echo $id?>]"
You can then iterate them on the backend with foreach to store the data. You have the id's as keys to the arrays so it should be fairly trivial to update the db.