First of all this is a crazy thing I have just done.. so please sit back and read the whole post.............. Today I finished my math final and decided to learn a new programming language..... MYSQL. So I was able make my way to http://www.freewebmasterhelp.com/tutorials/phpmysql using Google I followed most of the tutorial and got the database setup... up until part 4; Everything works great and now I am just curious that how can I make a small page called search.php in which I can make a small search box. and have only one result display from the MySQL?
desiguru
0
Junior Poster in Training
Recommended Answers
Jump to PostCreate a html form like this:
<form action="search.php" method="post"> <input type="text" name="search"><br> <input type="submit"> </form>
search.php
<?php $search = "%" . $_POST["search"] . "%"; mysql_connect ("localhost", "myuser", "mypassword"); mysql_select_db ("mydatabase"); $query = "SELECT mycolumn FROM mytable WHERE mycolumn LIKE '$search'"; $result = mysql_query ($query); …
Jump to Postif ($result) { while ($row = mysql_fetch_array ($result)) { foreach ($row as $key => $value) { echo "$key = $value<br>"; } echo "<hr>"; } }
All 5 Replies
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
desiguru
0
Junior Poster in Training
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
homienick
0
Newbie Poster
SheSaidImaPregy
28
Veteran Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.