Jump to content

guymclarenza

Members
  • Posts

    53
  • Joined

  • Last visited

Contact Methods

  • Website URL
    https://imagimedia.co.za

Profile Information

  • Gender
    Male
  • Location
    Nelspruit, South Africa
  • Interests
    Travel, Bikes, Cars, Books, Learning, Wood, Dad stuff
  • Age
    55

guymclarenza's Achievements

Regular Member

Regular Member (3/5)

2

Reputation

2

Community Answers

  1. 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.
  2. 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.
  3. 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]);
  4. foreach ($table as $table) is the line that contains the faq variable in the code, I replaced it with table to anonymise my code.
  5. 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.
  6. Should I keep this thread open if I have more questions? or should I start a new thread for my next issues?
  7. 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.
  8. 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...
  9. 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.
  10. I haven't tested yet, It was a general question about coding practice. Is it as simple as not looping it?
  11. 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"]; } }
  12. The problems as I see them are as follows. It crawls a page, gets links, then has to discard duplicates, I think the hold up is there. I am removing duplicates after fixing the url, maybe it would be better to strip out all duplicates before "fixing" the url. To get 50 results, it is crawling and doing the whole process on 50 pages Does this make sense. follow links. add links to array remove duplicates fix links echo links repeat at present the logic is follow links fix links remove duplicates echo links repeat
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.