Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
Dear friends i have a table in phpmyadmin i write code to reterive all data from database when page load now i need to create a search ...
default all records should show but when i enter rownumber in search just the relate record should retrieve
Posted
Comments
Mohibur Rashid 9-Apr-15 19:07pm    
Your table is not in phpmyadmin, your table is in mysql. You should study more about select query

Muhammad i think you should look for "LIKE clause" and "WHERE clause", google it.

for example :
PHP
$q = strip_tags(trim($_GET['query']));
$sql = "SELECT id,name FROM customers WHERE name LIKE '%". $q ."%'"


This may help http://www.w3schools.com/sql/sql_like.asp[^]
 
Share this answer
 
v2
Comments
Muhammad Qasim Ludin 9-Apr-15 22:08pm    
brother there is a problem when i create the search its working correctly but the table is showing blank when i write keyword in search and after click its showing record i need by default in table should show data and also when i search another record should show
amin khoshzahmat 10-Apr-15 1:52am    
can you please paste your php code here?
If you are new to database driven web development, then first take a look at this CRUD with PHP and MySQLi using OOP Syntax[^].
Learn more about PHP MySQL Database[^]
For your question, you should be using either prepared statements or parameterized queries to prevent SQL-injection in PHP[^]
To use "Like" in the parameter,
prepare('SELECT * FROM tablename WHERE fieldname LIKE ?');
$stmt->bind_param('s', '%'.$searchkeyword.'%');
Read more about Everything you wanted to know about SQL[^]
Learn more about: PHP Prepared Statements[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900