Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-04-2011, 10:11 AM   PM User | #1
saranvarma
New to the CF scene

 
Join Date: Oct 2011
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
saranvarma is an unknown quantity at this point
help me regarding paging and search

<?php
error_reporting(0);
session_start();
if(isset($_SESSION['userName']))
{
echo "<style float='right'>".$_SESSION['userName']."</style>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" align="center" width="760">
<tr>
<td align="center" colspan="3"><h2> Welcome to <?=$_SESSION['userName']?></h2></td>
</tr>
<tr>
<td align="left" ><?="hello ".$_SESSION['userName']?></td>
<td align="right"><a href="index1.php">home</a>&nbsp&nbsp <a href="logout.php" >logout</a></td>
</tr>
<tr>
<td valign="top" align="left"><a href="index2.php">student management</a></td>
<td align="center">
<?
$con= mysql_connect("localhost","root","root");
if(!$con)
{
die("connection failed:".mysql_error());
}
mysql_select_db("saran",$con);

if($_POST['submit'] == 'Insert')
{
move_uploaded_file($_FILES["file"]["tmp_name"],"images/".$_FILES['file']['name']);
$query = "INSERT INTO `student` (`name` ,`marks`, `image`) VALUES ('".$_POST['name']."', '".$_POST['marks']."','".$_FILES['file']['name']."')";
mysql_query($query)or die(mysql_error());
header('Location: index2.php');
}
if($_POST['submit'] == 'Update')
{
if($_FILES['file']['name']==""||$_FILES['file']['name']=="null")
{
$query = "update student set name='".$_POST['name']."',marks=".$_POST['marks']." where id=".$_GET['id'] ;
mysql_query($query)or die(mysql_error());
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],"images/".$_FILES['file']['name']);
$query = "update student set name='".$_POST['name']."', marks=".$_POST['marks']." , image='".$_FILES['file']['name']."' where id=".$_GET['id'] ;
mysql_query($query)or die(mysql_error());

}
header('Location: index2.php');
}

if($_GET['action'] == 'delete')
{
mysql_query("DELETE FROM `student` WHERE `id` = ".$_GET['id'])or die(mysql_error());
header('Location:index2.php');
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function deletefunc(id)
{
var r=confirm("do you want to delete this record?");
if (r==true)
{
location.href="index2.php?action=delete&id="+id;
}
}
</script>
</head>
<body>
<? if(($_GET["action"] == 'edit') || ($_GET['action'] == 'insert')){

if($_GET["action"] == 'edit'){
$sql = mysql_query("SELECT * FROM student WHERE id =".$_GET['id']);
$sql_f = mysql_fetch_array($sql);
}
?>
<form action="" method="post" name="form2" enctype="multipart/form-data">
<table align="center">
<tr>
<td>name</td>
<td><input type="text" name="name" id="name" value="<?=$sql_f["name"]?>" /></td>
</tr>
<tr>
<td>marks</td>
<td><input type="text" name="marks" id="marks" value="<?=$sql_f["marks"]?>" /></td>

</tr>
<? if($_GET["action"] == 'edit'){ ?>
<tr>
<td colspan="2"><input type="file" id="file" name="file"/> </td>
</tr>
<tr>
<td><img src="images/<?=$sql_f["image"]?>" height="20" width="20"/></td>
<td colspan="2"><input type="submit" name="submit" value="Update" /></td>
</tr>
<? } ?>
<? if($_GET["action"] == 'insert'){ ?>
<tr>
<td colspan="2"><input type="file" id="file" name="file"></td>
<td colspan="2"><input type="submit" name="submit" value="Insert" /></td>
</tr>
<? } ?>
</table>
</form>
<? } else {

if(isset($_GET['sort']) and $sort=="asc"){
$sort="desc";
}else{$sort="asc";}
$result =mysql_query("SELECT * FROM `student` ORDER BY name $sort ");
?>

<form method="post" name="form1" action="">
<table align="center" border="2">
<tr>
<td>Id</td>
<td><a href='index2.php?sort=<?=$sort?>'>name</td>
<td>marks</td>
<td>image</td>
<td>Action</td>
</tr>
<?
while($rec = mysql_fetch_array($result)){
?>
<tr>
<td><?=$rec["id"]?></td>
<td><?=$rec["name"]?></td>
<td><?=$rec["marks"]?></td>
<td><img src="images/<?=$rec[image]?>" height="20" width="20"/></td>
<td><a href="index2.php?action=edit&id=<?=$rec["id"]?>" >Edit</a> &nbsp <a href="#" onclick="deletefunc(<?=$rec["id"]?>);">delete</a></td>
</tr>
<?
} ?>
<tr>
<td colspan="2"><a href="index2.php?action=insert">Insert</a></td>
</tr>
<? }
?>
</table>
</form>
</body>
</html>

</td>
</tr>
</table>
</form>
</td>
</tr>
</table>

</body>
</html>
how to add search box and paging for this code ? i know the logic but i dont know where to modify plz help me urgent
saranvarma is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:24 AM.


Advertisement
Log in to turn off these ads.