Practical Web Development by Unknown
Author:Unknown
Language: eng
Format: mobi, epub
Publisher: Packt Publishing
Fetching the result
Now, if we typed in everything correctly—at first you may have mistakenly omitted one of the semicolons on either side of the closing single quote—MySQL will have returned the title and price of every single book in our table. It has done so by returning an object that we named $result, which we can apply a few methods to.
The simplest one will give us the number of rows that were found, the most powerful one being fetch_assoc(), which will create for us an associative array that we can instantly use in a while loop. So, here is how we can generate an HTML table with a list of all book titles and prices with just a few lines of code:
<?php $numbooks = $result->num_rows; $htmlstring = '<table><thead><tr><th>Book title</th><th>Price</th></tr></thead><tbody>'; while ($row = $result->fetch_assoc()) { $htmlstring .= '<tr><td>'.$row['title'].'</td><td>'.$row['price'].'</td></tr>'; } $htmlstring .= '</tbody></table>'; echo $htmlstring; ?>
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Brazilian Economy since the Great Financial Crisis of 20072008 by Philip Arestis Carolina Troncoso Baltar & Daniela Magalhães Prates(121592)
International Integration of the Brazilian Economy by Elias C. Grivoyannis(91512)
The Art of Coaching by Elena Aguilar(52951)
Flexible Working by Dale Gemma;(23254)
How to Stop Living Paycheck to Paycheck by Avery Breyer(19638)
The Acquirer's Multiple: How the Billionaire Contrarians of Deep Value Beat the Market by Tobias Carlisle(12241)
Thinking, Fast and Slow by Kahneman Daniel(12080)
The Radium Girls by Kate Moore(11927)
The Art of Thinking Clearly by Rolf Dobelli(10229)
Hit Refresh by Satya Nadella(9040)
The Compound Effect by Darren Hardy(8814)
Tools of Titans by Timothy Ferriss(8222)
Atomic Habits: Tiny Changes, Remarkable Results by James Clear(8188)
Turbulence by E. J. Noyes(7940)
A Court of Wings and Ruin by Sarah J. Maas(7653)
Change Your Questions, Change Your Life by Marilee Adams(7637)
Nudge - Improving Decisions about Health, Wealth, and Happiness by Thaler Sunstein(7622)
How to Be a Bawse: A Guide to Conquering Life by Lilly Singh(7394)
Win Bigly by Scott Adams(7095)