How to make Comment system using ChatView

Well first of all I would like to say Hi to everyone :slightly_smiling_face:
Now to move to topic.In this guide I will describe you to make comments system and managing it using your own Database.

What you will need

Here is a list of items/resources you will need before getting started…

How it looks from Designer

Sometimes ago on my one Guide when Aia file download link was not working then users asked for its Design so here is its design…

Components

Following have been used in making this comment system-

  • Button
  • TexBox
  • ChatView
  • Notifier
  • Web
  • Clock

Note:- If you want to show comments in ListView Image and Text then replace ChatView by it

Pre-added rows/tables

If you are continuing this guide then I assume you have created a Table named ‘Comments’ and four rows named as following-

  • Timestamp
  • Id
  • User
  • Comment

Blocks

Blocks are divided into three parts…

1.Save comment in database

blocks%20(64)
blocks%20(65)

2.Load comments from Datebase

blocks%20(67)

3.Load comments for specific ID

blocks%20(68)

Extras
‘runQuery’ Procedure:-


Thanks to @Taifun

Universal ‘Got Text’ event

Procedure to get ‘id’ for Chat View
blocks%20(71)

Screenshot/Testing

Thanks Peter for your avtar

Apk for testing

Comments.apk (5.1 MB)

Aia File

Here is Aia file download Link:-

Comments.aia (71.6 KB)

Liked my work

You can donate me here:

From Developer

As it is open source so everyone can contribute to this guide and improve it.
Also if you find any bug or have a query then post that here or message me(in personal case)

Thank you :slightly_smiling_face:

26 Likes

:grin::grin::grin::grin::grin::grin:

9 Likes

Awesome work.

1 Like

Goodwoork
But I already did this in my app​:star_struck:but normally…

1 Like

I simply stored comments in one cell in database and juth gave each post a different id.and work done!just load Comments according to id

MySql has more features than airtable.

4 Likes

that was awesome but complicated. Can you do that with airtable.& use split block to store more data in one row

1 Like

Actually airtable is easy to use but has less features than mysql.
But I will try.

2 Likes

Can you explained what’s the different Between airtable & mysql i mean advantage. I didn’t know.plz

Airtable database is the simplest way for making comments system like fb, YouTube. I made it comments with airtable.

Hi … i am using infinityfree hosting and i cant find the MySQL DataBase url and also key
please help me .

image
how to see this

Url is your site url while key is what you set in the php file.
For more information see this:

can you give an example

Hi , can you give me the php code file

You can find that here:

What You’ll Need

  1. Kodular Creator: Use it to design your app’s UI, including the ChatView component for displaying comments.
  2. Web Hosting: Use a hosting service like 000webhost to store and execute PHP scripts.
  3. PHP Script: This will handle communication between your app and the database (e.g., insert, retrieve, delete comments).
  4. Database: A MySQL database hosted on your web server to store the comments.

Steps to Create the Comment System

Step 1: Set Up the Backend

  1. Create a Database:
  • Log into your web hosting control panel and create a MySQL database.
  • Create a table for comments with fields like:

sql

Copy code

CREATE TABLE comments (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(100),
    comment TEXT,
    timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);
  1. Write PHP Scripts:
  • Insert Comment (insert_comment.php):

php

Copy code

<?php
$conn = new mysqli("your_host", "your_user", "your_password", "your_database");

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$username = $_POST['username'];
$comment = $_POST['comment'];

$sql = "INSERT INTO comments (username, comment) VALUES ('$username', '$comment')";

if ($conn->query($sql) === TRUE) {
    echo "Success";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>
  • Retrieve Comments (get_comments.php):

php

Copy code

<?php
$conn = new mysqli("your_host", "your_user", "your_password", "your_database");

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM comments ORDER BY timestamp DESC";
$result = $conn->query($sql);

$comments = array();
while ($row = $result->fetch_assoc()) {
    $comments[] = $row;
}

echo json_encode($comments);

$conn->close();
?>
  1. Upload the Scripts:
  • Use an FTP client or your hosting control panel to upload the PHP scripts to your server.

Step 2: Design the App in Kodular

  1. Add ChatView Component:
  • Drag the ChatView component onto your screen to display comments.
  1. Create Comment Input Form:
  • Add a TextBox for the user to input their comment.
  • Add a Button to submit the comment.

Step 3: Configure Kodular Logic

  1. Retrieve Comments:
  • Use the Web component to fetch data from get_comments.php.
  • On success, parse the JSON response and display comments in the ChatView:
    • Blocks:
      • Use Web.GotText to parse the JSON data.
      • Use ChatView.AddItem to display each comment.
  1. Submit Comment:
  • Use the Web component to send data to insert_comment.php when the button is clicked.
  • Pass the username and comment as POST parameters.
  • On success, refresh the comments list by re-calling get_comments.php.

Step 4: Test the System

  1. Insert Comments:
  • Test adding comments through the app and check if they appear in the ChatView and database.
  1. Retrieve Comments:
  • Ensure that comments are retrieved and displayed in real-time.
  1. Error Handling:
  • Add error messages for failed submissions or network issues.

Optional Enhancements

  • User Authentication:
    • Use a login system to associate comments with specific users.
  • Like/Reply System:
    • Add functionality to like or reply to specific comments.
  • Pagination:
    • Load comments in batches to improve performance with a large number of comments.