Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 29th, 2014, 04:38 PM
Registered User
 
Join Date: Jun 2013
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Exclamation Please Help in search query using php & mysql

hi,
i am having a problem in search query.
after entrering query in text field i get only value of one row.
he is da structure

Student table
Code:
********************************************************* 
student_id	    student_name	          student_course	           student_age
*********************************************************
1	                Alex	                          BIT	                      19
2	                Alex	                          SEO	                      24
3	                Najim	                         ADS	                      23
4	                Julius	                         ADS	                      21
5	               Timothy	                 MP                         23
6	                Alex	                         OS                         19
*********************************************************
here is form coding index.php

Code:
<form action="search.php" method="get">
  <label>Name:
  <input type="text" name="keyword" />
  </label>
  <input type="submit" value="Search" />
</form>
here is search.php

PHP Code:
<?php
include_once ("connection.php");
$queryitem trim($_GET['keyword']);
if(
$queryitem == "")
{
    echo 
"Enter name you are searching for.";
    exit();
}
$query "SELECT * FROM student WHERE student_name LIKE '%$queryitem%'";
$results mysql_query($query);
if(
mysql_num_rows($results) >= 1)
{
    
$output "";
    while(
$row mysql_fetch_array($results))
    {
        
$id $row['student_id'];
        
$name $row['student_name'];
        
$course $row['student_course'];
        
$age $row['student_age'];
    }
    
$output .=' '.$id.' <br /> '.$name.' <br /> '.$course.' <br /> '.$age.' ';
}
else
    
$output 'There was no matching record for the name  ' $queryitem ';
?>
<html>
<head>
</head>
<body>
<?php echo $output; ?>
</body>
</html>
here the problem occour
if i search for Alex ony one value is displaying like

1
Alex
BIT
19

please help

Last edited by farwall.ghost; January 29th, 2014 at 04:44 PM.. Reason: wrong typed





Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql & php connection problem. Manu Sharma PHP Databases 2 March 2nd, 2007 07:03 AM
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 10:57 AM
search in PHP/MySQL lanc71 MySQL 0 March 4th, 2006 08:10 PM
PHP & MySQL d-dubu MySQL 2 January 14th, 2005 01:32 PM
How to script search form in PHP/MYSQL javabeans PHP How-To 0 January 12th, 2004 03:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.