<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mr.Crystal</title>
    <description>The latest articles on Forem by Mr.Crystal (@mrcrystal).</description>
    <link>https://forem.com/mrcrystal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1034232%2F60e467d4-838b-4658-b6a1-fdedf5492a60.jpeg</url>
      <title>Forem: Mr.Crystal</title>
      <link>https://forem.com/mrcrystal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mrcrystal"/>
    <language>en</language>
    <item>
      <title>Tags Input with Autocomplete using jQuery and PHP</title>
      <dc:creator>Mr.Crystal</dc:creator>
      <pubDate>Thu, 20 Apr 2023 17:34:13 +0000</pubDate>
      <link>https://forem.com/mrcrystal/tags-input-with-autocomplete-using-jquery-and-php-cch</link>
      <guid>https://forem.com/mrcrystal/tags-input-with-autocomplete-using-jquery-and-php-cch</guid>
      <description>&lt;p&gt;Tags are used to organize posts or articles on the website. Tags provide an effective way to group related posts and make it easier for the user to find relevant posts quickly. It also helps readers to get a brief idea about the post without reading the entire content. Tags are more like categories, but they can describe posts in more detail than categories. Generally, one category is assigned to a post, on other hand you can use multiple tags for a single post.&lt;/p&gt;

&lt;p&gt;The tags input field should be allowed to input multiple values separated by a specific separator. Mostly, the comma (,) is used as a separator for the multiple value’s input field. In this tutorial, we will show you how to create multiple tags input field using jQuery. You can build a user interface to manage tags with autocomplete feature using jQuery and PHP.&lt;/p&gt;

&lt;p&gt;The example code will integrate a text field to input multiple tags. Also, an autocomplete feature will be provided to display tag suggestions from the database under the input field while the user starts typing.&lt;/p&gt;

&lt;p&gt;Tags Input with jQuery&lt;br&gt;
In this code sample, we will use the TagsInput jQuery plugin to convert a simple text input field to the tag list input area and allow the user to input multiple tag values.&lt;/p&gt;

&lt;p&gt;The tag can be added by entering a comma (,).&lt;br&gt;
The tag can be removed by a cross icon (x).&lt;br&gt;
Define an HTML input field.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;input type="text" id="tags_input"&amp;gt;&lt;/code&gt;&lt;br&gt;
Include the jQuery and TagsInput library files.&lt;/p&gt;

&lt;p&gt;`&amp;lt;!-- Include jQuery library --&amp;gt;&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
Initialize the tagsInput plugin and specify the selector (#tags_input) to attach it to the input field.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;br&gt;
$('#tags_input').tagsInput();&lt;br&gt;
&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;br&gt;
Tags Input with Autocomplete using PHP and MySQL&lt;br&gt;
In the following example code snippet, we will show you how to add autocomplete feature to the tags input field using jQuery and PHP.&lt;/p&gt;

&lt;p&gt;Create Database Table:&lt;br&gt;
To store the autosuggestion tags data a table is required in the database. The following SQL creates a tags table with some basic fields in the MySQL database.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE&lt;/code&gt;tags&lt;code&gt;(&lt;br&gt;
&lt;/code&gt;id&lt;code&gt;int(11) NOT NULL AUTO_INCREMENT,&lt;br&gt;
&lt;/code&gt;name&lt;code&gt;varchar(100) COLLATE utf8_unicode_ci NOT NULL,&lt;br&gt;
&lt;/code&gt;status&lt;code&gt;tinyint(1) NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive',&lt;br&gt;
  PRIMARY KEY (&lt;/code&gt;id`)&lt;br&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;&lt;br&gt;
HTML Input Element:&lt;br&gt;
Create an input element with HTML.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
jQuery Library:&lt;br&gt;
jQuery library is required to use the TagsInput plugin.&lt;/p&gt;

&lt;p&gt;jQuery UI Library:&lt;br&gt;
To use autocomplete feature in tagsInput, the jQuery UI library is required. Include the jQuery UI library files first.&lt;/p&gt;



&lt;p&gt;tagsInput Plugin:&lt;br&gt;
Include the library files of the tagsInput jQuery plugin.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
Set server-side script URL in autocomplete_url option of the tagsInput() method.&lt;/p&gt;

&lt;p&gt;&amp;lt;br&amp;gt;
$(&amp;amp;#39;#tags_input&amp;amp;#39;).tagsInput({&amp;lt;br&amp;gt;
    &amp;amp;#39;autocomplete_url&amp;amp;#39;: &amp;amp;#39;fetchData.php&amp;amp;#39;,&amp;lt;br&amp;gt;
});&amp;lt;br&amp;gt;
&lt;code&gt;&lt;br&gt;
Fetch Autocomplete Tags from Database with PHP and MySQL (&lt;/code&gt;fetchData.php&lt;code&gt;):&lt;br&gt;
The &lt;/code&gt;fetchData.php&lt;code&gt; file is called by the &lt;/code&gt;tagsInput()` method to retrieve the tags from the server-side script based on the search term.&lt;/p&gt;

&lt;p&gt;Get the search term using the PHP $_GET method.&lt;br&gt;
Fetch the matched records from the database with PHP and MySQL.&lt;br&gt;
Return tags data as JSON encoded array using PHP &lt;code&gt;json_encode()&lt;/code&gt; function.&lt;br&gt;
`&amp;lt;?php &lt;/p&gt;

&lt;p&gt;// Database configuration &lt;br&gt;
$dbHost     = "localhost"; &lt;br&gt;
$dbUsername = "root"; &lt;br&gt;
$dbPassword = "root"; &lt;br&gt;
$dbName     = "codexworld"; &lt;/p&gt;

&lt;p&gt;// Create database connection &lt;br&gt;
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName); &lt;/p&gt;

&lt;p&gt;// Check connection &lt;br&gt;
if ($db-&amp;gt;connect_error) { &lt;br&gt;
    die("Connection failed: " . $db-&amp;gt;connect_error); &lt;br&gt;
} &lt;/p&gt;

&lt;p&gt;// Get search term &lt;br&gt;
$searchTerm = $_GET['term']; &lt;/p&gt;

&lt;p&gt;// Fetch matched data from the database &lt;br&gt;
$query = $db-&amp;gt;query("SELECT * FROM tags WHERE name LIKE '%".$searchTerm."%' AND status = 1 ORDER BY name ASC"); &lt;/p&gt;

&lt;p&gt;// Generate array with tags data &lt;br&gt;
$tagsData = array(); &lt;br&gt;
if($query-&amp;gt;num_rows &amp;gt; 0){ &lt;br&gt;
    while($row = $query-&amp;gt;fetch_assoc()){ &lt;br&gt;
        $data['id'] = $row['id']; &lt;br&gt;
        $data['value'] = $row['name']; &lt;br&gt;
        array_push($tagsData, $data); &lt;br&gt;
    } &lt;br&gt;
} &lt;/p&gt;

&lt;p&gt;// Return results as json encoded array &lt;br&gt;
echo json_encode($tagsData); &lt;/p&gt;

&lt;p&gt;?&amp;gt;`&lt;br&gt;
tagsInput Options&lt;br&gt;
Various configuration options are available to customize the tagsInput() functionality. Some useful options are given below.&lt;/p&gt;

&lt;p&gt;autocomplete_url – URL to fetch the autocomplete data&lt;br&gt;
autocomplete – Options and values for autocomplete data &lt;code&gt;({option: value, option: value})&lt;/code&gt;&lt;br&gt;
height – Height of the tags input area (100px)&lt;br&gt;
width – Width of the tags input area (300px)&lt;br&gt;
defaultText – Placeholder text for the input field (add a tag)&lt;br&gt;
onAddTag – A callback function that triggers when the tag is added&lt;br&gt;
onRemoveTag – A callback function that triggers when the tag is removed&lt;br&gt;
onChange – A callback function that triggers when the tag value is changed&lt;br&gt;
delimiter – Separator for a new tag ([‘,’,’;’] or a string with a single delimiter. Ex: ‘;’)&lt;br&gt;
removeWithBackspace – Remove tag by backspace (true)&lt;br&gt;
minChars – Minimum character limit (default, 0)&lt;br&gt;
maxChars – Maximum character limit (default, no limit)&lt;br&gt;
placeholderColor – Placeholder text color (default, #666666)&lt;br&gt;
Get Value of Input Tags with PHP&lt;br&gt;
Once the form is submitted, you can get the value of the tags input field using the $_POST method in PHP. The following example code snippet shows how to submit the form and get the tags input field’s value using PHP.&lt;/p&gt;

&lt;p&gt;HTML Form with Tags Input:&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;
&lt;br&gt;
    &amp;lt;!-- Input field --&amp;gt;&lt;br&gt;
    &lt;br&gt;
        Tags:&lt;br&gt;
        &lt;br&gt;
    
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- Submit button --&amp;gt;
&amp;lt;input type="submit" name="submit" value="Submit"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
`&lt;br&gt;
Get Value of Tags Input:&lt;br&gt;
After the form submission, use the $_POST method in PHP to retrieve the value from the tags input field.

&lt;p&gt;`if(isset($_POST['submit'])){ &lt;br&gt;
    $tags = $_POST['tags_input']; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo '&amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Selected Tags:&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; '.str_replace(',', '&amp;lt;br/&amp;gt;', $tags); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;br&gt;
Autocomplete Textbox with jQuery UI using PHP and MySQL&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Tags input with autocomplete feature is very useful for the tags management in post/product creation form. You can the example code to allow the user to input multiple tags and manage them easily. The autocomplete functionality helps to find relevant tags quickly and select from the pre-populated list. You can also get multiple values from the input fields and insert tags in the database with PHP and MySQL.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create Dynamic Image Slider with PHP and MySQL</title>
      <dc:creator>Mr.Crystal</dc:creator>
      <pubDate>Wed, 19 Apr 2023 19:58:35 +0000</pubDate>
      <link>https://forem.com/mrcrystal/create-dynamic-image-slider-with-php-and-mysql-330o</link>
      <guid>https://forem.com/mrcrystal/create-dynamic-image-slider-with-php-and-mysql-330o</guid>
      <description>&lt;p&gt;Image slider is mostly used to display banners or products on the web page. It helps to display multiple images or elements in the same section without taking up much space on the web page. The slider is a very useful component for the eCommerce website. You can use a carousel slider for multiple purposes in the web application, such as displaying featured products, offers, deals, and other important content.&lt;/p&gt;

&lt;p&gt;Generally, static images or text contents are used in the slider. But you need to edit and modify the file each time you wish to change or add new images in the slider. To overcome this issue, you can display the images dynamically in the slider. With the dynamic process, the images will be fetched from the database and displayed in the slider. You can change or add images easily from the database without editing the file manually.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will show you how to create dynamic image slider with jQuery using PHP and MySQL. The dynamic slider can be used to display images from the database with PHP and MySQL. You can use a dynamic slider to integrate the product slider in PHP with the database. There are various jQuery plugins are available to add slider feature to the webpage. We will use slick carousel slider plugin to create dynamic image slider with PHP and MySQL.&lt;/p&gt;

&lt;p&gt;Before getting started to make dynamic product slider with PHP, take a look at the file structure.&lt;/p&gt;

&lt;p&gt;dynamic_image_slider_with_php/&lt;br&gt;
├── dbConfig.php&lt;br&gt;
├── index.php&lt;br&gt;
├── slick/&lt;br&gt;
│   ├── slick.css&lt;br&gt;
│   └── slick.min.js&lt;br&gt;
├── images/&lt;br&gt;
├── js/&lt;br&gt;
│   └── jquery.min.js&lt;br&gt;
└── css/&lt;br&gt;
    └── style.css&lt;br&gt;
Create Database Table&lt;br&gt;
To store image file information a table needs to be created in the database. The following SQL creates an images table with some basic fields in the MySQL database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE `images` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `file_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `created` datetime NOT NULL DEFAULT current_timestamp(),
  `modifed` datetime NOT NULL DEFAULT current_timestamp(),
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you need to insert some data in the images table in the database which will be fetched from the database later in the script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO `images` (`id`, `file_name`, `title`, `created`, `modifed`, `status`) VALUES
(1, 'car-img-1.jpg', 'Demo Product 1', '2023-01-12 16:19:36', '2023-01-12 16:19:36', 1),
(2, 'car-img-2.jpg', 'Demo Product 2', '2023-01-12 16:19:53', '2023-01-12 16:19:53', 1),
(3, 'car-img-3.jpg', 'Demo Product 3', '2023-01-12 16:20:03', '2023-01-12 16:20:03', 1),
(4, 'car-img-4.jpg', 'Demo Product 4', '2023-01-12 16:20:11', '2023-01-12 16:20:11', 1),
(5, 'car-img-5.jpg', 'Demo Product 5', '2023-01-12 16:20:22', '2023-01-12 16:20:22', 1);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that: The respective image files must be placed in the images/ folder.&lt;/p&gt;

&lt;p&gt;Create Directory to Store Images&lt;br&gt;
A directory is required in the server to store the physical files. Create a folder named images/ to store the image files.&lt;/p&gt;

&lt;p&gt;Database Configuration (dbConfig.php)&lt;br&gt;
The dbConfig.php file is used to connect and select the database. Specify the database host ($dbHost), username ($dbUsername), password ($dbPassword), and name ($dbName) as per your MySQL database credentials.&lt;/p&gt;

&lt;p&gt;``&amp;lt;?php  &lt;/p&gt;

&lt;p&gt;// Database configuration&lt;br&gt;&lt;br&gt;
$dbHost     = "localhost";&lt;br&gt;&lt;br&gt;
$dbUsername = "root";&lt;br&gt;&lt;br&gt;
$dbPassword = "root";&lt;br&gt;&lt;br&gt;
$dbName     = "codexworld_db";  &lt;/p&gt;

&lt;p&gt;// Create database connection&lt;br&gt;&lt;br&gt;
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);  &lt;/p&gt;

&lt;p&gt;// Check connection&lt;br&gt;&lt;br&gt;
if ($db-&amp;gt;connect_error) {&lt;br&gt;&lt;br&gt;
    die("Connection failed: " . $db-&amp;gt;connect_error);&lt;br&gt;&lt;br&gt;
} &lt;/p&gt;

&lt;p&gt;?&amp;gt;``&lt;br&gt;
Dynamic Image Slider (index.php)&lt;br&gt;
The images and text contents are fetched from the database and added to the slick slider.&lt;/p&gt;

&lt;p&gt;jQuery Library:&lt;br&gt;
The slick.js library has a dependency on jQuery, include the jQuery library file first.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;br&gt;
Slick Carousel Plugin:&lt;br&gt;
The jQuery slick plugin is used to add slider feature in HTML, so, include the CSS and JS library files of the slick slider.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;!-- slick slider CSS library files --&amp;gt;&lt;br&gt;
&amp;lt;link rel="stylesheet" type="text/css" href="slick/slick.css"/&amp;gt;&lt;br&gt;
&amp;lt;link rel="stylesheet" type="text/css" href="slick/slick-theme.css"/&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;!-- slick slider JS library file --&amp;gt;&lt;br&gt;
&amp;lt;script type="text/javascript" src="slick/slick.min.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;br&gt;
Use the slick() method to initialize the slider and attach it to the HTML element.&lt;/p&gt;

&lt;p&gt;Specify the parent div class (.product-slider) as a selector to bind the slick slider.&lt;br&gt;
You can use some setting options to configure the slider as per the application requirement.&lt;br&gt;
&lt;code&gt;&amp;lt;script&amp;gt;&lt;br&gt;
$(document).ready(function(){&lt;br&gt;
    $('.product-slider').slick({&lt;br&gt;
        slidesToShow: 1,&lt;br&gt;
        slidesToScroll: 1,&lt;br&gt;
        dots: false,&lt;br&gt;
        infinite: true,&lt;br&gt;
        arrows: true&lt;br&gt;
    });&lt;br&gt;
});&lt;br&gt;
&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;br&gt;
Slider Element with Dynamic Images:&lt;br&gt;
The image and title are fetched from the database and listed to define slider markup.&lt;/p&gt;

&lt;p&gt;The data are retrieved from the database dynamically using PHP and MySQL.&lt;br&gt;
All the images and titles should be listed under the parent div (.product-slider) whose class is specified as a selector in the slick() method.&lt;br&gt;
`&lt;/p&gt;
&lt;br&gt;
    &amp;lt;?php &lt;br&gt;
    // Include database configuration file &lt;br&gt;
    require 'dbConfig.php'; 
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Retrieve images from the database 
$query = $db-&amp;gt;query("SELECT * FROM images WHERE status = 1"); 

if($query-&amp;gt;num_rows &amp;gt; 0){ 
    while($row = $query-&amp;gt;fetch_assoc()){ 
        $imageURL = 'images/'.$row["file_name"]; 
?&amp;gt;
    &amp;lt;div class="slide"&amp;gt;
        &amp;lt;img src="&amp;lt;?php echo $imageURL; ?&amp;gt;" alt="" /&amp;gt;
        &amp;lt;h6&amp;gt;&amp;lt;?php echo $row["title"]; ?&amp;gt;&amp;lt;/h6&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;?php } 
} ?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
`&lt;br&gt;
&lt;strong&gt;Testing&lt;/strong&gt;&lt;br&gt;
Now, if you open the index.php file on the browser, you’ll see a fully functional dynamic slider with the product image and title on the web page.

&lt;p&gt;dynamic-product-slider-with-php-mysql-codexworld&lt;br&gt;
Create Dynamic Image Gallery with Database PHP &amp;amp; MySQL&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
With this example script, we have tried to provide a step-by-step process to create dynamic slider in PHP with MySQL. You can use this dynamic responsive image slider component to build product slider in online shopping or eCommerce website. Here the slick plugin is used for the slider feature that can be configured or customized as per your needs.&lt;/p&gt;

</description>
      <category>jqurey</category>
      <category>carousel</category>
      <category>slider</category>
      <category>php</category>
    </item>
    <item>
      <title>OOP and FP</title>
      <dc:creator>Mr.Crystal</dc:creator>
      <pubDate>Sun, 16 Apr 2023 18:45:57 +0000</pubDate>
      <link>https://forem.com/mrcrystal/oop-and-fp-25gf</link>
      <guid>https://forem.com/mrcrystal/oop-and-fp-25gf</guid>
      <description>&lt;p&gt;OOP helps developers understanding complex system by modeling into real-world objects with properties and methods. By applying OOP developers can improve the reusability of code and easier to manage and understand the system.&lt;/p&gt;

&lt;p&gt;FP on the other hand, helps developers manage and control the access of data in which reduce the side-effect of having stateful objects like OOP.&lt;/p&gt;

&lt;p&gt;It is depend on the project requirement and individual code-style that OOP or FP should be the choice on the project.&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>oop</category>
      <category>mrcrystal</category>
    </item>
  </channel>
</rss>
