close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

I want to show the month name at the beginning of each month, along with the products

Thread began 1/14/2020 9:19 am by Jonas | Last modified 1/16/2020 9:10 am by Ray Borduin | 768 views | 10 replies |

Jonas

I want to show the month name at the beginning of each month, along with the products

I have a result page from a product database, where I want to list the products in date order. I also want to show the month name at the beginning of each month. The table contains the following columns: ProductID, ProductMonth, ProductDate, ProductName. How do I write this query?

Sign in to reply to this post

Ray BorduinWebAssist

I don't really understand the question. I think the query would just be:

SELECT * FROM products ORDER BY ProductDate

Then just write the month name at the beginning of each month like:

php:
<?php

$lastMonth 
"";
?>
<?php
while (!$recordset->atEnd()) {
?>
<?php
if ($lastMonth != $recordset->getColumnVal("ProductMonth")) {
?>
<h2><?php echo($recordset->getColumnVal("ProductMonth")); ?></h2>
<?php
  $lastMonth 
$recordset->getColumnVal("ProductMonth");
}
?>
<!-- rest of your looped code here -->
Sign in to reply to this post
Did this help? Tips are appreciated...

Jonas

I think you understood! But I don't make it work. The page is empty (http error).
Attaches image to code and how it should look like (static code).

Attached Files
aktuella-provningar.php
Sign in to reply to this post

Ray BorduinWebAssist

Delete line 115 it is a repeat of line 109.

Then move line 114 up above line 107

Sign in to reply to this post
Did this help? Tips are appreciated...

Jonas

Thanks, now it's getting closer!
The name of the month is now displayed only for the first product within the same month.
But at the same time, it seems that this table row, with the month name - appears under all products - which is obviously not good.
The attached screen shows these lines that I marked with red color (in css).

How do I make this row appear only with the month name?

Attached Files
aktuella-provningar.php
Sign in to reply to this post

Ray BorduinWebAssist

You have:

php:
<?php if ($RSProvningar->getColumnVal("ProvningManad") !="") { ?><tr class="manadsnamn">

                  <td colspan="4" >
<?php if ($lastMonth != $RSProvningar->getColumnVal("ProvningManad")) { ?>
<h2><?php echo($RSProvningar->getColumnVal("ProvningManad")); ?></h2>
<?php $lastMonth $RSProvningar->getColumnVal("ProvningManad"); } ?>
                  </td>
                </tr> <?php ?>



You probably just want:

php:
<?php 

if ($lastMonth != $RSProvningar->getColumnVal("ProvningManad") && $RSProvningar->getColumnVal("ProvningManad") !="") { 
?>
<tr class="manadsnamn">
  <td colspan="4" >
<h2><?php echo($RSProvningar->getColumnVal("ProvningManad")); ?></h2>
  </td>
</tr>
<?php 
$lastMonth 
$RSProvningar->getColumnVal("ProvningManad"); 

?>
Sign in to reply to this post
Did this help? Tips are appreciated...

Jonas

You're right, as always. I learn new things all the time, thank you! One last question about this. Is it possible to make a separate table per month? See attached screenshot. Where the first line is the name of the month. The next line is the table head and then all the products for that month.

Attached Files
aktuella-provningar.php
Sign in to reply to this post

Ray BorduinWebAssist

Please attach a current copy of the page and I can help.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jonas

I've done that, can't you see it?

Sign in to reply to this post

Ray BorduinWebAssist

Try using this for your table:

php:
<?php $lastMonth "";?>

<?php
$wa_startindex 
0;
while(!
$RSProvningar->atEnd()) {
  
$wa_startindex $RSProvningar->Index;
?>
<?php 
if ($lastMonth != $RSProvningar->getColumnVal("ProvningManad") && $RSProvningar->getColumnVal("ProvningManad") !="") { ?>
<?php 
if (isset($tableShown)) {
echo(
"</tbody></table>");
}
$tableShown true;
?>
            <table class="table table-hover">
              <thead>
                <tr>
                  <th scope="col"><i class="far fa-calendar-alt"></i></th>
                  <th scope="col"><i class="fas fa-chair"></i></th>
                  <th scope="col"><i class="fas fa-wine-glass-alt"></i></th>
                  <th scope="col"><i class="fas fa-coins"></i></th>
                </tr>
              </thead>
      
              <tbody>
                <tr class="manadsnamn">
                    <td colspan="4">
                    <h2><?php echo($RSProvningar->getColumnVal("ProvningManad")); ?></h2>
                    </td>
                </tr>
                <?php $lastMonth $RSProvningar->getColumnVal("ProvningManad");} ?>
                 
                  <tr class="text-black-50">
                    <td><?php echo($RSProvningar->getColumnVal("Dayname")); ?> <?php echo($RSProvningar->getColumnVal("Day")); ?> <?php echo($RSProvningar->getColumnVal("Month")); ?></td>
                    <td><?php echo($RSProvningar->getColumnVal("ProvningPlatser")); ?> st</td>
                    <td><?php echo($RSProvningar->getColumnVal("Kategorier_KategoriNamn")); ?></td>
                    <td><?php echo($RSProvningar->getColumnVal("KategoriPrisklass")); ?></td>
                  </tr>
<?php 
if (1==0) {
  
?>
          </tbody>
        </table>
<?php
}
?>
                  <?php
  $RSProvningar
->moveNext();
}
$RSProvningar->moveFirst(); //return RS to first record
unset($wa_startindex);
unset(
$wa_repeatcount);
?>
<?php 
if (isset($tableShown)) {
echo(
"</tbody></table>");
}
?>
Sign in to reply to this post
Did this help? Tips are appreciated...
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...