How do I print out a single column from a row in my mysql database using php PDO.?
-
I have two pages, Index.php and insertcarbonate.php In my mysql I have a database called "drinks". In that database I have a table called "persons". In that table ...show more
-
Answer:
Use URL like insertcarbonate.php?fname=NAME with code like: <html> <?php /*** mysql hostname ***/ $hostname = 'localhost'; /*** mysql username ***/ $username = 'username'; /*** mysql ***/ $password = 'password'; try { $dbh = new PDO( "mysql:host=$hostname;dbname=drinks", $username, $password); /*** echo a message saying we have connected ***/ echo 'Connected to database' . "\n"; /*** The SQL SELECT statement ***/ $fname = $_GET['fname']; $STH = $dbh -> prepare( "SELECT * FROM persons WHERE fname LIKE '$fname'" ); $STH -> execute(); $result = $STH -> fetch(PDO::FETCH_OBJ); //1); print $result->fname . " " . $result->lname . " (" . $result->age . ")" ; } catch(PDOException $e) { echo $e->getMessage(); } ?> <head> </head> <body> <p><?php print $result ; ?></p> </body> </html>
KGAEITXCM5MSNYOFZBCOOFOX5A at Yahoo! Answers Visit the source
Related Q & A:
- How do I scroll to a certain widget in a QScrollArea?Best solution by Stack Overflow
- How do I print out a list of my contacts email addresses?Best solution by Yahoo! Answers
- How can I get into a graduate program without a stellar GPA?Best solution by answers.yahoo.com
- How can I print wirelessly from a laptop to a printer without a router?Best solution by answers.yahoo.com
- How do I print off a brochure on Open Office?Best solution by openoffice.blogs.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.