Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAdam Smallman
4,182 PointsCreating a Searchable Databse for website use
Hi guys! I have been playing around with an idea for about 2 years now very simple in theory!
Website opens with a search bar, user can search search bar gives back pages that correspond with the search.
I don't think there is any need to go into to much detail haha!
I am now comfortable with HTML, CSS, etc to start or rather start learning new skill to create this project!
I understand that a Database would be needed. Would the video tutorials be the best start? Using MySQL etc.
Start to finish, would that lead to a searchable data base for a website?
Thank you so much guys!
I think using this project would be great to get started in MySQL.
3 Answers
Dave Evans
13,160 PointsAll you really need to do is create a MySQL query on the DB table based on the input data from the user's search input. You obviously need to connect to the db, but below is an example of what could be done:
<?php
$search = $_POST["search"];
$query = "SELECT * FROM `whatever-table` WHERE `something`='$search'";
$result = mysql_query($query) or die (mysql_error());
if($result) {
while($row = mysql_fetch_row($result)) {
echo $row[0],$row[1],$row[2];
}
} else {
echo "No result";
}
?>
<form action="search.php" method="post">
<input type="text" name="search"><br>
<input type="submit">
</form>
Andrew Chappell
12,782 PointsDo the Database foundations course first and then learn either Rails or PHP.
Adam Smallman
4,182 PointsThats great thank you!
I am going to continue for the PhP then move onto mySQL
Steven Crowe
4,483 PointsSteven Crowe
4,483 PointsPHP Development is available in tracks, it goes as for as search functions but not with MySQL Database, I am wanting to connect a search with a db as well.