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.