php - Retrieving data from a database -
I have a database designated product, and I want to use PHP data from the database, I have never php Have done First of all, I have tried to use information from other answers in this forum, but still got stuck. Any help is appreciated
I have used the code of Nenja Admov and it worked well.
Here is the code to connect with the database and get the results:
1. DB Connection
& lt? Php $ host = "localhost"; $ Username = "your_username"; $ Password = "your_password"; $ Db_name = "your_db_name"; $ Connection = mysql_connect ($ host, $ username, $ password) or die ("Error :: [1]"); Mysql_select_db ($ db_name, $ connection) or die ("Error :: [2]"); ? & Gt;
Wrap the code above "db_conn.inc", and later if you want to do something with the database (update / insert / read), just include 'em' db_conn.inc ' ;
2. Get results.
& lt? Includes Php ('db_conn.inc'); $ Query = "selection` id`,` name '`' mytable`"; // query ... $ result = mysql_query ($ query, $ connection); // If request a query ($ result) {// If any results near the result print '& lt; Table & gt; & Lt; TR & gt; & Lt; TD & gt; Id & lt; / TD & gt; & Lt; TD & gt; Name & lt; / TD & gt; & Lt; / Tr> '; While ($ line = mysql_fetch_array ($ result)) {Print '& lt; Tr> & lt; Td> . $ Line [0] '& lt; / TD & gt; & Lt; TD & gt; '. $ Line [1] '& lt; / TD & gt; & Lt; / TR & gt; '; }} Print '& lt; / Table & gt; '; Mysql_close ($ connection); // Close connection? & Gt;
are accepted as upvote / this reply as if you feel free to solve your problem.
Comments
Post a Comment