Help with processing records

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Wade
Forum Commoner
Posts: 41
Joined: Mon Dec 18, 2006 10:21 am
Location: Calgary, AB, Canada

Help with processing records

Post by Wade »

Morning everyone, I'm having a real bad case of the Mondays (just can't seem to figure this out!)

What Ia ma trying to do is give the user a page to administer an event invite list, this page will only show those that are invited so far. what I want to do is be able to remove records based on the unchecking of the 'Invited' checkbox. Will I need to use js as well?

Here's my code so far, this displays the records correctly, so we're about 50% there (I think):

Code: Select all

<?php
$windowtitle="Contacts Database";
$dbtitle="Contacts Database";
$pagetitle="Edit Invite List";
include 'header.php';
include 'config.php';
include 'opendb.php';
session_start();
if(isset($_SESSION['myusername'])){ 
// how many rows to show per page
$rowsPerPage = 20;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}

if(isset($_GET['event'])){
  $event = html_entity_decode($_GET['event']);
	$eventsafe = $_GET['event'];
} else { 
    if(isset($_POST['selInvite'])){
  	$event = ereg_replace("-", " ", $_POST["selInvite"]);
    $eventsafe = htmlentities($event);
  }
}
echo("Event: " . $event);
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$pagingQuery = " LIMIT $offset, $rowsPerPage";

switch ($event) {
case "Builder Luncheon":
		 $anEventsCat = "xBuilderLunchInvite";
    break;
case "DJD":
		 $anEventsCat = "DJDInvite";
    break;
default:
		 $anEventsCat = "";
} 


//Get EventID to restrict records by
	$query = "SELECT EventID FROM events WHERE EventName='" . $event . "'";
 	$result = mysql_query ($query)or die ('I cannot connect to the database because: ' . mysql_error());
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
  $eventID = $row4['EventID'];

	//Get records
  $query = mysql_escape_string("SELECT * FROM anualevents WHERE " . $anEventsCat . "=1");
// 	echo($query . "<br><br>");
	$result = mysql_query ($query)or die ('I cannot connect to the database because: ' . mysql_error());

  $result = mysql_query($query . $pagingQuery) or die ('I cannot connect to the database because: ' . mysql_error());
  $total = mysql_num_rows($result);
?>
<form name="myform" method="post" action="edinv.php" >
<h2><font size =2><?php echo($total . " Record(s) of $numrows shown."); ?></font></h2></div>
<p>

<table cellspacing=0 cellpadding=0 width=960 class="sorttable" rules="none">
<tr>
<th>Name</th>
<th>Company</th>
<th>Title</th>
<?php
echo("<th width =70>" . $event . " Invite</th>");
?>
<th>Phone</th>
<th>Category</th>
<th>Email</th></tr>

<?php if($total>0) {
// fetch the current row into the array $row
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
//print_r($row);
    $query2 = mysql_escape_string("SELECT * FROM _contact WHERE ContactID = " . $row['ContactID'] );
//		echo($query2 . "<br><br>");
    $result2 = mysql_query ($query2)or die ('I cannot connect to the database because: ' . mysql_error());
    $row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
	  $name = $row2["Prefix"] . " " . $row2["FirstName"] . " " . $row2["LastName"];
echo("<tr>");
echo("<td>" . substr($name, 0, 30) . "</td>");
echo("<td>" . substr($row2["CompanyName"], 0, 20) . "</td>");
echo("<td>" . substr($row2["Position"], 0, 18) . "</td>");
?>
<td><input type="checkbox" name="record[]" value=<?php echo ($row2["ContactID"]); ?> <?php if($row[$anEventsCat]){echo " CHECKED";} ?>  /></td>
<?php
if($row2["PhoneWorkExt"]){
echo("<td>" . substr($row2["PhoneWork"], 0, 14) . "  x" . substr($row2["PhoneWorkExt"], 0, 5) . "</td>");
} else {
echo("<td>" . substr($row2["PhoneWork"], 0, 14) . "</td");
}
$query5 = "SELECT * FROM category WHERE CategoryID='" . $row2["CategoryID"] . "'";
$result5  = mysql_query($query5) or die ('I cannot connect to the database because: ' . mysql_error());
$row5 = mysql_fetch_array($result5, MYSQL_ASSOC);
echo("<td>" . $row5["CategoryName"] . "</td>");
echo("<td><a href=\"mailto:". $row2["Email"] . "\">". $row2["Email"] . "</a></td>");
echo "</tr>";
}
echo("</table>");
echo("<br>");
}
$result  = mysql_query($query) or die('Error, query failed');
$numrows = mysql_num_rows($result);

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

$self = $_SERVER['PHP_SELF'];

// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link

// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
	$page = $pageNum - 1;
	if (isset($eventsafe)){
	$prev = " <a href=\"$self?page=$page&event=$eventsafe\">[Prev]</a> ";
	$first = " <a href=\"$self?page=1&event=$eventsafe\">[First Page]</a> ";
	} else {
	$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
	$first = " <a href=\"$self?page=1\">[First Page]</a> ";
	}
}
else
{
	$prev  = '';       // we're on page one, don't enable 'previous' link
	$first = ''; // nor 'first page' link
}

// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
	$page = $pageNum + 1;
	if (isset($eventsafe)){
	$next = " <a href=\"$self?page=$page&event=$eventsafe\">[Next]</a> ";
	$last = " <a href=\"$self?page=$maxPage&event=$eventsafe\">[Last Page]</a> ";
	} else {
	$next = " <a href=\"$self?page=$page\">[Next]</a> ";
	$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
	}
}
else
{
	$next = '';      // we're on the last page, don't enable 'next' link
	$last = ''; // nor 'last page' link
}
?>
<input type="Submit" value="Go" class="button" onclick="if(QuerySave(this.form)){this.form.submit()" style="color: #fff; background-color: #f90"/>
</form>
<br><br>
<?php
// print the page navigation link
echo $first . $prev . "Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;
} else {
			 		echo "You are not authorized to view this page.";
}
include 'closedb.php';
include 'footer.php';
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Javascript is never required. If one thinks it is, things need to be reconsidered.

Only selected checkboxes are submitted. You will need to compare what is submitted against what the database holds. I don't see how this is a Client-side issue.
Post Reply