I have built a web page that updates the status to either active, inactive or "NA".
"N/A" = 0
active = 1
inactive = -1
This all works fine
These are therefore inserted into database: 1, 0 and -1
Now i want to make a update page that only shows inactive values, in other words, only shows -1
Now I want to update this like I have inserted it on the insert page
if($_REQUEST['update']=="Yes")
{
if($_GET['status']==-1){
$update = mysql_query("update causelist set msg=0 where id='".$_GET['uid']."'");
}elseif($_GET['status']==1){
$update = mysql_query("update causelist set msg=-1, where id='".$_GET['uid']."'");
}elseif($_GET['status']==0){
$update = mysql_query("update causelist set msg=1 where id='".$_GET['uid']."'");
}
}
?>
<table width="100%" style="table-layout:fixed;">
<tbody>
<?php
$query = mysql_query("select * from causelist where CaseType='A'");
while($res= mysql_fetch_array($query))
{ ?>
<tr >
<td class="blueh" width="5px" style="height:40px;">
<?php echo $res['SNo']; ?>
</td>
<td class="purpleh" width="25px" style="height:40px;">
<font size="3" style="color:black;line-height:100%;font-family:'Calibri';">
<?php echo $res['CaseNo']; ?>
</font>
</td>
<td class="purpleh" width="25px" style=" width=20px;height:40px;">
<font size="3" style="color:black;line-height:100%;font-family:'Calibri';">
<?php echo $res['CouncilName']; ?>
</font>
</td>
<td class= "purpleh" width="25px" style="width=20px;height:40px;">
<font size="3" style="color:black;line-height:100%;font-family:'Calibri';">
<?php echo $res['resadv']; ?>
</font>
</td>
<td class="redh" width="3px" style=";line- height:50%;">
<?php if($res['msg']==1)
{
//echo "Active";
echo "<img src='images/r.png'/>";
}
elseif($res['msg']==-1)
{
//echo "Inactive";
echo "<img src='images/take.png'/>";
}
elseif($res['msg']==0)
{
//echo "NA";
echo "<img src='images/none.png'/>";
} ?></td>
<td class="redh" width="3px" style="center;height:5px;line-height:50%;">
<a href="case.php?uid=<?php echo $res['id']; ?>&update=Yes&status=
<?php echo $res['msg']; ? >">
<img src="images/p2.png"/></a></td>
</tr>
<?php }}?>
</tbody>
</table>
Related
Why my edit button only function for row 1 only in my table?
When I click other rows it still show data from row 1 but the id is changed.
When I update row 1 the data updates in the database.
//fetch the record to be updated
if (isset($_GET['edit'])){
$entry_id = $_GET['edit'];
$edit_state = true;
$rec = mysqli_query($db, "select r.room_id, r.room_name, s.time_date, s.entry_id, s.time_exam, s.course_code, s.course_enroll from room r, schedule_entry s where s.room_id = r.room_id");
$record = mysqli_fetch_array($rec);
$time_date = $record['time_date'];
$time_exam = $record['time_exam'];
$course_code = $record['course_code'];
$course_enroll = $record['course_enroll'];
$room_name = $record['room_name'];
$room_id= $record['room_id'];
$entry_id= $record['entry_id'];
}
?>
<?php
if (mysqli_num_rows($results)>0){
while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td width="180"><?php echo $row['time_date']; ?></td>
<td width="70"><?php echo $row['time_exam']; ?></td>
<td width="200"><?php echo $row['course_code']; ?></td>
<td width="70"><?php echo $row['course_enroll']; ?></td>
<td><?php echo $row['room_name']; ?></td>
<td width="70">
<a class="edit_btn" href="entry.php?edit=<?php echo $row['entry_id']; ?>">Edit</a>
</td>
<td width="70">
<a class="del_btn" href="entryserver.php?del=<?php echo $row['entry_id']; ?>">Delete</a>
</td>
</tr>
<?php } }?>
you need to run the loop to update the ids,
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<td> <a class="edit_btn" href="entry.php?edit=
<?php echo $row['entry_id']; ?>">Edit</a></td>
<?php
}
}
?>
you have to evaluate your syntax, i think $row['entry_id'] have same value, so you must var_dump($row) form know all, like that
.... SOME CODE ....
<?php
if (mysqli_num_rows($results)>0){
while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td><? var_dump($row); ?>
</tr>
<?php } }?>
and after that i think you can solve your problem ...
I've never had issues programming PHP SQL updates when updating multiple rows of data with multiple columns, but for some reason this section of coding is killing me as it is nothing more than checkboxes for the end user to check and/or uncheck. I've include portions of the code below as the full code is over 50+ columns wide of checkboxes and can range from 1-200 rows.
Everything displays/runs the way its supposed to but the updating isnt functioning properly ... example: if there is 5 rows (each with a unique trackingid) and I check the checkbox for the 4th row on update it says that the 1st checkbox was checked and NOT the 4th row.
<?php if (!isset($_POST['trackingid'])) { ?>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post" enctype="multipart/form-data" class="form-horizontal" id="form"><input type="hidden" name="id" value="<?php echo $id; ?>">
<table class="table table-striped">
<thead>
<tr>
<td class="rotate-alt"></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt"><div><span>Glass</span></div></td>
<td class="rotate-alt"><div><span>Glass - SDL</span></div></td>
<td class="rotate-alt"><div><span>Mill - S&R</span></div></td>
</tr>
</thead>
<tbody>
<?php $result = sqlsrv_query($conn, "SELECT id, [Order Number], [Door Number], [Qty Display], [Interior or Exterior], [Style], Species_DD_Desc, [Mill Batch Nbr],
[Glass Completed], [Glass Completed By], [Glass STD Hrs], [SDL Completed], [SDL Completed By], [SDL STD Hrs],
[Mill Completed], [Mill Completed By], [Mill STD Hrs]
FROM PD_Tracking
WHERE [Order Number] = '$id'
ORDER BY [Door Number], [Qty Display], [Mill Batch Nbr]");
$i=0;
while ($list = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){ ?>
<tr>
<td class="center">
<input type="checkbox" onclick="$('input[id=\'selid<?php echo $i; ?>\']').attr('checked', this.checked);">
<input type="hidden" name="trackingid[]" value="<?php echo $list['id']; ?>">
</td>
<td class="center"><?php echo $list['Door Number']; ?></td>
<td class="center"><?php echo $list['Qty Display']; ?></td>
<td class="center"><?php echo $list['Interior or Exterior']; ?></td>
<td class="center"><?php echo $list['Style']; ?></td>
<td class="center"><?php echo $list['Species_DD_Desc']; ?></td>
<td class="center">
<?php if (($list['Glass STD Hrs']>0) && (!isset($list['Glass Completed']))){ ?>
<input type="checkbox" name="glass[]" id="selid<?php echo $i; ?>">
<?php } else if (($list['Glass STD Hrs']>0) && ($list['Glass Completed'] > ' ')){ ?>
<input type="checkbox" name="glass[]" checked="checked" id="selid<?php echo $i; ?>">
<?php } else { ?>
NR
<?php } ?>
</td>
<td class="center">
<?php if (($list['SDL STD Hrs']>0) && (!isset($list['SDL Completed']))){ ?>
<input type="checkbox" name="sdl[]" id="selid<?php echo $i; ?>">
<?php } else if (($list['SDL STD Hrs']>0) && ($list['SDL Completed'] > ' ')){ ?>
<input type="checkbox" name="sdl[]" checked="checked" id="selid<?php echo $i; ?>">
<?php } else { ?>
NR
<?php } ?>
</td>
<td class="center">
<?php if (($list['Mill STD Hrs']>0) && (!isset($list['Mill Completed']))){ ?>
<input type="checkbox" name="mill[]" id="selid<?php echo $i; ?>">
<?php } else if (($list['Mill STD Hrs']>0) && ($list['Mill Completed'] > ' ')){ ?>
<input type="checkbox" name="mill[]" checked="checked" id="selid<?php echo $i; ?>">
<?php } else { ?>
NR
<?php } ?>
</td>
</tr>
<?php ++$i;
} ?>
</tbody>
</table>
<?php } // END if (!isset($_POST['trackingid'])) {
if (isset($_POST['trackingid'])) {
$query = sqlsrv_query($conn, "SELECT * FROM users WHERE id=".$_SESSION['auid']."");
$row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC);
$employee_num = $row['Employee Number'];
$size = count($_POST['trackingid']);
for($i=0; $i < $size; $i++){
$trackingid = $_POST['trackingid'][$i];
$query = "UPDATE PD_Tracking SET ";
if(isset($_POST['glass'][$i])){
$query .= "[Glass Completed]='$date_time_entered', [Glass Completed By]='$employee_num', ";
} else {
$query .= "[Glass Completed]= NULL, [Glass Completed By]= NULL, ";
}
if(isset($_POST['sdl'][$i])){
$query .= "[SDL Completed]='$date_time_entered', [SDL Completed By]='$employee_num', ";
} else {
$query .= "[SDL Completed]= NULL, [SDL Completed By]= NULL, ";
}
if(isset($_POST['mill'][$i])){
$query .= "[Mill Completed]='$date_time_entered', [Mill Completed By]='$employee_num' ";
} else {
$query .= "[Mill Completed]= NULL, [Mill Completed By]= NULL ";
}
$query .= "WHERE id='$trackingid'";
$query = sqlsrv_query($conn, $query);
} // END for($i=0; $i < $size; $i++){?>
<SCRIPT LANGUAGE='JavaScript'>
<!-- Begin
window.location = '<?php echo $_SERVER['REQUEST_URI']; ?>&success=edit';
// End -->
</script>
<?php } // END if (isset($_POST['trackingid'])) { ?>
I have a table of exams where I have an edit part. When I select one of exam to edit it doesn't take the exam's id. And I can't figure it out why. Here is my code :
This is my principal page content where is showing the table
<div class="view">
<table class="tabel">
<tr class="tepprand">
<td>Data</td>
<td>An</td>
<td>Materia</td>
<td>Profesor</td>
<td>Asistent</td>
<td>Sala</td>
<td>Tip Examen</td>
</tr>
<?php
$sqll = "SELECT r.id AS id , r.data AS data , ra.an AS an, rm.numemat AS numemat, rp1.numep AS numep1 , rp1.prenumep AS prenumep1, rp2.numep AS numep2, rp2.prenumep AS prenumep2, rs.salaa AS salaa , re.tip AS tip
FROM examen_programat AS r
LEFT JOIN an ra ON (r.id_ann=ra.id_an)
LEFT JOIN materii rm ON (r.id_mate=rm.id_mat)
LEFT JOIN profesor rp1 ON (r.id_prof1=rp1.id_prof)
LEFT JOIN profesor rp2 ON (r.id_prof2=rp2.id_prof)
LEFT JOIN sala rs ON (r.id_sala=rs.id_s)
LEFT JOIN examen re ON (r.id_tipp = re.id_tip)
ORDER by data";
$result = mysqli_query($link,$sqll);
while($rows=mysqli_fetch_array($result,MYSQLI_BOTH)) {
?>
<tr>
<td><?php echo $rows['data']; ?></td>
<td><?php echo $rows['an']; ?></td>
<td><?php echo $rows['numemat']; ?></td>
<td><?php echo $rows['numep1']." ".$rows['prenumep1']; ?></td>
<td><?php echo $rows['numep2']." ".$rows['prenumep2']; ?></td>
<td><?php echo $rows['salaa']; ?></td>
<td><?php echo $rows['tip']; ?></td>
<td> Edit </td>
<td> Stergere </td>
</tr>
<?php
}
?>
</table>
</div>
This is what happens when I press EDIT :
<div class="view">
<?php
$idul=$_GET['id'];
$str = "SELECT * FROM examen_programat WHERE id =$idul ";
$rez = mysqli_query($link,$str);
$row = mysqli_fetch_array($rez);
$an=$row['id_ann'];
$materie=$row['id_mate'];
$profesor=$row['id_prof1'];
$asistent=$row['id_prof2'];
$salaa=$row['id_sala'];
$tip=$row['id_tipp'];
?>
<form name="tabel" method="post" action="updateexamen.php">
<input type="hidden" name="idu" value="<?php echo " $idul" ?>">
<table>
<tr>
<td>Data</td>
<td><input type="date" name="data" value="<?php echo $row['data'] ?>" required="required"/><br></td>
</tr>
<tr>
<td>An</td>
<td>
<?php
$sql_year="SELECT * FROM an";
$rez_year = mysqli_query($link,$sql_year);
echo "<select name=\"year\" >";
while($year=mysqli_fetch_array($rez_year))
{
echo "
<option value=\"".$year['id_an'];
if ($year[
'id_an']==$an)
echo "\" selected=\"selected\">".$year['grupa']."</option>\n";
else
echo "\">".$year['grupa']."</option>\n";
}
echo "</select>";
?><br>
</td>
</tr>
<tr>
<td>Materie</td>
<td>
<?php
$sql_mat="SELECT * FROM materii";
$rez_mat = mysqli_query($link,$sql_mat);
echo "<select name=\"mat\" >";
while($mat=mysqli_fetch_array($rez_mat))
{
echo "
<option value=\"".$mat['id_mat'];
if ($mat[
'id_mat']==$materie)
echo "\" selected=\"selected\">".$mat['numemat']."</option>\n";
else
echo "\">".$mat['numemat']."</option>\n";
}
echo "</select>";
?><br>
</td>
</tr>
<tr>
<td>Profesor</td>
<td>
<?php
$sql_proff="SELECT * FROM profesor";
$rez_proff = mysqli_query($link,$sql_proff);
echo "<select name=\"proff\" >";
while($proff=mysqli_fetch_array($rez_proff))
{
echo "
<option value=\"".$proff['id_prof'] ;
if($proff[
'id_prof']==$profesor)
echo "\" selected=\"selected\">".$proff['numep']." ".$proff['prenumep']."</option>\n";
else
echo "\">".$proff['numep']." ".$proff['prenumep']."</option>\n";
}
echo "</select>";
?><br>
</td>
</tr>
<tr>
<td>Asistent</td>
<td>
<?php
$sql_profff="SELECT * FROM profesor";
$rez_profff = mysqli_query($link,$sql_profff);
echo "<select name=\"profff\" >";
while($profff=mysqli_fetch_array($rez_profff))
{
echo "
<option value=\"".$profff['id_prof'];
if($profff[
'id_prof']==$asistent)
echo "\" selected=\"selected\">".$profff['numep']." ".$profff['prenumep']."</option>\n";
else
echo "\">".$profff['numep']." ".$profff['prenumep']."</option>\n";
}
echo "</select>";
?><br>
</td>
</tr>
<tr>
<td>Sala</td>
<td>
<?php
$sql_sala="SELECT * FROM sala";
$rez_sala= mysqli_query($link,$sql_sala);
echo "<select name=\"sala\" >";
while($sala=mysqli_fetch_array($rez_sala))
{
echo "
<option value=\"".$sala['id_s'];
if ($sala[
'id_s']==$salaa)
echo "\" selected=\"selected\">".$sala['salaa']."</option>\n";
else
echo "\">".$sala['salaa']."</option>\n";
}
echo "</select>";
?><br>
</td>
</tr>
<tr>
<td>Tip</td>
<td>
<?php
$sql_type="SELECT * FROM examen";
$rez_type= mysqli_query($link,$sql_type);
echo "<select name=\"type\" >";
while($type=mysqli_fetch_array($rez_type))
{
echo "
<option value=\"".$type['id_tip'];
if ($type[
'id_tip']==$tip)
echo "\" selected=\"selected\">".$type['tip']."</option>\n";
else
echo "\">".$type['tip']."</option>\n";
}
echo "</select>";
?><br>
</td>
</tr>
<tr>
<td><input name="submit" type="submit" value="Update"/></td>
<td><input name="reset" type="reset" value="Reset"/></td>
</tr>
</table>
</form>
</div>
And this is the UPDATE:
<?php
include ('conect.php');
$idd=$_POST['idu'];
$a1=$_POST['data'];
$b1=$_POST['year'];
$c1=$_POST['mat'];
$d1=$_POST['proff'];
$e1=$_POST['profff'];
$f1=$_POST['sala'];
$g1=$_POST['type'];
$str = "UPDATE examen_programat
SET data='$a1',
id_ann='$b1',
id_mate='$c1',
id_prof1='$d1',
id_prof2='$e1',
id_sala='$f1',
id_tipp='$g1'
WHERE id='$idd'";
$result=mysqli_query($link,$str);
// if successfully updated.
if($result){
header("Location:tabelex.php");
}
else {
echo "ERROR";
}
?>
And my table of examen_programat it looks like this:
id id_ann id_mate id_prof1 id_prof2 id_sala id_tipp
Short open tag may cause this problem, on your last two td element. Add php after your ?
<td>
Edit
</td>
<td>
Stergere
</td>
From PHP DOC: http://php.net/manual/en/language.basic-syntax.phptags.php
PHP also allows for short open tag <? (which is discouraged since it
is only available if enabled using the short_open_tag php.ini
configuration file directive, or if PHP was configured with the
--enable-short-tags option).
My code
<?php
include('ConnectToDb.php');
$query = "SELECT * FROM News WHERE NewsFlag = 1 ORDER BY PostDate DESC";
$arrCount = -1;
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$ID=$row['ID'];
$PostDate = $row['PostDate'];
$NewsHeader = stripslashes($row['NewsHeader'])
;
$NewsStart = stripslashes($row['NewsStart'])
;
echo "<hr>";
echo "<div>". date('j F Y',strtotime($PostDate)). "</div>";
echo "<p>";
$news_id = strval(sprintf("%1$04d",$ID));
$array = scanImageFolder("newsImages/newsThumbs",$news_id);
if(count($array)>0) {
echo "<img src='". $array[0]. "' alt='' />";
}
echo "<h2 style='text-align:center'><u><a href='latestnews_full.php?ID=$ID'>". $NewsHeader. "</a></u></h2>";
echo "<div style='text-align:left'><h3>";
echo $NewsStart. " ......<a href='latestnews_full.php?ID=$ID'>(more)</a><br />";
echo "<div style='text-align:center'>";
echo "</div>";
echo "</h3></div>";
}
?>
displays my data nicely on four lines with date at the top, then a picture, title and then description.
However, I want to display the data as a table like this
<table style="width: 100%">
<tr>
<td colspan="2">postDate here</td>
</tr>
<tr>
<td rowspan="2">picture here</td>
<td>newsHeader here</td>
</tr>
<tr>
<td>newsStart here</td>
</tr>
</table>
I'm not sure how to echo the table cells correctly and all of my attempts so far have resulted in a white page. Could anyone please enlighten me?
I'd suggest you to make your logic separated from your presentable part. Close the PHP tag once you are ready fetching the results, assigning var's etc, then:
<table style="width: 100%">
<?php
//yourcode
//...
//...
$NewsStart = stripslashes($row['NewsStart']);
$news_id = strval(sprintf("%1$04d",$ID));
$array = scanImageFolder("newsImages/newsThumbs",$news_id);
?>
<tr>
<td colspan="2"><?= date('j F Y',strtotime($PostDate)) ?></td>
</tr>
<tr>
<?php
if(count($array)>0) {
?>
<td rowspan="2"><img src='<?= $array[0] ?>' alt='' /></td>
<?php } ?>
<td><?= $NewsHeader ?></td>
</tr>
<tr>
<td><?= $NewsStart ?> </td>
</tr>
<?php } ?>
</table>
However, it's again not so clear, and I would suggest using a template engine. If you want I can post a code with assigning vars to Smarty and output your presentation in Smarty template
I'm trying to use php with mysql. basically i've an index page where user fills a form and another page where all rows are displayed. i've checkboxes for each row for deleting the selected row/rows. i'm trying to create a new page (namely details) where it shows only the selected row.
I'm trying to use $_GET but i could not do it. maybe the syntax is wrong. any help is welcome.
here are the relative code parts:
display.php:
<?
require_once('auth.php');?>
<html>
<head>
<title>Goruntule</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="checkboxForm">
<?
require "config.php"; // All database details will be included here
$page_name="display.php";
$start=$_GET['start']; // To take care global variable if OFF
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start -0);
$limit = 10; // No of records to be shown per page.
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
// WE have to find out the number of records in our table. We will use this to break the pages
$query2=" SELECT * FROM table1 ";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);
/////// The variable nume above will store the total number of records in the table////
/////////// Now let us print the table headers ////////////////
$bgcolor="#f1f1f1";
echo "<TABLE width=80% align=center cellpadding=5 cellspacing=0> <tr>";
echo "<td bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='2'>#</font></td>";
echo "<td bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='2'>ID</font></td>";
echo "<td bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='2'>Time</font></td>";
echo "</tr>";
////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
$query=" SELECT * FROM table1 ORDER BY id DESC limit $eu, $limit ";
$result=mysql_query($query);
echo mysql_error();
//////////////// Now we will display the returned records in side the rows of the table/////////
while($rows = mysql_fetch_array($result))
{
if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}
echo "<tr>";
echo "<td><input name='checkbox[]' type='checkbox' value='" . $rows[id] . "'></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='1'>$rows[id]</font></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='1'>$rows[DateTime]</font></td>";
echo "<td>Details</td>";
//here is the problematic line i guess
echo "</tr>";
}
echo "</table>";
////////////////////////////// End of displaying the table with records ////////////////////////
///// Variables set for advance paging///////////
$p_limit=100; // This should be more than $limit and set to a value for whick links to be breaked
$p_f=$_GET['p_f']; // To take care global variable if OFF
if(!($p_f > 0)) { // This variable is set to zero for the first page
$p_f = 0;
}
$p_fwd=$p_f+$p_limit;
$p_back=$p_f-$p_limit;
//////////// End of variables for advance paging ///////////////
/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
echo "<table align = 'center' width='50%'><tr><td align='left' width='20%'>";
if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='2'>PREV $p_limit</font></a>"; }
echo "</td><td align='left' width='10%'>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0 and ($back >=$p_f)) {
print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='2'>PREV</font></a>";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
echo "</td><td align=center width='30%'>";
for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit){
if($i <> $eu){
$i2=$i+$p_f;
echo " <a href='$page_name?start=$i&p_f=$p_f'><font face='Verdana' size='2'>$i</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$i</font>";} /// Current page is not displayed as link and given font color red
}
echo "</td><td align='right' width='10%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume and $this1 <($p_f+$p_limit)) {
print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='2'>NEXT</font></a>";}
echo "</td><td align='right' width='20%'>";
if($p_fwd < $nume){
print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='2'>NEXT $p_limit</font></a>";
}
echo "</td></tr></table>";
?>
<tr>
<td colspan="14" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete">
<form>
<INPUT TYPE="BUTTON" VALUE="Previous" ONCLICK="window.location.href='http://......../util'">
</FORM></td>
</tr>
<?php
$checkbox=$_POST['checkbox'];
if($_REQUEST['delete']=='Delete'){
foreach($checkbox as $id => $value)
{$sql="DELETE FROM table1 WHERE id='$value'";
$result = mysql_query($sql);
}
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=display.php\">";
}
}
?>
details
<?
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
detail.php
<?php
require_once('auth.php');
$host="localhost";
$username="";
$password="";
$db_name="";
$tbl_name="table1";
mysql_connect("$host", "$username", "$password")or die("Cannot connect ". mysql_error());
mysql_select_db("$db_name")or die("Cannot select DB ". mysql_error());
$num=$_GET['var1'];
$query = "SELECT * FROM table1 where id='$num'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_row($result) or die(mysql_error());
?>
<table border="0" align="center" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="13" align="center" bgcolor="#FFFFFF"><strong>Bölge</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Time</strong></td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name="checkbox[]" type="checkbox" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF" align="center"><? echo $row['13']; ?></td>
<td bgcolor="#FFFFFF" align="center"><? echo $row['0']; ?></td>
</tr>
<tr>
<td colspan="14" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete">
<form>
<input type=button value="Close" onClick="javascript:window.close();">
</form>
</tr>
<?php
$checkbox=$_POST['checkbox'];
if($_REQUEST['delete']=='Delete'){
foreach($checkbox as $key=>$value)
{$sql="DELETE FROM $tbl_name WHERE id='$value'";
$result = mysql_query($sql);
}
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=display.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
<html><head><link href="loginmodule.css" rel="stylesheet" type="text/css" /></head></html>
As I've said, the only problem i'm guessing is with the syntax, or something small as i can echo the row when i gave the var1 a specific id.
I'm sorry if i'm reposting but i couldn't find an answer. Thanks!
Edit: I'm thinking of deleting checkbox parts and adding gif links in the while loop where users can delete, edit or detailed view of the corresponding row. seems easier i guess.
Make sure that the details link is within the while block.
<?php
while($rows = mysql_fetch_array($result)) {
echo 'Details';
}
?>
Looks like you should not be using double quotes.
<? echo "$rows[id]" ?>
Should be
<?php echo $rows[id]; ?>
I also suggest you use 'id' as the name of the get rather than 'var1'. 'var1' does not mean anything whereas 'id' makes more sense.
Details
It's because you are using $rows outside your while-loop. You have to put the
Details
inside the while loop.
//EDIT:
Alright, I've stripped your code to the very neccessary according to your problem. So don't just copy/paste the code, it probably won't work. But read it carefully, and I hope you get the idea and see what may be wrong with your code ;)
display.php
<?php
require_once('auth.php');
require "config.php";
$page_name="display.php";
$start = (isset($_GET['start']) && $_GET['start'] < 1) ? 0 : $_GET['start'];
$eu = ($start-0);
$limit = 10;
$query="SELECT * FROM table1 ORDER BY id DESC limit $eu, $limit";
$result=mysql_query($query);
echo mysql_error();
$i = 0; //counter for the bg-color
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="checkboxForm">
<table width="80%" align="center" cellpadding="5" cellspacing="0">
<?php while($rows = mysql_fetch_array($result)) :
$bgcolor = $i%2 == 0 ? '#ffffff' : '#f1f1f1';
?>
<tr>
<td>
<input name="checkbox[]" type="checkbox" value="<?php echo $rows['id']; ?>">
</td>
<td style="align: left; font-family: Verdana; font-size: 10px; background-color: <?php echo $bgcolor; ?>;" id="title">
<?php echo $rows['id']; ?>
</td>
<td style="align: left; font-family: Verdana; font-size: 10px; background-color: <?php echo $bgcolor; ?>;" id="date">
<?php echo $rows['DateTime']; ?>
</td>";
<td>
Details
</td>
</tr>
<?php endwhile; ?>
</table>
</form>
detail.php
<?php
require_once('auth.php');
$num= isset($_GET['var1']) ? $_GET['var1'] : '';
$query = "SELECT * FROM table1 where id='$num'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
?>
<form name="form1" method="post" action="">
<table border="0" align="center" cellspacing="1" cellpadding="0">
<input name="checkbox[]" type="checkbox" value="<? echo $rows['id']; ?>">
<? echo $row['13']; ?>
<? echo $row['0']; ?>
<input name="delete" type="submit" id="delete" value="Delete">
<button onClick="javascript:window.close();">Close</button>
</table>
</form>
And not only for security's sake, you should get more familiar with PHP and some design patterns before publishing your website.