close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

please can you help (simple code)

Thread begun 1/01/2022 6:33 pm by yogastudents362523 | Last modified 1/03/2022 10:31 pm by Ray Borduin | 1824 views | 9 replies |

yogastudents362523

please can you help (simple code)

Hello,

I had been very much relying on re-using some old code from my previous project, but things have changed massively.
Here is the MySQL query code as built by DataAssist MySQLi extension.
The "Test" button in the extension says the query is valid. I am selecting all classes for the current month plus 4 ahead.

Since I am not sure if the issue is in my Select query or in the PHP, it is difficult to know what to do next.


<?php
$mySaturdayClasses = new WA_MySQLi_RS("mySaturdayClasses",$mysqli_workshops,1);
$mySaturdayClasses->setQuery("SELECT * FROM workshops.saturdayssundays WHERE (saturdayssundays.classdate BETWEEN (DATE_ADD(CURDATE(), INTERVAL 0 MONTH)) AND (DATE_ADD(CURDATE(), INTERVAL 5 MONTH))) AND (WEEKDAY(saturdayssundays.classdate)=5) ORDER BY saturdayssundays.classdate");
$mySaturdayClasses->execute();
?>

Then I try to create a simple while loop to print out the data. I gave up using the object approach when I couldn't get that to work. But this procedural approach is also not working.

while ($row = mysqli_fetch_array($mySaturdayClasses)) {
echo date('F', strtotime($row["classdate"])) ;
echo date('j', strtotime($row["classdate"])) ;
}

The last time I did all this PHP 5 was only about a year old, and was the exciting new thing.

I would very much appreciate a working example of an object approach so I can figure out what I am doing wrong, and then correct all my other coding that does not seem to be working under PHP 7. I believe PHP 8 is just about upon us!!

Thank you for your help once again,
KAB

Sign in to reply to this post

yogastudents362523

SEEMINGLY RESOLVED (Thank you)

Hello,

This recuperation stuff is not good for the mind.

I eventually sat back and figured out that I should gradually be able to put everything together entirely using your tools.

From a combination of your recordset "show if not empty"
your MySQLi etceteras,
and figuring my way around the PHP date formatting matters, I now have the following, which is working:

<p>testing webassist stuff in here</p>
<?php if ($myMondayCancellations->TotalRows > 0) { // Show if mysqli recordset not empty ?>
<?php } // Show if mysqli recordset not empty ?>
<?php
$wa_startindex = 0;
while(!$mySaturdayClasses->atEnd()) {
$wa_startindex = $mySaturdayClasses->Index;
?>


<?php echo date('F', strtotime($mySaturdayClasses->getColumnVal("classdate"))); // extracting month full name
echo (" ");
echo date('j', strtotime($mySaturdayClasses->getColumnVal("classdate"))); extracting date
?>
<?php
$mySaturdayClasses->moveNext();
}
$mySaturdayClasses->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>

Thank you,
KAB

Sign in to reply to this post

yogastudents362523

show region: three times anomaly?

Hello,

The following "show" region insists on a three times repetition when there are only in fact 2 times in the recordset; and I do not understand why:

<?php
$wa_startindex = 0;
while(!$myTuesdayCancellations->atEnd()) {
$wa_startindex = $myTuesdayCancellations->Index;
?>
display 3 times anomaly here<br>

<?php // echo date('M', strtotime($myTuesdayCancellations->getColumnVal("cancelleddate")));
// echo (" ");
// echo date('jS', strtotime($myTuesdayCancellations->getColumnVal("cancelleddate")));
?>

<?php
$myTuesdayCancellations->moveNext();
}
$myTuesdayCancellations->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>

This is the SELECT query that generates it:

<?php
$myTuesdayCancellations = new WA_MySQLi_RS("myTuesdayCancellations",$mysqli_workshops,0);
$myTuesdayCancellations->setQuery("SELECT * FROM workshops.cancellationdates WHERE (cancellationdates.cancelleddate BETWEEN (DATE_ADD(CURDATE(), INTERVAL 0 MONTH)) AND (DATE_ADD(CURDATE(), INTERVAL 5 MONTH))) AND (WEEKDAY(cancellationdates.cancelleddate)=1) ORDER BY cancellationdates.cancelleddate");
$myTuesdayCancellations->execute();
?>

The URL for the relevant page is in the private area.
Thank you.

Sign in to reply to this post

Ray BorduinWebAssist

I think the recordset must be returning 3 rows. Try running that SQL statement in phpMyAdmin and see how many results come back.

If you send me FTP details I can debug the page directly. I don't seem to have access to that site anymore.

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

yogastudents362523

Hello,

I have run that query in Navicat, and I get various (and correct) results according to the (WEEKDAY(cancellationdates.cancelleddate)=0) variable. I get 2 results on Monday (value = 0), 1 result on Tuesday (value = 1) and 1 result on Thursday (value = 3).

I have put the ftp details in the private area.

Thank you,
KAB

Sign in to reply to this post

yogastudents362523

Another anomaly
I am sorry, but I would like to add that the top of the page are 2 (of 5) queries that are NOT showing in the WebAssist MySQLi "show region" dialogue box.

The three queries:
$myMondayCancellations
$myTuesdayCancellations
and
$mySaturdayClasses
all display correctly as selectable options.

But
$myThursdayCancellations
$myFridayCancellations

do not.

I am happy to rebuild them when you are done, if necessary.

Thank you,
KAB

Sign in to reply to this post

Ray BorduinWebAssist

Your recordset code had some typos. That was probably causing both issues. I've fixed it. Please take a look and let me know if it is all working properly now.

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

yogastudents362523

Hi

Thank you, that all seems to be working now.
I will have to figure out how those queries got corrupted?
Maybe I did that when trying to adjust each individual weekday index?

I shall try to take more care.

Thank you again,
KAB.

Sign in to reply to this post

Ray BorduinWebAssist

It looks like you copied and pasted to create the recordsets and didn't update the recordset name in all of the lines properly, so some were referring to other recordset names.

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

yogastudents362523

Hi,

I have obviously not recovered nearly so well as I think I have.
I will have to work in shorter stretches.

Especially given that I am also watching videos to simultaneously learn more about object PHP, rather than the procedural I am used to from all those years ago.

Thank you again for the WebAssist videos you have provided.
KAB

Sign in to reply to this post
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...