/

Ticker

6/recent/ticker-posts

Advertisement

Responsive Advertisement

How to set limit to insert row in PHP and MySQL?

 Insert Limit in row in PHP and MySQL

In this tutorial you will learn if you are having an MySQL database and you want to set a limit that only 3 rows can be inserted in it how you can do it .

I am going to show only PHP code which is from my project 

How to set limit to insert row in PHP and MySQL


This is the PHP code - 





$check_table = "SELECT count(id) AS result from header_showcase";

$response_check_table = $db->query($check_table);

if($response_check_table){

    $data = $response_check_table->fetch_assoc();
    $count_rows = $data['result'];
    if($count_rows<3 db-="" store_data="INSERT INTO header_showcase( title_image, title_text, subtitle_text, title_color, subtitle_color, title_size, subtitle_size, h_align, v_align, buttons) VALUES ('$files_binary','$title','$subtitle','$title_color','$subtitle_color','$title_size','$subtitle_size','$h_align','$v_align','$button')" store_response="$reponse">query($store_data);
            if($store_response){
                echo "data is inserted";
            }
            else{
                echo "data is not inserted";
            }
    }
    else{
        echo "You can insert only 3 rows";
    }



 Explanation - 

 In this code we are putting count method in id and storing it in result variable  then we are fetching it using fetch_assoc() method retrieving the value of result and storing in count_row variable.

Now checking the row limit to insert row in MySQL.

Post a Comment

0 Comments