Found 4219 Articles for MySQLi

How can we handle NULL values stored in a MySQL table by using PHP script?

Srinivas Gorla
Updated on 22-Jun-2020 14:09:52

286 Views

We can use the if...else condition in PHP script to prepare a query based on the NULL value. To illustrate it we are having the following example −ExampleIn this example, we are using the table named ‘tcount_tbl’ having the following data −mysql> SELECT * from tcount_tbl; +-----------------+----------------+ | tutorial_author | tutorial_count | +-----------------+----------------+ |      mahran     |       20       | |      mahnaz     |      NULL      | |       Jen       |      NULL      | |      Gill       |       20       | +-----------------+----------------+ 4 rows in set (0.00 sec)Now, the following is a PHP script that takes the value of ‘tutorial_count’ from outside and compares it with the value available in the field.

How to write PHP script by using MySQL JOINS inside it to join two MySQL tables?

mkotla
Updated on 22-Jun-2020 14:11:18

4K+ Views

We can use the syntax of MySQL JOIN for joining two tables into the PHP function – mysql_query(). This function is used to execute the SQL command and later another PHP function – mysql_fetch_array() can be used to fetch all the selected data.To illustrate it we are having the following example −ExampleIn this example, we are using two MySQL tables which have the following data −mysql> SELECT * FROM tcount_tbl; +-----------------+----------------+ | tutorial_author | tutorial_count | +-----------------+----------------+ | mahran          |      20        | | mahnaz          |     ... Read More

How to write PHP script by using ORDER BY clause inside it to sort the data of MySQL table?

Abhinanda Shri
Updated on 22-Jun-2020 14:18:23

178 Views

We can use the similar syntax of the ORDER BY clause into the PHP function – mysql_query(). This function is used to execute the SQL command and later another PHP function – mysql_fetch_array() can be used to fetch all the selected data.To illustrate it we are having the following example −ExampleIn this example, we are writing a PHP script that will return the result in descending order of the authors of the tutorial −

How to write PHP script by using LIKE clause inside it to match the data from MySQL table?

Giri Raju
Updated on 22-Jun-2020 14:17:26

280 Views

We can use the similar syntax of the WHERE...LIKE clause into the PHP function – mysql_query(). This function is used to execute the SQL command and later another PHP function – mysql_fetch_array() can be used to fetch all the selected data if the WHERE...LIKE clause is used along with the SELECT command.But if the WHERE...LIKE clause is being used with the DELETE or UPDATE command, then no further PHP function call is required.To illustrate it we are having the following example −ExampleIn this example, we are writing a PHP script that will return all the records from the table named ‘tutorial_tbl’ ... Read More

How can we create a MySQL view by selecting some range of values from a base table?

Kumar Varma
Updated on 22-Jun-2020 14:00:50

116 Views

As we know that MySQL BETWEEN operator can be used to select values from some range of values. We can use BETWEEN operator along with views to select some range of values from the base table. To understand this concept we are using the base table ‘student_info’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | Shimla     ... Read More

How can we create MySQL view by selecting data based on pattern matching from base table?

Arjun Thakur
Updated on 22-Jun-2020 14:19:38

97 Views

MySQL LIKE operator is used to select data based on pattern matching. Similarly, we can use LIKE operator with views to select particular data based on pattern matching from the base table. To understand this concept we are using the base table ‘student_info’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | Shimla     | Computers  | | 130  | ... Read More

How can we create a MySQL view with GROUP BY clause?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:21

2K+ Views

We can use GROUP BY to group values from a column, and, if we want, we can perform calculations on that column. You can use COUNT, SUM, AVG, etc., functions on the grouped column. To understand GROUP BY clause with views we are creating a view named ‘Info’ using the base table ‘Student_info’ having the following data − mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History ... Read More

How to write PHP script to delete data from an existing MySQL table?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

230 Views

We can use the SQL DELETE command with or without the WHERE CLAUSE into the PHP function – mysql_query(). This function will execute the SQL command in a similar way it is executed at the mysql> prompt. To illustrate it we are having the following example − Example In this example, we are writing a PHP script to delete a record from MySQL table named ‘tutorial_tbl’ whose tutorial_id as 3.

How to write PHP script to update an existing MySQL table?

Sreemaha
Updated on 22-Jun-2020 14:01:31

215 Views

We can use the SQL UPDATE command with or without the WHERE CLAUSE in the PHP function – mysql_query(). This function will execute the SQL command in a similar way it is executed at the mysql> prompt. To illustrate it we are having the following example −ExampleIn this example, we are writing a PHP script to update the field named tutorial_title for a record having turorial_id as 3.

How to write PHP script to fetch data, based on some conditions, from MySQL table?

varma
Updated on 22-Jun-2020 14:02:39

584 Views

If we want to fetch conditional data from MySQL table then we can write WHERE clause in SQL statement and use it with a PHP script. While writing the PHP script we can use PHP function mysql_query(). This function is used to execute the SQL command and later another PHP function mysql_fetch_array() can be used to fetch all the selected data. This function returns a row as an associative array, a numeric array, or both. This function returns FALSE if there are no more rows. To illustrate it we are having the following example −ExampleIn this example we are writing ... Read More

Advertisements