When you run the following code below, what happens, just like it is, don’t restructure it.
[php]<?php
//require ‘config.php’;
require_once ‘functions.php’;
?>
<?php
//for testing purposes only
$_SESSION['adminname'] = 'Richard';
//Set the statuses to an array, cleans the code up at the bottom.
$statuses[0] = "Closed";
$statuses[1] = "On Hold";
$statuses[2] = "New";
$statuses[3] = "A.C.R";
$statuses[4] = "Updated";
if(isset($_POST['close'])) {
for($i = 0; $i < count($_POST['ck']); $i++) {
//echo $_POST['ck'][$i]."
";
$rid = $_POST['ck'][$i];
mysql_query("UPDATE venzo_contactus SET status = 0 WHERE req_id = '$rid'") or die(mysql_error());
}
}
$query = mysql_query("SELECT * FROM venzo_contactus WHERE status <> 0 ORDER BY date DESC") or die(mysql_error());
if(!mysql_num_rows($query)) { //if there is no data returned from the query
echo "No Inquires to display.";
} else { //If there is data returned
//Display the Table header
?>
<table cellpadding="2" cellspacing="1" border="0" style="width: 99%; padding-left: 5px; font-size: 12px;">
<tr>
<td width="32" style="text-align: center;">Req ID</td>
<td width="107" style="text-align: center;">Submitted</td>
<td width="37" style="text-align: center;">Status</td>
<td width="207" style="text-align: center;">From</td>
<td width="415" style="text-align: center;">Topic</td>
<td width="229" style="text-align: center;">Updated On</td>
<td width="121" style="text-align: center;">Ans'd by</td>
<td width="104" style="text-align: center;"></td>
</tr>
<?php
$date = date("Y-m-d");
$CurDate = strtotime($date);
$yesterday = strtotime("-1 day", $CurDate);
$i = 0; //We'll use this to create dynamic ID's so the Javascript knows what row to "Drop down"
while($r = mysql_fetch_assoc($query)) { //Loop through the data array, assign it to $r
$status = $statuses[$r['status']];
$compare = strtotime($r['date']);
if($compare > $yesterday) {
$new = "
$r[req_id]";
} else {
$new = $r['req_id'];
}
if(trim($r['subject']) == "") //If your checking for an empty variable, always trim() it to clear any whitespaces
{
$r['subject'] = "Test";
}
if(trim($r['last_answered_by']) == "") {
$ans = "
Open";
} else {
$ans = $r['last_answered_by'];
}
if($i % 2) {
echo "
\n";
} else {
echo "
\n";
}
if(empty($r['last_answered_by'])) //empty($var) is the same as $var == ""
{
$ans = "";
} else {
$val = explode(', ', $r['last_answered_by']);
$ans = end($val);
}
?>
<td style="width: 25px; padding-right: 10px;"><?php echo $new; ?></td>
<td style="width: 100px; padding-right: 10px;"><?=date('m/d/Y', strtotime($r['createdon']))?></td>
<td style="width: 30px; padding-right: 10px;"><?php echo $status; ?></td>
<td style="width: 200px; padding-right: 10px;"><?php echo $r['email']; ?></td>
<td><?php echo truncate(stripslashes($r['subject'])); ?></td>
<td style="width: 200px;"><?=date('m/d/Y', strtotime($r['date']))?> @ <?=date('h:i:s a', strtotime($r['date']))?></td>
<td style="width: 120px;" nowrap="nowrap"><?php echo $ans; ?></td>
<td style="width: 25px; padding-right: 10px;">
<a href="#<?=$i?>" onclick="ShowEdit('<?=$i?>')"> <img src="images/icn_edit.png" title="Edit News" alt="Edit News" border="0" /></a>
<input type="image" src="images/icn_trash.png" title="Trash">
</td>
</tr>
<!-- this is your drop down row put what you want in here -->
<tr style="display:none;" id="<?=$i?>" >
<td colspan="8">
<a name="<?=$i?>"></a>
<table cellpadding="1" cellspacing="1" border="0" width="100%" id="inq_tab">
<tr>
<td colspan="3" height="100" valign="top">
<div style="height: 100px; overflow: auto; padding-top: 5px; padding-left: 5px;background-color:#EEEEEE; border:1px solid #dddddd;">
<?=nl2br(strip_slashes_recursive($r['message']))?>
</div>
</td>
</tr>
</table>
<br />
<div style="width: 99.5%;">
<form action="" method="post" name="myform">
<div style="float: left; width: 90px; margin: 0 auto;">
<input type="submit" name="close" value="close message" />
</div>
<div style="float: right;">
<select name="danswer" id="danswer" >
<?php
$ans = mysql_query("SELECT * FROM venzo_contactus_answers") or die(mysql_error());
while($row = mysql_fetch_array($ans)) {
echo "<option value='$row[id]'>$row[name]</option>";
}
unset($row);
?>
</select>
<input type="button" id="a_select" name="select" value="Select" onclick="ajaxFunction();"/>
<input type="hidden" name="id" value="<?=$id?>" />
<input type="hidden" name="req_id" value="<?=$r['req_id']?>" />
</div>
</form>
</div>
<div style="clear: both;"> </div>
<form id="subticket" method="POST" action="inc/ajax_process_ticket.php" >
<input type="hidden" id="tid" name="tid" value="<?=$r['id']?>" />
<input type="hidden" id="replyto" name="cemail" value="<?=$r['email']?>" />
<input type="hidden" id="req_id" name="req_id" value="<?=$r['req_id']?>" />
<input type="hidden" id="u_name" name="u_name" value="<?=$r['name']?>" />
<input type="hidden" id="a_name" name="a_name" value="<?=$_SESSION['adminname']?>" />
<input type="hidden" id="div_id" value="<?=$i?>" />
<textarea style="width: 99%;" rows="11" name="n_answer" id="reply"><?=strip_slashes_recursive($read)?></textarea>
<div align="center" style="width: 100%;"><input type="button" id="igjo" name="igjo" value="Answer" /></div>
</form>
</td>
</tr>
<!-- end drop down row -->
<?php
$i++;
}
}
?>
[/php]