SPACE(): to add space in Query


MySQL SPACE
SPACE Query takes integer N as argument.
SELECT SPACE (15)
We can add one start and end string to display the space between them
SELECT  '#', SPACE( 15 ) ,  '#' 
Output is here
#	             	#
We can use SPACE with our student table
SELECT  name , SPACE(10), class , mark, sex  FROM `student`
nameSPACE(10)classmarksex
John Deo Four75female
Max Ruin Three85male
Arnold Three100male
Krish Star Four60female
John Mike Four60female
Alex John Four55male

SPACE with UPDATE Query

We can add blank space to data in a Column by using update query
UPDATE student set name=CONCAT(space(5),name)
We added space before all names in our student table.

CONCAT to add string

Removing Space

To remove space from Left we can use LTRIM, to remove space from Right we can use RTRIM and to remove from both sides we can use TRIM

Read more on UPDATE Query

PHP Script

MySQLi database connection string

require "config.php";// Database connection
$query="SELECT  name , SPACE(10), class FROM `student`";
if ($result_set = $connection->query($query)) {
while($row = $result_set->fetch_array(MYSQLI_ASSOC)){
echo $row['name'],$row['SPACE(10)'],$row['class']."<br>";
}
 $result_set->close();
}



SQL String References elt(): String from the postion

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com

    Post your comments , suggestion , error , requirements etc here





    SQL Video Tutorials










    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer