Hai All i want a code that fetches a row in a sql database named student and display the result in a table format.........i am a newbie in php................please Help me

Recommended Answers

All 8 Replies

$string = ("select * from table where field = "studentname"); // EDIT HERE and specify your table and field and studentname for the SQL query
$query = mysql_query($string)
or die (mysql_error());

$query = mysql_query($string) or die (mysql_error());
$result = mysql_fetch_array($query);
if($result==true)
{
do 
{
	echo "<table><tr>";
	echo "<td>".$result[nameofsqlcolumn]."</td>";
	echo "</tr></table>";
    
}while($result = mysql_fetch_array($query));
}
?>

this should work but will need tweeking to match your connection etc

Brother Can I Get A Full Version OF this I am a newbie

I have table named "student" in database named "shahaz" and there are three i items in the row named "Reg","Name","Marks" and what i want is that a searching script which when we enter the "Register No:" It should show all the other details in that row like "Name" and "Marks"...........It should be more useful if you provide this to me Thanks................

$con=mysql_connect("servername", "username", "password");//'localhost','root',''
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("shahaz", $con);
$string = ("select * from student where Reg= '$Register No'); 
$query = mysql_query($string)
or die (mysql_error());

$query = mysql_query($string) or die (mysql_error());
$result = mysql_fetch_array($query);
if($result==true)
{
do 
{
	echo "<table><tr>";
	echo "<td>".$result['Name']."</td>";
echo "<td>".$result['Marks']."</td>";
	echo "</tr></table>";
    
}while($result = mysql_fetch_array($query));
}
?>

How Can I Make A Search Tabe With Button................

see this link

or

see this code

<h2>Search</h2> <form name="search" method="post" action="<?=$PHP_SELF?>"> Seach for: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="fname">First Name</option> <Option VALUE="lname">Last Name</option> <Option VALUE="info">Profile</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form>

Can You Please Mix All These Together For Me I have database named"shahaz" Table named"shahaz" ang the table contains three rows named "Reg","Name" and "Marks" and wat i want to do is that wen some one enters a register no that is stored in "Reg" I want display The "Name" and "Result" In a Tabular Form Please Help Me............Thanks

Perhaps you should make a bit of effort on this yourself? So far all I have seen is "gimme code" posts and no code of your own.

save this code with name search.htm
code is :

<h2>Search</h2> <form name="search" method="post" action="search.php"> Seach for: <input type="text" name="find" /> in <Select NAME="search" size="1"> <Option VALUE="rn" selected>Registration
    No.</option> <Option VALUE="name">Name</option> <Option VALUE="marks">Marks</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="b1" value="Search" /> </form>

AND make a SECOND FILE search.php

and put this code on this file :

<?php

$search=$_POST['search'];


echo "$search";

$con=mysql_connect("servername", "username", "password");//'localhost','root',''

if (!$con)  {  die('Could not connect: ' . mysql_error());  } 

 mysql_select_db("data", $con);


switch ($search)

{

case "rn":

$string = ("select * from student where Reg= '$search');

 $query = mysql_query($string)or die (mysql_error());

 $query = mysql_query($string) or die (mysql_error());

$result = mysql_fetch_array($query);

if($result==true){

do

 {	echo "<table><tr>";

	echo "<td>".$result['Reg']."</td>";
echo "<td>".$result['Name']."</td>";

echo "<td>".$result['Marks']."</td>";

	echo "</tr></table>"; 

}while($result = mysql_fetch_array($query));}


break;


case "name":

$string = ("select * from student where name= '$search');

 $query = mysql_query($string)or die (mysql_error());

 $query = mysql_query($string) or die (mysql_error());

$result = mysql_fetch_array($query);

if($result==true){

do

 {	echo "<table><tr>";

	echo "<td>".$result['Reg']."</td>";
echo "<td>".$result['Name']."</td>";

echo "<td>".$result['Marks']."</td>";

	echo "</tr></table>"; 

}while($result = mysql_fetch_array($query));}


break;

case "marks":
$string = ("select * from student where marks= '$search');

 $query = mysql_query($string)or die (mysql_error());

 $query = mysql_query($string) or die (mysql_error());

$result = mysql_fetch_array($query);

if($result==true){

do

 {	echo "<table><tr>";

	echo "<td>".$result['Reg']."</td>";
echo "<td>".$result['Name']."</td>";

echo "<td>".$result['Marks']."</td>";

	echo "</tr></table>"; 

}while($result = mysql_fetch_array($query));}


break;
}

?>
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.