Jump to content

mactron

Members
  • Content Count

    13
  • Joined

  • Last visited

Community Reputation

0 Neutral

About mactron

  • Rank
    Member
  1. Try $msg = "<script type="text/javascript"> $(document).ready(function(){ demo.initChartist(); $.notify({ icon: 'pe-7s-gift', message: 'TESTING!' },{ type: 'info', timer: 4000 }); }); JS; print '<script>'.msg.'</script>'; P.S. Your code is not safe. Use PDO instead MySQLi.
  2. Hello, I have a table with people and some details insde. So, my question is if my MySQL architecture down below is good or not. Should I devide the table into two tables and kept only p_id, p_name and p_slug inside my table (people_tbl). Thank you! p = person p_description = bio p_category = occupation (people_category_tbl) people_tbl +------+---------+---------+---------------+-------------+-------------------+-----------+------------+---------+ | p_id | p_name | p_title | p_description | p_seo_title | p_seo_description | p_country | p_category | p_slug | +------+---------+---------+---------------+-------------+-------------------+-----------+------------+---------+ | 1 | John Li | title | johns bio | 70 charsets | 170 charsets | Germany | 1 | john-li | | 2 | Bob Stu | title | bobs bio | 70 charsets | 170 charsets | Italy | 2 | bob-stu | +------+---------+---------+---------------+-------------+-------------------+-----------+------------+---------+
  3. persons_tbl person_id | person_name | person_surname | person_description | person_slug -----------+--------------+-------------------+--------------------+------------- 1 | John | Doe | bla bla bla | john-doe 1 | Jane | Doe | bla bla bla | jane-doe 2 | Greg | Stue | bla bla bla | greg-stue -----------+--------------+----------------+--------------------+------------- persons_web_tbl person_web_id | person_web_linkedin | person_web_twitter | person_web_facebook | person_web_website | person_id ---------------+----------------------+--------------------+---------------------+--------------------+--------- 1 | linkedin.com/john | twitter.com/john | facebook.com/john | www.johndoe.com | 1 1 | linkedin.com/jane | twitter.com/jane | facebook.com/jane | www.janedoe.com | 2 2 | linkedin.com/greg | twitter.com/greg | facebook.com/greg | NULL | 3
  4. persons_web_tbl will look something like that person_web_id | person_web_linkedin | person_web_twitter | person_web_facebook | person_web_website | person_id
  5. From form ... I have two person tables, both get data from forms. I just added $person_web_twitter = "add something" and echo "found"; to test the class.. table 1 -> table person_tbl as an index of all people. table 2 -> persons_web_tbl where I will store people's links such as websites, twitter & facebook profiles. So, that's wrong approach?
  6. Hi! I wrote a small function that check if person_id already exist in the table called persons_web_tbl. If the person_id exist I get a message otherwise I add twitter/facebook profile of that person. I'm just trying to prevent duplicated entries this way. I will get person_id from table person_tbl, where are all people saved. The function actually works, I'm just curious if I'm on the right path. Thanks! $person_id = 11; class test extends dbh{ public function personExist($person_id) { $sql = "SELECT person_id FROM persons_web_tbl WHERE person_id = ?"; $stmt = $this->conn->prepare($sql); $stmt->execute([$person_id]); $row = $stmt->fetchColumn(); if ($row > 0){ echo "found"; }else { $person_web_twitter = "add something"; $sql = "INSERT INTO persons_web_tbl (person_web_twitter, person_id) VALUES (?, ?)"; $stmt = $this->conn->prepare($sql); $stmt->execute([$person_web_twitter, $person_id]); } } } $person = new test (); $person = $person->personExist($person_id);
  7. Your code works, but I don't have a clue with how many connections. Thanks!
  8. Hi, is this correct way? I'm on the right path? Thanks! class PostsData extends dbh{ private $conn; public function __construct() { $this->conn = new dbh(); $this->conn = $this->conn->connect(); } public function getPosts() { $sql = "SELECT * FROM posts_tbl"; $stmt = $this->connect()->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll((PDO::FETCH_OBJ)); return $result; } public function addPost($filter_author, $filter_title, $filter_txt) { $sql = "INSERT INTO posts_tbl (post_author, post_title, post_txt) VALUES (?, ?, ?, ?)"; $stmt = $this->connect()->prepare($sql); $stmt->execute([$filter_author, $filter_title, $filter_txt]); } } $post = new PostsData(); $posts = $post->getPosts(); foreach ($posts as $post) { echo $post->post_title; }
  9. Honestly speaking I don't know how to use this function inside my class. Did I miss something? Is my code above completely wrong? Please note: The code works like a charm I just don't understand the concept of using function __construct(PDO $connection). Any advice is appreciated! Thanks!
  10. Hi! I'm new here I'm following an online course where we building CMS using OOP PHP and PDO. I read some articles and watched a few youtube tutorials and to be honest, I'm pretty confused. Some of the developers suggest using function __construct(PDO $connection) inside the class. Their code looks something like that: private PDO $connection; function __construct(PDO $connection) { $this->connection = $connection; connect.php class dbh{ private $host = "localhost"; private $user = "root"; private $pwd = ""; private $dbname = "cms"; protected function connect() { $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname; $pdo = new PDO ($dsn, $this->user, $this->pwd); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); return $pdo; } } function.php // not a whole code class CategoriesData extends dbh{ public function getAllCategories() { $sql = "SELECT * FROM categories_tbl"; $stmt = $this->connect()->query($sql); while ($row = $stmt->fetch()){ echo $row['category_name'] . '<br>'; } } public function getCategoryName() { $sql = "SELECT category_name FROM categories_tbl"; $stmt = $this->connect()->prepare($sql); $stmt->execute(); $category = $stmt->fetch(PDO::FETCH_OBJ); if($category == null) { return null; }else { return $category->category_name; } } public function getCategoryDetials() { $sql = "SELECT * FROM categories_tbl"; $stmt = $this->connect()->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll((PDO::FETCH_OBJ)); return $result; } public function addCategory ($filter_name, $filter_title, $filter_description, $filter_slug) { $sql = "INSERT INTO categories_tbl (category_name, category_title, category_description, category_slug) VALUES (?, ?, ?, ?)"; $stmt = $this->connect()->prepare($sql); $stmt->execute([$filter_name, $filter_title, $filter_description, $filter_slug]); } public function deleteCategory($delete_category_id) { $sql = "DELETE FROM categories_tbl WHERE category_id = ?"; $stmt = $this->connect()->prepare($sql); $stmt->execute([$delete_category_id]); } } }
×
×
  • 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.