hi dear friends yesterday I asked about a teachers rating system but did not get any idea please help me. i am making a teacher rating system where i want to rate every teacher by making text boxes in front of the name of each teacher .the number that the user will add in text box for a specific teacher is to be added to a current rate of teacher.but the code is not working properly.when i add values through text boxes it adds the value from the last text box to all rows.for example for the first teacher i want to add 2 ,for the second i want to add 4 and for the 3rd teacher i want to rate 3. so instead of 2 and 3 all the rating of all teachers are incremented by 3.how to solve the problem?please help i am giving code of 2 pages m.php and n.php
m.php
<form action="n.php" method="post" enctype="multipart/form-data">
<table width="642" height="215" border="10" align="left" cellspacing="0" >
<tr>
<th class="style5">Teacher ID</th>
<th width="90" class="style5">Teacher Name</th>
<th width="127" class="style5">Teacher Registration</th>
<th width="135" class="style5">Teacher Qualification</th>
<th width="92" class="style5">Teacher Subject</th>
<th width="92" class="style5">Action</th>
</tr>
<?php
include 'conn.php';
$sql = "SELECT * FROM teacher ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_array()){
$id=$row['tid'];
?>
<tr>
<td height="50" align="center" class="style5"><?php echo $row['tid'];?></td>
<td align="center" class="style5"><?php echo $row['tname'];?></td>
<td align="center" class="style5"><?php echo $row['treg'];?></td>
<td align="center" class="style5"><?php echo $row['qualification'];?></td>
<td align="center" class="style5"><?php echo $row['subject'];?></td>
<td align="center"> <input type="text" name="rating">
</td>
</tr>
<?php
}
}else{
echo "<center><p><font size=10/> No Records</p></center>";
}
$conn->close();
?><tr><td colspan="6">
<input type="submit" name="submit" value="Enter"></td></tr>
</table>
</form>
n.php
<?php
mysql_connect("localhost","root","") or die ("couldnt connnect to server");
mysql_select_db("project") or die ("couldnt connnect to database");
include 'conn.php';
if(isset($_POST['submit']))
{
$sql = "SELECT * FROM teacher";
$result = $conn->query($sql);
if($result->num_rows > 0){
while($row = $result->fetch_array()){
$id=$row['tid'];
$newvalue=$_POST['rating'];
$sql_update="UPDATE teacher set hits = hits +$newvalue where tid=".$id."";
mysql_query($sql_update) or die(mysql_error());
header("location:m.php");
}
}
}
Like this ... give rating name array with id from table and update the record with the right value and id ... but never do this way for username and password case ...
<form action="n.php" method="post" enctype="multipart/form-data">
<table width="642" height="215" border="10" align="left" cellspacing="0" >
<tr>
<th class="style5">Teacher ID</th>
<th width="90" class="style5">Teacher Name</th>
<th width="127" class="style5">Teacher Registration</th>
<th width="135" class="style5">Teacher Qualification</th>
<th width="92" class="style5">Teacher Subject</th>
<th width="92" class="style5">Action</th>
</tr>
<?php
include 'conn.php';
$sql = "SELECT * FROM teacher ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_array()){
$id=$row['tid'];
?>
<tr>
<td height="50" align="center" class="style5"><?php echo $row['tid'];?></td>
<td align="center" class="style5"><?php echo $row['tname'];?></td>
<td align="center" class="style5"><?php echo $row['treg'];?></td>
<td align="center" class="style5"><?php echo $row['qualification'];?></td>
<td align="center" class="style5"><?php echo $row['subject'];?></td>
<td align="center"> <input type="text" name="rating[<?php echo $id; ?>]">
</td>
</tr>
<?php
}
}else{
echo "<center><p><font size=10/> No Records</p></center>";
}
$conn->close();
?><tr><td colspan="6">
<input type="submit" name="submit" value="Enter"></td></tr>
</table>
</form>
<?php
mysql_connect("localhost","root","") or die ("couldnt connnect to server");
mysql_select_db("project") or die ("couldnt connnect to database");
include 'conn.php';
if(isset($_POST['submit']))
{
$sql = "SELECT * FROM teacher";
$result = $conn->query($sql);
if($result->num_rows > 0){
while($row = $result->fetch_array()){
$id=$row['tid'];
$newvalue=$_POST['rating'];
if(isset($newvalue[$id])) {
$new_temp_value = $newvalue[$id];
$sql_update="UPDATE teacher set hits = hits +$new_temp_value where tid=".$id."";
mysql_query($sql_update) or die(mysql_error());
}
}
}
header("location:m.php");
}
Related
The code below works, but I want to change the months into names, such as "October", "November" and "December" using MONTHNAME. When I do, I get an error like the following:
JulyError in query: unknown column 'July' in 'where clause'.
What am I doing wrong?
<html>
<body>
<?php
$connection = mysql_connect('localhost','root','') or die ('unable to connect');
mysql_select_db("naurah")or die ("cannot select db");
$query = "SELECT YEAR(date) AS year, SUM(total) AS total FROM `order` GROUP BY year";
$result = mysql_query($query) or die ("Error in query:".mysql_error());
if (mysql_num_rows($result) > 0) {
while ($row=mysql_fetch_array($result)) {
echo $row[0];
$query1 = "SELECT * FROM `order` WHERE YEAR(date) = $row[0]";
$result1=mysql_query($query1) or die ("Error in query:".mysql_error());
if (mysql_num_rows($result1) > 0) {
echo '<table border="1" cellpadding="0" cellspacing="0" class="tg">
<strong>
<tr>
<th class="tg-031e">Order ID</th>
<th class="tg-031e" width="100">Date</th>
<th class="tg-031e">Name</th>
<th class="tg-031e">Email</th>
<th class="tg-031e" width="100">Telephone</th>
<th class="tg-031e">Address</th>
<th class="tg-031e">City</th>
<th class="tg-031e">Postcode</th>
<th class="tg-031e">State</th>
<th class="tg-031e">Reference No</th>
<th class="tg-031e">Total</th>
<th class="tg-031e">Order Status</th>
<th class="tg-031e">Postage</th>
<th class="tg-031e">Action</th>
</tr>
</strong>';
while ($row1 = mysql_fetch_array($result1)) {
echo "
<tr>
<td class=\"tg-4eph\" ><div align=\"center\"> $row1[0] </div></td>
<td class=\"tg-031e\" ><div align=\"center\"> $row1[1] </div></td>
<td class=\"tg-031e\" ><div align=\"center\">$row1[3] $row1[2]</div></td>
<td class=\"tg-4eph\" ><div align=\"center\"> $row1[4]</div></td>
<td class=\"tg-031e\" ><div align=\"center\"> $row1[5]</div></td>
<td class=\"tg-4eph\" ><div align=\"center\"> $row1[6]</div></td>
<td class=\"tg-031e\" ><div align=\"center\"> $row1[7]</div></td>
<td class=\"tg-4eph\" ><div align=\"center\"> $row1[8]</div></td>
<td class=\"tg-031e\"><div align=\"center\"> $row1[9]</div></td>
<td class=\"tg-031e\"><div align=\"center\"> $row1[10]</div></td>
<td class=\"tg-031e\"><div align=\"center\"> $row1[11]</div></td>
<td class=\"tg-031e\"><div align=\"center\"> $row1[12]</div></td>
<td class=\"tg-031e\"><div align=\"center\"> $row1[13]</div></td>
<td class=\"tg-4eph\" width=\"100\"><div align=\"center\">
<a href=\"adminupdatetrans.php?orderID= $row1[0]\">
<img src=\"../images/icn_edit_article.png\" title=\"Remove\"/>
</a>
<a href=\"admindeleteorder.php?orderID= $row1[0] \" onclick=\"return confirm('Are you sure want to delete ?')\">
<img src=\"../images/icn_trash.png\" title=\"Remove\"/>
</a>
</td>
</tr>
";
}
echo '
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
<td >Total All:</td>
';
echo '<td>RM';
echo $row[1];
echo '</td></tr>';
echo '</table>';
}
}
}
?>
</body>
</html>
Assuming that the date is in a timestamp format :),
You can get the names of months thanks to this method :
date("F",mktime(0,0,0,date('m', $timestamp),1,2011));Or like this :
date('F', strtotime("2015-date('m', $timestamp)-01"));
I can final exams assignment of lecturers to create a website forum.
and now there is a problem in my coding.
please fix.
when creating a topic / thread, and we opened the topic / threadnya, there is a date that tell us when the topic / thread made.
but in my coding, showing all existing date in the database.
<?php
session_start();
if($_SESSION['logged'] == true)
{
if(isset($_SESSION['username']))
{ echo $username=$_SESSION["username"];
}else
{
header('Location:login.php');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!==CSS>
<style>
#clock{
pointer-events: none
}
</style>
<!close css>
<img src="head1.jpg" alt="icon" width="100%" height="110">
<img src="line1.jpg" alt="icon" width="100%" height="20">
<title>Venray</title>
<body background="alienbackground.jpg">
<font face="comic sans MS">
<!==Table Login==>
<table border="0" style="width:99%" bgcolor="#424242" align="center">
<tr>
<table border="0" style="width:98%" bgcolor="#424242" align="center">
<tr>
<td> <img src="start.gif" alt="icon" width="26" height="26"> </td>
<td rowspan="2" align="right">
<table border="0" bgcolor="#2E2E2E">
<tr>
<td><b>
<?php
{
echo "<tr><td><b><font color=green> Welcome, ";
echo $username;
echo '<span>, [Log Out]</span></li>';
echo "</tr></td></b></font>";
}
?>
</b></td>
</tr>
<tr>
<td id=clock align="right"><b><iframe src="http://free.timeanddate.com/clock/i4eh41xm/n108/tlsg/fn7/fs12/tct/pct/ftb/tt0/tw1/tm1/th1" frameborder="0" width="182" height="20" allowTransparency="true"></iframe>
</b></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top"><b><font size="4">Community</font></b></td>
</tr>
</table>
</tr>
<p style="color:#ff0000">
<!==Table please welcome==>
<table border="0" style="width:98%" bgcolor="#424242" align="center">
<tr>
<td align="right">
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
require("conn.php");
$con = mysql_connect($server,$user,$pass);
$db = mysql_select_db($db);
$sql = "select * from d_admin order by username";
//echo $sql;
$ambil_data = mysql_query($sql);
while($data = mysql_fetch_array($ambil_data))
$result = mysql_query("SELECT * FROM d_admin");
$rows = mysql_num_rows($result);
echo "Member " . $rows . " * ";
?>
Post 1 * Topics 1 </td>
</tr>
</table>
<br>
<table border="1" width="98%" height="6%" align="center" bgcolor=#424242 >
<tr>
<td align="left" ><img src="hometopic.gif" width="40" height="40"> </td>
</tr>
<tr>
<table border="1" width="98%" height="40" align="center" bgcolor="#86B404" bordercolor=green>
<tr>
<th width="70%" align="left"><img src="open.png" width="40" height="40">Posting Display</th>
<td align="right"><img src="replay.png" width="150" height="40"></td>
</tr>
</tr>
<tr>
<table border="1" width="98%" height="70" align="center" bgcolor=#424242>
***<?php
error_reporting(E_ALL ^ E_DEPRECATED);
$con = mysql_connect($server,$user,$pass);
$db = mysql_select_db($db);
$sql = "select * from tabel_topik ";
$ambil_data = mysql_query($sql);
while($data = mysql_fetch_array($ambil_data))
{
echo '<tr><th align="left" valign="top" colspan="2" >'.$data['date'].'</th></tr>';
echo '</tr>';
}
?>***
<tr><th align="center" width="15%">Venray</th><td align="left" width="85%">title</td></tr>
<tr><th align="top" width="15%">join dates</th><td align="left" rowspan="2" valign="top">awd</td></tr>
<tr><th align="center" valign="top" width="15%" height="400">9 Post</th></tr>
<tr>
<td align="left">*</td>
<td align="right" width="85%"><img src="replay.png" width="150" height="40"></td></tr>
</table>
</tr>
</table>
</body>
</font>
</head>
</html>
Get forum specific datas by passing the ID or any similar field in the query for starters. Then if you are looking to format the way in which the date is displayed, you could use the php date function like this:
while($data = mysql_fetch_array($ambil_data))
{
echo '<tr><th align="left" valign="top" colspan="2" >'.date('jS M, Y',strtotime($data['date'])).'</th></tr>'; //format the date as required
echo '</tr>';
}
I have successfully created log in and log out page..when the user success to log in using their username and password they will go to the view page but unfortunately the view page doesn't show out data in database mysql and also no error come out on that coding..
This is my viewpage.php
<html>
<?php
include("authenticationStaff.php");
include ("dbase.php");
?>
<body>
<table width="869" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="645" height="50" align="left" valign="middle"><strong>Welcome , You log in as <?php echo $_SESSION['SESS_STAFF_NAME'];?>
<td width="377" align="right" valign="middle"><strong>Log Out</strong></td>
</tr>
</table>
</center>
<?php
$query= "SELECT s.staff_id,s.staff_name,i.project_name,i.location,i.cost,i.pic,i.detail,i.file_name,i.file_type,i.file_size,i.file_content,i.staff_id
FROM staff s
JOIN inter1 i
on(s.staff_id = i.staff_id)
WHERE i.staff_id = '".$_SESSION['SESS_ID']."'";
$result = mysql_query($query);
?>
<tr>
<td colspan="4" align="left" valign="top" class="horizon_divider"><p> </p>
</td><td width="750" valign="top"><div align="center">
<h3>DATA</h3>
<table width="836" border="2" align="center" style= "background-color: #FFFFFF; color: #000000; margin: 0 auto;" >
<thead>
<tr bgcolor="#FFFFFF">
<th width="142">PROJECT NAME</th>
<th width="114">LOCATON</th>
<th width="94">COST</th>
<th width="151">PERSON IN CHARGE</th>
<th width="187">DETAIL</th>
<th width="187">ATTACHMENT</th>
<th width="88">ACTION</th>
</tr>
</thead>
<tbody>
<?php
while( $row = mysql_fetch_assoc( $result ) ){
echo
"<tr>
<td>{$row['project_name']}</td>
<td>{$row['location']}</td>
<td>{$row['cost']}</td>
<td>{$row['pic']}</td>
<td>{$row['detail']}</td>
<td></td>
<td><a href='editStaff.php?id={$row ['staff_id']}'>ADD NEW RECORD</a>||<a href='deleteStaff.php?id={$row ['staff_id']}'>DELETE</a></td> </tr> ";
}
?>
</tbody>
</table>
</table>
</body>
</html>
Can someone see where I am going wrong?if you need any more info then please let me know. thanks.
I a newbie with this language and I do not know how to make it.
So in here I have script like this :
<?php
include_once "library/inc.sesadmin.php";
include_once "library/inc.library.php";
$row = 20;
$hal = isset($_GET['hal']) ? $_GET['hal'] : 0;
$pageSql = "SELECT * FROM kategori";
$pageQry = mysql_query($pageSql, $koneksidb) or die ("error paging: ".mysql_error());
$jml = mysql_num_rows($pageQry);
$max = ceil($jml/$row);
?>
<table width="700" border="0" cellpadding="2" cellspacing="1" class="table-border">
<tr>
<td colspan="2" align="right"><h1><b>DATA KATEGORI</b></h1></td>
</tr>
<tr>
<td colspan="2"><img src="images/btn_add_data2.png" height="25" border="0" /></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><table class="table-list" width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<th width="32" align="center"><b>No</b></th>
<th width="93" align="center"><b>Kode</b></th>
<th width="444"><b>Nama Kategori </b></th>
<th width="93" align="center"><b>Jumlah Barang</b> </th>
<td width="47" align="center" bgcolor="#CCCCCC"><b>Ubah</b></td>
<td width="52" align="center" bgcolor="#CCCCCC"><b>Hapus</b></td>
</tr>
<?php
$kategoriSql = "SELECT kategori.*, (SELECT COUNT(*) FROM barang WHERE barang.kd_kategori=kategori.kd_kategori) As qty_barang
FROM kategori ORDER BY kd_kategori ASC LIMIT $hal, $row";
$kategoriQry = mysql_query($kategoriSql, $koneksidb) or die ("Query kategori salah : ".mysql_error());
$nomor = 0;
while ($kategoriRow = mysql_fetch_array($kategoriQry)) {
$nomor++;
$Kode = $kategoriRow['kd_kategori'];
?>
<tr>
<td align="center"><b><?php echo $nomor; ?></b></td>
<td align="center"><b><?php echo $kategoriRow['kd_kategori']; ?></b></td>
<td><?php echo $kategoriRow['nm_kategori']; ?></td>
<td align="center"><?php echo $kategoriRow['qty_barang']; ?></td>
<td align="center"><img src="images/btn_edit.png" width="20" height="20" border="0" /></td>
<td align="center"><img src="images/btn_delete.png" width="20" height="20" border="0" alt="Delete Data" /></td>
</tr>
<?php } ?>
</table></td>
</tr>
<tr>
<td><b>Jumlah Data :</b> <?php echo $jml; ?> </td>
<td align="right"><b>Halaman ke :</b>
<?php
for ($h = 1; $h <= $max; $h++) {
$list[$h] = $row * $h - $row;
echo " <a href='?page=Data-Kategori&hal=$list[$h]'>$h</a> ";
}
?>
</td>
</tr>
</table>
I want to make table sorting and search by at this table, but I do not know how to make it.
Can anyone help me for this simple project??
I really appreciate your big help in here..
I'm not going to give you the exact code because it's not how we do things in SO,
However I will share with you the main idea of how to accomplish it.
For each column add a link, for example:
<td><a href='?orderby=id'>ID</a></td>
<td><a href='?orderby=name'>Name</a></td>
When id and name are fields in the table (SQL & html).
Before the query you check if there's a LEGIT value for orderby ($_GET['orderby'])
and if so add it to the ORDER BY ... in the query.
Please notice that you're using mysql_* which is not safe (especially in this case),
consider using mysqli_* or PDO (you can google it)
EDIT
You can add &direction= to the columns' links to set the direction (DESC / ASC)
I need to add "Last member topics" in the members profile, so that it shows the last 5 topics that member wrote.
I used this code:
$last_topic = mysql_query("SELECT * FROM " .prefix. "TOPICS WHERE T_AUTHOR = '".$ProMemberID."' ORDER BY T_DATE DESC LIMIT 5") or die (mysql_error());
$result = mysql_num_rows($last_topic);
if ($result > 0){
$rslast = mysql_fetch_array($last_topic);
$topic_id = $rslast['TOPIC_ID'];
$topic_subject = $rslast['T_SUBJECT'];
$topic_mes = $rslast['T_MESSAGE'];
$t_ret = $rslast['T_ENUM'];
$i=0;
while ($i < $result){
echo '<tr>
<td colSpan="2" align="center" class="userdetails_data" width="100%">
<table border="0" width="100%">
<tr>
<td>
<font style="font-size: 9pt" face="Arial"><a href="index.php?mode=t&t='.$topic_id.'">
'.$topic_subject.'</a>
</td>
<td class="editedby" width="130">
<font face="Arial" style="font-size: 9pt"> Edited
:
'.$t_ret.'</font></td>
</tr>
</table>
</td>
</tr>
';
++$i;
}
}else {
echo '<tr><td colSpan="2" align="center" class="userdetails_data" width="100%">
<span lang="ar-eg">
<font color="#FF0000" style="font-size: 9pt" face="Arial">This member has no topics yet! </font></span></td></tr>';
}
It works, but showing the same topic in the 5 rows??!!
any solutions?
its because you are assigning a $rslast one time and then using this variable in loop ,
try this
$last_topic = mysql_query("SELECT * FROM " .prefix. "TOPICS WHERE T_AUTHOR = '".$ProMemberID."' ORDER BY T_DATE DESC LIMIT 5") or die (mysql_error());
$result = mysql_num_rows($last_topic);
if ($result > 0){
while($rslast = mysql_fetch_array($last_topic)) {
$topic_id = $rslast['TOPIC_ID'];
$topic_subject = $rslast['T_SUBJECT'];
$topic_mes = $rslast['T_MESSAGE'];
$t_ret = $rslast['T_ENUM'];
echo '<tr>
<td colSpan="2" align="center" class="userdetails_data" width="100%">
<table border="0" width="100%">
<tr>
<td>
<font style="font-size: 9pt" face="Arial"><a href="index.php?mode=t&t='.$topic_id.'">
'.$topic_subject.'</a>
</td>
<td class="editedby" width="130">
<font face="Arial" style="font-size: 9pt"> Edited
:
'.$t_ret.'</font></td>
</tr>
</table>
</td>
</tr>
';
}
}else {
echo '<tr><td colSpan="2" align="center" class="userdetails_data" width="100%">
<span lang="ar-eg">
<font color="#FF0000" style="font-size: 9pt" face="Arial">This member has no topics yet! </font></span></td></tr>';
}
You are getting same value because your $result var has total rows from query which in this case is 5 while you are saving the value to variable $rslast, instead use while loop so that you can loop over array values.
$last_topic = mysql_query("SELECT * FROM " .prefix. "TOPICS WHERE T_AUTHOR = '".$ProMemberID."' ORDER BY T_DATE DESC LIMIT 5") or die (mysql_error());
$result = mysql_num_rows($last_topic);
if ($result > 0){
while($rslast = mysql_fetch_array($last_topic,MYSQL_ASSOC)) {
//^-----while Loop added to loop through arrays, ^----associative array
$topic_id = $rslast['TOPIC_ID'];
$topic_subject = $rslast['T_SUBJECT'];
$topic_mes = $rslast['T_MESSAGE'];
$t_ret = $rslast['T_ENUM'];
echo '<tr>
<td colSpan="2" align="center" class="userdetails_data" width="100%">
<table border="0" width="100%">
<tr>
<td>
<font style="font-size: 9pt" face="Arial"><a href="index.php?mode=t&t='.$topic_id.'">
'.$topic_subject.'</a>
</td>
<td class="editedby" width="130">
<font face="Arial" style="font-size: 9pt"> Edited :'.$t_ret.'</font></td>
</tr>
</table>
</td>
</tr>';
}}else {
echo '<tr><td colSpan="2" align="center" class="userdetails_data" width="100%">
<span lang="ar-eg">
<font color="#FF0000" style="font-size: 9pt" face="Arial">This member has no topics yet! </font></span></td></tr>';
}