I need to get certain information out of a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jthemans
    New Member
    • Dec 2012
    • 2

    I need to get certain information out of a database

    Hello,

    I am working on something and it's a database with a list of book titles and years they have been published, I need to get the books that have been written for 1880 from the database only and with my code it shows all of the books with all the years, please help.

    My code:
    Code:
    		<?php
    					
    		$db = new PDO('mysql:host=localhost;dbname=boekenlijst','root','');
    		
    		$sql = "SELECT BoekNummer, Jaar, Titel FROM boeken";
    		$resultaat = $db->query($sql);
    		echo '<table border = 1>';
    		foreach($resultaat as $row) {
    		echo '<tr>';
    		$nummer = $row['BoekNummer'];	
    		echo '<td>'.$row['BoekNummer'].'</td>';
    		echo '<td>'.$row['Titel'].'</td>';
    		echo '<td>'.$row['Jaar'].'</td>';
    
    		}
    		echo '</table>';
    
    			
    		
    		$db= NULL;
    		
    		?>
    I am sorry that somethings are in an other language (dutch). Thanks in advance!

    PS: jaar = year, BoekNummer =ID in the database and title = title
    Last edited by jthemans; Dec 8 '12, 10:31 AM. Reason: Forgot something
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    You're going to want to use a WHERE clause so you can limit what gets returned. So your query:
    Code:
    $sql = "SELECT BoekNummer, Jaar, Titel FROM boeken";
    Should turn to:
    Code:
    $sql = "SELECT BoekNummer, Jaar, Titel FROM boeken WHERE jaar = '1880'";

    Comment

    Working...