How to Retrieve Data From MySQL in PHP With Breaks & Spaces
HTML has special encoding for spaces and line breaks. When you store these values in a database table, you must include them when you run MySQL queries from your PHP Web pages. You use these queries when you want to search for text in HTML format, so you can return the fully encoded string to the Web app.
Instructions
-
-
1
Right-click the PHP file you want to use to query MySQL. Click "Open With," then click your PHP editor.
-
2
Create the connection to the MySQL Server using pre-defined PHP connection functions. The following code connects to a DB named "WebDB" on the server "dbserver":
mysql_connect("dbserver", "user", "pass") or die(mysql_error());
mysql_select_db("WebDB");Replace these values with your own server, database, username and password.
-
-
3
Crete the query variable with breaks and space characters. The following code sets up a query that includes the HTML break character and space character:
$query = "select * from customer where name = 'joe smith <br>'";
The " " code indicates a space in HTML. The "<br>" is the "break" character.
-
4
Query the server. After you set up the query, use the variable to query MySQL. The following code queries the server:
$records= mysql_fetch_array( $query);
-
1