-
Posts
64 -
Joined
-
Last visited
Everything posted by guymclarenza
-
weird problem with dates on calendar
guymclarenza replied to guymclarenza's topic in PHP Coding Help
Fixed -
I have a problem here, this script works with the exception of showing the correct days with the date Result can be seen at https://centurionphotographer.co.za/booking/ AI just gives me one different problem after another and I am not a good enough coder to solve the problem. // Number of months to display $monthsToShow = 3; // Get the current date and time $currentDate = date('Y-m-d'); // Calculate the start and end dates for the calendar $startDate = date('Y-m-d', strtotime($currentDate)); $endDate = date('Y-m-d', strtotime($currentDate . ' + ' . ($monthsToShow * 30) . ' days')); // Prepare the SQL statement to retrieve availability $availabilityQuery = $pdo->prepare(" SELECT avdate, COUNT(*) AS available_slots FROM availability WHERE avdate BETWEEN :start_date AND :end_date GROUP BY avdate "); // Prepare the SQL statement to retrieve bookings $bookingsQuery = $pdo->prepare(" SELECT bkdate, COUNT(*) AS booked_slots FROM bookings WHERE bkdate BETWEEN :start_date AND :end_date GROUP BY bkdate "); // Generate the calendar $currentMonth = ''; echo '<table>'; // Loop through each day within the specified range for ($date = $startDate; $date <= $endDate; $date = date('Y-m-d', strtotime($date . ' + 1 day'))) { $currentMonthOfDate = date('F Y', strtotime($date)); $dayOfWeek = date('w', strtotime($date)); // Check if a new month has started if ($currentMonth !== $currentMonthOfDate) { $currentMonth = $currentMonthOfDate; echo '<tr><th colspan="7">' . $currentMonth . '</th></tr>'; echo '<tr><th>Sunday</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th></tr>'; } // Check availability for the current date $availabilityQuery->bindParam(':start_date', $date); $availabilityQuery->bindParam(':end_date', $date); $availabilityQuery->execute(); $availabilityResult = $availabilityQuery->fetchAll(PDO::FETCH_ASSOC); // Check bookings for the current date $bookingsQuery->bindParam(':start_date', $date); $bookingsQuery->bindParam(':end_date', $date); $bookingsQuery->execute(); $bookingsResult = $bookingsQuery->fetchAll(PDO::FETCH_ASSOC); // Determine the class to apply based on availability if ($availabilityResult && $availabilityResult[0]['available_slots'] > 0) { $class = 'available'; $link = '<a href="timeslots.php?date=' . $availabilityResult[0]['avdate'] . '">Check available timeslots</a>'; } elseif ($bookingsResult && $bookingsResult[0]['booked_slots'] > 0) { $class = 'fully-booked'; $link = 'Fully Booked'; } else { $class = 'unavailable'; $link = ''; } // Output the date with the appropriate class and link echo '<td class="' . $class . '">' . $date . '<br>' . $link . '</td>'; // Start a new row after Saturday if ($dayOfWeek == 6) { echo '</tr><tr>'; } } echo '</table>';
-
Count links on a page, sort them and grade them.
guymclarenza replied to guymclarenza's topic in PHP Coding Help
This function parses the input using an HTML 4 parser. The parsing rules of HTML 5, which is what modern web browsers use, are different. Depending on the input this might result in a different DOM structure. Therefore this function cannot be safely used for sanitizing HTML. As an example, some HTML elements will implicitly close a parent element when encountered. The rules for automatically closing parent elements differ between HTML 4 and HTML 5 and thus the resulting DOM structure that DOMDocument sees might be different from the DOM structure a web browser sees, possibly allowing an attacker to break the resulting HTML. Seems like that is not a fantastic option -
This function is not working but I need some addd info from the function, Assume $content is populated, I want to count outbound links, ie links going to another website and internal links those staying on the website but going to another page. I also want to list said links by outbount and internal with link text and url., It would also be nice if I could at the same time fail or pass link text if neccessary, If linktext is "click here" or something equally non descriptive it would be marked with a red cross, or green tick if good, Why is this not working? and how do I make the neccessary changes to the script to add the functionality function checkLinksForDescriptiveText($content) { // Example: Check links for descriptive link text preg_match_all('/<a [^>]*href=["\']([^"\']+)["\'][^>]*>([^<]+)<\/a>/i', $content, $links); $total_links = count($links[1]); $descriptive_links = 0; foreach ($links[2] as $linkText) { $linkText = strip_tags($linkText); if (strlen($linkText) > 0 && strlen($linkText) < 50) { $descriptive_links++; } } return [$total_links, $descriptive_links]; }
-
Code doesn't crash but gives no result
guymclarenza replied to guymclarenza's topic in PHP Coding Help
Thank You, now lets see if I can make the next thing work. -
I am an amateur php coder at best, yet I muddle through and make stuff work mostly, So this is not crashing, but all I am getting as an answer is the header and my this is not working, what am I doing wrong here? The fact that it is not throwing up an error is already a win, I have checked, $content exists. <?php function validateURL($url) { return filter_var($url, FILTER_VALIDATE_URL); } function fetchURLContent($url) { $content = @file_get_contents($url); return $content !== false ? $content : false; } function analyzePage($url) { $analysis = []; $url = validateURL($url); if ($url) { $content = fetchURLContent($url); if ($content !== false) { $analysis['page_size'] = getPageSize($content); //$analysis['page_speed'] = getPageSpeed($url); } } } function getPageSize($content) { // Example: Calculate and return the page size return number_format(strlen($content) / 1024, 2) . ' KB'; } /*function getPageSpeed($url) { // Example: Calculate and return the page load time $start_time = microtime(true); $content = fetchURLContent($url); $end_time = microtime(true); $load_time = ($end_time - $start_time) * 1000; return number_format($load_time, 2) . ' ms'; } function getPageRequests($content) { // Example: Count and return the number of page requests preg_match_all('/<img [^>]*src=["\']([^"\']+)["\']/i', $content, $images); return count($images[1]); } */ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $url = $_POST['url']; $analysis = analyzePage($url); if (isset($analysis['error'])) { echo "<p>Error: {$analysis['error']}</p>"; } else { // Output analysis results here... echo "<h1>Test</h1>"; foreach ($analysis as $key => $value) { echo "<p>$key: $value</p>"; } } echo "This shit is working but not"; } else { ?> <h1>Test</h1> <form method="post"> <label for="url">Enter URL: </label> <input type="text" name="url" id="url" required> <input type="submit" value="Analyze"> </form> <?php } ?>
-
Thanks to everyone that tried to help, I have been busy with my real job. Making wooden stuff. I found the solution and my site now works under php8.1, hopefully I never need to do this again unless I feel like making a change. If you want to see the site it's at DustFactory <? wasn't doing it, I had to make all instances <?php
-
Yje flowing block of text is the this.
-
$sqli= $pdo->query("SELECT * FROM pages WHERE page_website='".$site."' ORDER by page_id ASC LIMIT 0,1"); while ($rowi = $sqli->fetch()) { $bid=$rowi["page_id"]; $img=$rowi["page_img"]; $imga=$rowi["page_imgalt"]; $title=$rowi["page_title"]; $pge=$rowi["page_text"]; $pint=$rowi["page_intro"]; $ptop=$rowi["page_banner"]; $pvid=$rowi["page_video"]; $tags=$rowi["page_tags"]; $metadesc=$rowi["page_desc"]; $ontology=$rowi["page_onto"]; $ontodesc=$rowi["page_ontodesc"]; } Gives me this as a result on page. In my limited understanding it would seem that pdo->query no longer gives the desired results in php8. This works in php7. I seem to be too stupid to find why this is. Can anyone point me in the right direction please.
-
Thank you
-
I have a working website that I need to upgrade to php 8 or whatever is latest, Is there some kind of script or app that can be used to check my existing script and tell me what is breaking it? Alternatively, where can I see a list of deprecated tags that need to be changed to become compliant. I am not a beginner but I don't do php full time, my main job is making stuff with wood.
-
How to reuse data from SQL in a class.
guymclarenza replied to guymclarenza's topic in PHP Coding Help
public function getFaq($site) { $sql = "SELECT faq_cats.faqc_name, faqs.faq_id, faqs.faq_question, faqs.faq_answer FROM faq_cats INNER JOIN faqs ON faq_cats.faqc_id = faqs.faq_cat WHERE faq_cats.faqc_site = ? ORDER BY faq_cats.faqc_name"; $stmt = $this->connect()->prepare($sql); $stmt->execute([$site]); $fcid = $stmt->fetchAll(); $fhead = null; $findex = null; $fcont = null; echo "<h1>FAQ Index</h1>"; foreach ($fcid as $faq) { $fname = $faq["faqc_name"]; $fquest = $faq["faq_question"]; $fans = $faq["faq_answer"]; $faid = $faq["faq_id"]; if ($fhead != $fname) { $findex .= "<h2>".$fname."</h2>"; } $findex .= "<a href=\"#".$faid."\">".$fquest."</a><br />"; $fhead = $fname; } foreach ($fcid as $faq) { $fname = $faq["faqc_name"]; $fquest = $faq["faq_question"]; $fans = $faq["faq_answer"]; $faid = $faq["faq_id"]; $fcont .= "<a name=\"".$faid."\"></a>".$fquest."<br />".$fans."<br /><br />"; } echo $findex; echo "<br /><br />"; echo $fcont; } } $faqob = new getData(); $faqob->getFaq($site); Is there a shorter or more concise way of doing this? The result looks like this FAQ Index DNA Testing FAQs What should I do with unexpected DNA results? How can I learn more about DNA and how to use it? What should I consider before testing my DNA? What is DNA? Genealogy FAQs What is the difference between my family tree and my genetic tree? What types of DNA are tested for ancestry purposes? Paternity Test FAQs How do I receive my results? How long do I have to wait for my paternity test results? How long will the paternity test take? How is the paternity test done? If the mother is deceased or does not want to come, what can we do? Does the mother have to be present? What should I do with unexpected DNA results? If you receive unexpected results, such as the identity of parents, grandparents, great-grandparents, or other previously unknown relatives, be sensitive and considerate of others involved who may be affected by the results. Approach family members with c How can I learn more about DNA and how to use it? Consider these resources in learning more about DNA and how you can use it effectively in your own family history activities: ISOGG Wiki—The International Society of Genetic Genealogists has created and maintains a wiki (community written encyclopedia) What should I consider before testing my DNA? DNA test results may reveal unexpected information about your family history, such as adoptions, unexpected paternity, etc. The affected party may be yourself or a close DNA relative—perhaps someone you know nothing about. If this new information may be u What is DNA? DNA, or deoxyribonucleic acid, is the genetic code that defines each person’s biological characteristics. DNA is chains of four individual nucleotide links, the sequence of which encode our genetic information. These strings of DNA are coiled into package What is the difference between my family tree and my genetic tree? Your family tree is what has been documented over time through family history records and often reflects relationships, some of which may not be biological. Your genetic tree consists of the relatives with whom you share DNA, which you mutually inherited What types of DNA are tested for ancestry purposes? DNA can provide information in different ways to help you identify your related family members and ancestors, depending on which part of the DNA molecule is used. Typically, four types of DNA are used to discover more about your ancestry: atDNA Autoso How do I receive my results? You have options to choose from that you indicate on the form How long do I have to wait for my paternity test results? Approximately 10-15 working days How long will the paternity test take? The test itself takes approximately 150 minutes How is the paternity test done? a Finger prick of the parties involved to collect a small blood sample If the mother is deceased or does not want to come, what can we do? If the mother is still alive but does not want to be present for the test, an affidavit is required explaining why she is not present. The affidavit must be brought with the other parties. If the mother is deceased, then the death certificate of the mo Does the mother have to be present? If the child is a minor (younger than 18 years), the mother needs to be present to sign consent for testing for the minor child. If the child is older than 18 years, the mother need not be present. -
How to reuse data from SQL in a class.
guymclarenza replied to guymclarenza's topic in PHP Coding Help
This does not work public function getFaq($site) { $sql = "SELECT faq_cats.faqc_name, faqs.faq_question, faqs.faq_answer FROM faq_cats INNER JOIN faqs ON faq_cats.faqc_id = faqs.faq_cat WHERE faq_cats.faqc_site = ? ORDER BY faq_cats.faqc_name"; $stmt = $this->connect()->prepare($sql); $stmt->execute([$site]); $fcid = $stmt->fetchAll(); $fhead = null; foreach ($fcid as $faq) { $fname = $faq["faqc_name"]; $fquest = $faq["faq_question"]; $fans = $faq["faq_answer"]; $fcont = null; if ($fhead != $fname) { $fcont .= "<h2>".$fname."</h2>"; } $fcont .= $fquest."<br />".$fans."<br /><br />"; $fhead = $fname; } } } $fcont; $faqob = new getData(); $faqob->getFaq($site); echo $fcont; This does Class GetData extends Dbh { public function getFaq($site) { $sql = "SELECT faq_cats.faqc_name, faqs.faq_question, faqs.faq_answer FROM faq_cats INNER JOIN faqs ON faq_cats.faqc_id = faqs.faq_cat WHERE faq_cats.faqc_site = ? ORDER BY faq_cats.faqc_name"; $stmt = $this->connect()->prepare($sql); $stmt->execute([$site]); $fcid = $stmt->fetchAll(); $fhead = null; foreach ($fcid as $faq) { $fname = $faq["faqc_name"]; $fquest = $faq["faq_question"]; $fans = $faq["faq_answer"]; $fcont = null; if ($fhead != $fname) { $fcont .= "<h2>".$fname."</h2>"; } $fcont .= $fquest."<br />".$fans."<br /><br />"; $fhead = $fname; echo $fcont; } } } $fcont; $faqob = new getData(); $faqob->getFaq($site); Can anyone tell me why and how to make the previous one work. -
I want to reuse the data from getFaq for different levels of a website. $fcid is the variable. Creating the full page in the getFaq function could work but limits the function to one set of results, Do I need to create a new function if I want to create another page with the data and a new call to the database? It seems to me there must be a way to store the array from $fcid and call it from another page to get a subset of the data. I added the getFP class as an attempt to do just that but I am getting no results. If I place the code in the getFP class in the getFAQ function the script works as envisioned. I want to create a getFAQpage, a getFAQheader and a getFAQsubset based on categories. The data is all there in $fcid but I have no idea on how to access it from outside the class. Dbh is the PDO connection. Class GetData extends Dbh { public function getFaq($site) { $sql = "SELECT faq_cats.faqc_name, faqs.faq_question, faqs.faq_answer FROM faq_cats INNER JOIN faqs ON faq_cats.faqc_id = faqs.faq_cat WHERE faq_cats.faqc_site = ? ORDER BY faq_cats.faqc_name"; $stmt = $this->connect()->prepare($sql); $stmt->execute([$site]); $fcid = $stmt->fetchAll(); return $fcid; } } Class getFP extends GetData { public function getFaqPage([$fcid]) { $fcid = $this->fcid; $fhead = null; foreach ($fcid as $faq) { $fname = $faq["faqc_name"]; $fquest = $faq["faq_question"]; $fans = $faq["faq_answer"]; if ($fhead != $fname) { echo "<h2>".$fname."</h2>"; } echo $fquest."<br />".$fans."<br /><br />"; $fhead = $fname; } } } $faqob = new getFP(); $faqob->getFaqPage([$fcid]);
-
Errors that make no sense to me. What am I doing wrong?
guymclarenza replied to guymclarenza's topic in PHP Coding Help
Thank you kind sirs, -
Errors that make no sense to me. What am I doing wrong?
guymclarenza replied to guymclarenza's topic in PHP Coding Help
foreach ($table as $table) is the line that contains the faq variable in the code, I replaced it with table to anonymise my code. -
I am testing some new code, trying to learn me some OOP. I know the SQL works because I tested it in phpmyadmin. There is something wrong and I cannot fathom why, <? $site= '15'; Class Dbh { private $user='xxx'; private $pass='xxx'; private $db='xxx'; private $host='localhost'; private $charset = 'utf8mb4'; protected function connect() { $dsn = 'mysql:host='.$this->host.'; dbname='.$this->db.';charset='.$this->charset; $pdo = new PDO($dsn, $this->user, $this->pass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); return $pdo; } } Class GetData extends Dbh { public function gettable($site) { $sql = "SELECT table_cats.tablec_name, tables.table_question, tables.table_answer FROM table_cats INNER JOIN tables ON table_cats.tablec_id = tables.table_cat WHERE table_cats.tablec_site = ? ORDER BY table_cats.tablec_name"; $stmt = $this->connect()->prepare($sql); $stmt->execute($site); $fcid = $stmt->fetchAll(); foreach ($table as $table) { echo $table["tablec_name"]."<br /><br />"; echo $fquest = $table["table_question"]."<br /><br />"; echo $table["table_answer"]."<br /><br />"; } } } $tableob = new getData(); $tableob->gettable($site); The error messages I am getting are as follows [24-Feb-2021 06:02:34 UTC] PHP Warning: PDOStatement::execute() expects parameter 1 to be array, string given in /home/imagimediaco/public_html/entrepreneur.za.bz/faq.php on line 32 [24-Feb-2021 06:02:34 UTC] PHP Notice: Undefined variable: faq in /home/imagimediaco/public_html/entrepreneur.za.bz/faq.php on line 35 [24-Feb-2021 06:02:34 UTC] PHP Warning: Invalid argument supplied for foreach() in /home/imagimediaco/public_html/entrepreneur.za.bz/faq.php on line 35 Line 32 is this line. $stmt->execute($site); I suspect the faq variable is undefined because it's not being populated because it expects $site to be an array, Why is an array expected for $site? Please explain to me in simple terms, I can be a little stupid.
-
Ta very mooch
-
Should I keep this thread open if I have more questions? or should I start a new thread for my next issues?
-
I am able to order the rows by the field required $sql = "SELECT table_cats.tablec_name, tables.table_question, tables.table_answer FROM table_cats INNER JOIN tables ON table_cats.tablec_id = tables.table_cat WHERE table_cats.tablec_site = ? ORDER BY table_cats.tablec_name"; $stmt = $this->connect()->prepare($sql); $stmt->execute($site); $fcid = $stmt->fetchAll(); foreach ($table as $table) { $fcat = $table["tablec_name"]; $fquest = $table["table_question"]; $fans = $table["table_answer"]; } , My HTML is not too crap, been doing it for a while, CSS though has it's challenges but not quite as many as PHP while I am learning new stuff. Your help is appreciated, The SQL above gives me all the fields I require, so that is not an issue. Your guidance gives me what I want to use said results. As we say here in the Southern Tip of Africa, Siyabonga Gakulu Mlungu. or Thank you muchly Boss. I will fiddle and run some tests till it does what I want it to.
-
Just one more question, would it be better to use the loops on the page that is viewed or hide them in the functions? In the example above I have one row, In another I have multiple rows dependant on information from a different query. example. for each Get id, name from table idvar echo name Get field1, field2 from anothertable where field3 = idvar for each echo field1 and field 2 I am thinking that an SQL statement inner joining the two tables and grouping them by table.name may be a more elegant solution, yet I am not sure how not to repeat table.name on every iteration of anothertable.result Am I on the right track? The output should look like this table.name.1 anothertable.result.1 anothertable.result.2 anothertable.result.3 table.name.2 anothertable.result.1 anothertable.result.2 anothertable.result.3 etc...
-
Thank you, That was what I thought but was unsure about how to access the data without a loop. I am busy rebuilding an old package as OOP to improve it. The original works but I am concerned about security even though I have updated to PDO. I figure the more secure the better. It's just that sometimes this old brain of mine finds some concepts difficult.
-
I haven't tested yet, It was a general question about coding practice. Is it as simple as not looping it?
-
I know this function will get one result, I suspect foreach is the wrong loop to use, should I be using a loop at all? Can someone correct me please. public function getSites($site) { $sql = "SELECT * FROM website WHERE website_id = ?"; $stmt = $this->connect()->prepare($sql); $stmt->execute($site) $siten = $stmt->fetch(); foreach ($siten as $row) { $title = $row["website_title"]; $wname = $row["website_name"]; $image1 = "header.jpg"; $metadesc = $row["website_description"]; $wurl = $row["website_url"]; $gtag = $row["website_gtag"]; $gmap = $row["website_map"]; $wcss = $row["website_css"]; } }
-
busy looking at scrapy in python