Selecting Data from the Database

Now I have some data in my database (I added a few more lines using the form), I want to display them on the page. Below the form code in index.php, I added the below…

<ul>
<?php
$sql = mysql_query("SELECT * FROM form_test");

while ($row = mysql_fetch_row($sql)) {
echo "<li>$row[0] $row[1]</li>";
}
?>
</ul>

This has now produced a list of all the entrys that are currently held within the database. I would now like to build that list into a menu that will take the user to an individual page to display the content on it’s own. In retrospect, had I planned to do this from the start, I would have added another column in the table called ‘title’ and used that for the menu. However, I didn’t so the row ID will have to do and just imagine it’s the title!!

<ul>
<?php
$sql = mysql_query("SELECT * FROM form_test");

while ($row = mysql_fetch_row($sql)) {
echo "<li><a href=\"results.php?id=$row[0]\">$row[0]</li>";
}
?>
</ul>

I now have a list on the screen with just the ID of the row going from 1 to 6, each as a hyperlink pointing at ‘results.php?id=’ and the id number. Fantastic! We’re getting somewhere! To build results.php, I’m going to use the $_GET[id] string, but before I do that I’m going to put it into it’s own variable of $id should I need to use it again on the page.

<?php
$id = $_GET[id];
$sql = mysql_query("SELECT * FROM form_test WHERE id=$id");

while ($row = mysql_fetch_row($sql)) {
echo "<h1>$id</h1><p>$row[1]</p>";
}
?>

Excellent! Now to work out what we’re going to do with this new knowledge…

Thursday, March 5th, 2009 Database Connection

TAGS: , , ,

No comments yet.

Leave a comment

fuck team five BIGGEST ASS CRAVING Ice La Fox outinpublic.com public invasion submit your bitch collegerules Hot tight pussy Gia Malone Brooke Banner assparade fat mature redhead Kat drills its gonna hurt tug jobs Bareblacking itsgonnahurt BIGGEST ASS CRAVING submit your bitch Medical Femdom facial fest collegerules Big Mouthfuls CIndia Summers publicinvasion public invasion camel toe publicinvasion VISCONTITRIPLETS rubs a huge cock Summer Bailey public invasion pussy licked tranny land ungloryhole milfsoup college rules Special Exercises public invasion Aiden Aspen Licking Dick And Ass publicinvasion Vince Ferelli milf lessons amazing blowjob GynoOrgasmVideos Roxy Love Nudesportvideos Aiden Aspen hazehim bait Bus Lesbiansportvideos porn star fucked hard great ass outinpublic MedicalFemdom submit your bitch shaved pussy hammered submityourbitch Gyno Orgasm Videos Blonde gets fucked hard NEXTDOORHOOKUPS sexy tit fuck publicnude Stephanie Cane Monsters Of Cock publicinvasion Special Examination Bang Bros Big tit fucked huge tits lesbian lover licks publicinvasion hazehim.com pussy pounded publicinvasion hazehim dildo drills her pussy outinpublic outinpublic Charmane Star itsgonnahurt.com public invasion collegerules lucky stud in a hot threesome submityourbitch milfsoup itsgonnahurt Big Mouthfuls GAy Cumshots Extrem submityourbitch hottest white girls Milf cravers CODYCUMMINGS natural perky tits college rules Redhead BBW outinpublic.com tight ass drilled collegerules.com VINTAGEGAYLOOPS sexy blonde petite Charmane Star public invasion NEXTDOORPASS evanrivers SpecialExercises Confession Of Married Man ungloryhole.com Latina pornstar pussy ungloryhole busty adventures outinpublic MALEDIGITAL collegerules tugjobs NEXTDOORBUDDIES natural beautiful tits bang pas out in public summer time milf trannyland collegerules.com Amy Reid outinpublic hazehim NEXTDOORMALE Nude sport videos tugjobs itsgonnahurt NEXTDOORPASS publicinvasion haze him SpecialExamination Lacey lounging TOMMYDXXX bangbus trannyland outinpublic.com Lesbian sport videos trannyland public invasion ungloryhole smacked those asses publicinvasion magical feet submityourbitch un glory hole collegerules.com haze him facialfest