Please help me to write a PHP code for following .

i have name , address , loanno (unique) , fup as fields in my database loandata.

i want a screen in which i enter a loan number and it should search the loan no. in lonono and if data matches it should print name,address,fup of that loanno

I am a beginner in PHP . please help!!!

cossay commented: We help people solve their problems, we don;t just don't write codes for plople here. +0

Recommended Answers

All 6 Replies

Ok I can help. Let me see.

thanks .. waiting for ur post

<?php
	$host_name = "localhost";
	$user_name = "root";
	$password = "rootwdp";
	$db_name = "db_test";
	$con = mysql_connect($host_name,$user_name,$password);
	$db_select = mysql_select_db($db_name,$con);
	
	if(isset($_POST['selLoan']))
	{
		$qry = "SELECT `name`, `address`, `fup` FROM `table_name` WHERE `loanno` = '".$_POST['selLoan']."'";
		$res = mysql_fetch_array(mysql_query($qry));
	}
	$rows = mysql_query("SELECT `loanno` FROM `table_name`");
?>
<form method="post">
    <select name="selLoan" onChange="javascript:this.form.submit();">
        <option value="">Select Loan no</option>
        <?php while($row = mysql_fetch_array($rows)){ ?>
        <option value="<?php echo $row['loanno']; ?>" <?php if($_POST['selLoan'] == $row['loanno']) {?> selected="selected" <?php } ?>><?php echo $row['loanno']; ?></option>
    <?php } ?>
    </select>
</form>

<?php if(@mysql_num_rows(mysql_query($qry))){ ?>
<table border="0">
	<tr>
    	<td>Name : </td>	<td><?php echo $res['name']; ?></td>
	</tr>
    <tr>
        <td>Address : </td>	<td><?php echo $res['address']; ?></td>
	</tr>
    <tr>
        <td>FUP : </td>		<td><?php echo $res['fup']; ?></td>
    </tr>
</table>
<?php } ?>

You just have to change the
host_name
user_name
password
db_name
table_name in each query
AND THEN TRY MY CODE.
Ii may help you.
GOOD LUCK

You could do this with a simple search box, drop menu (in case you want to search by things other than just loan number) and then a select query. Finally echo everything.

This is all pretty beginner stuff. I found a tutorial here (http://www.designplace.org/scripts.php?page=1&c_id=25

I made a few small changes. The pagination to $PHP_SELF doesnt work properly, maybe someone else here could tell you why.

You need to make changes to code line 32, 35, & 39.

<form name="form" action="search_sample.php" method="get">
  <input type="text" name="q" />
  <input type="submit" name="Submit" value="Search" />
</form>
Now, enter the following PHP. Follow the PHP comments for what the script is doing, if you get stuck, tell us in the forums!

<?php

  // Get the search variable from URL

  $var = @$_GET['q'] ;
  $trimmed = trim($var); //trim whitespace from the stored variable

// rows to return
$limit=10; 

// check for an empty string and display a message.
if ($trimmed == "")
  {
  echo "<p>Please enter a search...</p>";
  exit;
  }

// check for a search parameter
if (!isset($var))
  {
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  }

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("localhost","username","password"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("databasename") or die("Unable to select database"); //select which database we're using

$field = 'firstname';
// Build SQL Query  
$query = "select * from tablename where $field like \"%$trimmed%\"  
  order by $field"; // EDIT HERE and specify your table and field names for the SQL query

 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);

// If we have no results, offer a google search as an alternative

if ($numrows == 0)
  {
  echo "<h4>Results</h4>";
  echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";

// google
 echo "<p><a href=\"http://www.google.com/search?q=" 
  . $trimmed . "\" target=\"_blank\" title=\"Look up 
  " . $trimmed . " on Google\">Click here</a> to try the 
  search on google</p>";
  }

// next determine if s has been passed to script, if not use 0
  if (empty($s)) {
  $s=0;
  }

// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "<p>You searched for: &quot;" . $var . "&quot;</p>";

// begin to show results set
echo "<h3>Results</h3>";
$count = 1 + $s ;

// now you can display the results returned
  while ($row= mysql_fetch_array($result)) {
  $title = $row["$field"];

  echo "$count.) &nbsp;$title <br>" ;
  $count++ ;
  }

$currPage = (($s/$limit) + 1);

//break before paging
  echo "<br />";

  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt; 
  Prev 10</a>&nbsp&nbsp;";
  }

// calculate number of pages needing links
  $pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

  if ($numrows%$limit) {
  // has remainder so add one page
  $pages++;
  }

// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

  // not last page so give NEXT link
  $news=$s+$limit;

  echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";
  }

$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";
  
?>

We don't solve people's problem for them here, we only help people solve their own problems. To help you do what you are trying to do, you must start something yourself so we can guide/help you where possible. Anyway, I will help you. If you are learning PHP, this means that you probably have some knowledge of HTMl, databases(MySQL), and some basics of the PHP scripting language. Simply combine the little you know of these languages and you are done, and don't hesitate to let us know if you encounter any problem.

commented: Exactly +3
commented: dude if u know it doesnt mean all people can get by knowing these coding ok? dont be selfish if u dont wanna help go and be busy helping other people in ur category +0

THANKS MAHAVEER , THANKS solvision U GUYS ARE REALLY HELPFUL I DID IT :)

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.