Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/15/2021 in all areas

  1. If you want to use silly names like that with the "." at the end then you need the column name inside backticks. SELECT `KNr.` FROM .... From MySQL manual
    1 point
  2. I personally like leaving the HTML on the page itself as I like doing HTML/CSS mock-ups then just adding to the PHP to the HTML. For example - <main> <?php foreach ($cms as $record) { ?> <article class="cms"> <img class="article_image" src="<?php echo htmlspecialchars($record['image_path']); ?>" <?= getimagesize($record['image_path'])[3] ?> alt="article image"> <h2><?= $record['heading'] ?></h2> <span class="author_style">Created by <?= $record['author'] ?> on <time datetime="<?= htmlspecialchars(CMS::styleTime($record['date_added'])) ?>"><?= htmlspecialchars(CMS::styleDate($record['date_added'])) ?></time></span> <p><?= nl2br($record['content']) ?></p> <?php echo (isset($_SESSION['id'])) ? '<a class="editButton" href="edit.php?id= ' . urldecode($record['id']) . '">Record ' . urldecode($record['id']) . '</a>' : null; ?> </article> <?php } $url = 'index.php'; echo $pagination->new_page_links($url); ?> </main> I have a Database Object class An example (not the whole code) - namespace Techshangri; use mysql_xdevapi\Exception; use PDO; use PDOException; class DatabaseObject // The Parent Class: { static protected string $table = ""; // Overridden by the calling class: static protected array $db_columns = []; // Overridden by the calling class: static protected array $objects = []; static protected array $params = []; static protected $searchItem; static protected $searchValue; /* * Pagination static function/method to limit * the number of records per page. This is * useful for tables that contain a lot of * records (data). */ public static function page($perPage, $offset, $loc = 'index'): array { $sql = 'SELECT * FROM ' . static::$table . ' WHERE page=:page ORDER BY date_added DESC LIMIT :perPage OFFSET :blogOffset'; $stmt = Database::pdo()->prepare($sql); // Prepare the query: $stmt->execute(['perPage' => $perPage, 'blogOffset' => $offset, 'page' => $loc]); // Execute the query with the supplied data: return $stmt->fetchAll(PDO::FETCH_ASSOC); } // more code... and I have a Children's class that is more specific: Children's Class (CMS.php) - Example - class CMS extends DatabaseObject { protected static string $table = "cms"; // Table Name: static protected array $db_columns = ['id', 'user_id', 'thumb_path', 'image_path', 'Model', 'ExposureTime', 'Aperture', 'ISO', 'FocalLength', 'author', 'heading', 'content', 'data_updated', 'date_added']; public $id; public $user_id; public $page; public $thumb_path; public $image_path; public $Model; public $ExposureTime; public $Aperture; public $ISO; public $FocalLength; public $author; public $heading; public $content; public $date_updated; public $date_added; /* * Construct the data for the CMS */ public function __construct($args = []) { // $this->user_id = $args['user_id'] ?? null; // $this->author = $args['author'] ?? null; // $this->heading = $args['heading'] ?? null; // $this->content = $args['content'] ?? null; // $this->date_updated = $args['date_updated'] ?? null; // $this->date_added = $args['date_added'] ?? null; // Caution: allows private/protected properties to be set foreach ($args as $k => $v) { if (property_exists($this, $k)) { $v = static::filterwords($v); $this->$k = $v; static::$params[$k] = $v; static::$objects[] = $v; } } } // End of construct method: public static function styleTime($prettyDate): string { try { $dateStylized = new DateTime($prettyDate, new DateTimeZone("America/Detroit")); } catch (Exception $e) { } return $dateStylized->format("Y-m-d H:i:s"); } // more code... I use Active Record Design Pattern as for what I do doesn't get too complex and besides I'm starting to like this pattern. However, if I was doing a really large website I would go more the route of Model-View-Controller pattern. Well, at least I think I would? Anyways, I getting off topic and my point is that after struggling with OOP for awhile, I found out by doing tutorials and looking at examples is to keep your methods and even you classes as short as possible, plus try to have meaning to them that is helpful to you as the coder. The real benefit now is that I can transfer these classes over to other projects (websites) with no problem and that is when I find out if I have written a class that could had been written better. As I sometimes find myself getting a little carried away with a class or putting a method (or even the variables) in the wrong class. I always shoot myself when I do that when come to that realization. 🤣 Everyone codes differently, but that is my logic.
    1 point
  3. Is visitor a custom role? As a Wordpress user is generally only assigned one role, can you not simply do something like: #only show content to specific roles $user = wp_get_current_user(); if ( $user == 'subscriber' || $user == 'visitor' ){ // adsense code }
    1 point
  4. 1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • 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.