passing variables not working on a new tab - php

I am trying to open a new tab with a specific url with variables on it but the variables are not passed on the second tab. please help me with this . Heres my code.
<?php
$type= $_GET['type'];
$brochure_id = $_GET['id'];
$sql1 = "SELECT * from business_type WHERE business_id = '$type'";
$q1= $conn->query($sql1);
$q1->setFetchMode (PDO::FETCH_ASSOC);
$location=" ";
while($r1 = $q1->fetch())
{
if($r1['business_type'] == "Hotel"){
$location ="hotel.php";
}
else if($r1['business_type'] == "Restaurant"){
$location ="restaurant.php";
}
else if($r1['business_type'] == "Resort"){
$location ="resort.php";
}
else if($r1['business_type'] == "Spa"){
$location ="spa.php";
}
else if($r1['business_type'] == "Entertainment"){
$location ="entertainment.php";
}
}
echo "<a href='search-result-page-" . $location . "'?id='" . $brochure_id ."'' target='_blank' style='text-decoration: none' >
<div style='width: 260px; min-height: 30px; background-color: rgba(180,180,180,0.5); position: absolute; z-index: 1000; font-size: 17px; padding: 5px; color: black'>" . $r['business_name'] . "</div>
<img src='". $r['display_pic'] ."' width='260px' height='150px' />
</a>
</td>";
if($maxcol==$column){
echo "</tr>";
$column=0;
}
}
?>

Related

Showing div if condition is true

I asked this question before and got an answer but I want to do something differently. I am creating a social site that let's people message each other. I want to show the div with a blue background if the opened column is == 0. But what I have now only shows the div in the else column which is blank.
So immediately the background color goes straight to the else color even though the condition is true and it should be showing the blue color. Any help ?
public function getConvos () {
$userLoggedIn = $this->user_obj->getUsername();
$return_string = "";
$convos = array();
$query = $this->con->prepare('SELECT user_to, user_from, opened FROM messages WHERE
user_to = ? OR user_from = ? ORDER BY id DESC');
$query->bind_param("ss", $userLoggedIn, $userLoggedIn);
$query->execute();
$query_result = $query->get_result();
while ($row = $query_result->fetch_assoc()) {
$user_to_push = ($row['user_to'] != $userLoggedIn) ? $row['user_to'] : $row['user_from'];
if(!in_array($user_to_push, $convos)) {
array_push($convos, $user_to_push);
}
$color = ($row['opened'] == '0') ? "#DDEDFF" : "";
}
foreach ($convos as $username) {
$user_found_obj = new User($this->con, $username);
$latest_message_details = $this->getLatestMessage($userLoggedIn, $username);
$return_string .= "<a href='messages.php?u=$username'><div class='user_found_messages'
style='background-color: $color;' >
<img src='" . $user_found_obj->getProfilePic() .
"' style='border-radius: 5px; margin-right: 5px;'>
". $username ."<br/>".
$latest_message_details . "</div></a>";
}
return $return_string;
}
.user_found_messages {
padding-left: 10px;
padding-top: 20px;
padding-bottom: 10px;
height: auto;
border-bottom: 1px solid #d9d9d9;
}
.user_found_messages:hover {
background-color: #e6ffff;
color: #669999;
}
.user_found_messages img {
height: 105px;
float: left;
margin-top: 1px;
margin-right: 5px;
}
This issue happened due to $color overwrite in each iteration.
Try this:
$i = 0;
while ($row = $query_result->fetch_assoc()) {
$user_to_push = ($row['user_to'] != $userLoggedIn) ? $row['user_to'] : $row['user_from'];
if(!in_array($user_to_push, $convos)) {
array_push($convos, $user_to_push);
}
$color[$i] = ($row['opened'] == '0') ? "#DDEDFF" : "";
$i++;
}
foreach ($convos as $key => $username) {
$user_found_obj = new User($this->con, $username);
$latest_message_details = $this->getLatestMessage($userLoggedIn, $username);
$return_string .= "<a href='messages.php?u=$username'><div class='user_found_messages'
style='background-color: ". $color[$key]; ."' >
<img src='" . $user_found_obj->getProfilePic() .
"' style='border-radius: 5px; margin-right: 5px;'>
". $username ."<br/>".
$latest_message_details . "</div></a>";
}

PHP MySQL Result displays twice why?

I have this simple PHP Script to fetch results from the localhost WAMP server, and when I echo the query it displays one record twice for every record I have!
Result displayed as shown in picture:
Here is the PHP MySQL script
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
$movie_lists = "";
$no_result = "";
$servername = "localhost";
$username = "root";
$password = "localpass";
$dbname = "movieadventuredb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//$sql = "SELECT id, movie_quality, movie_release_date FROM movielisting";
$sql = "SELECT * FROM movielisting ORDER BY ID DESC LIMIT 10";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
//echo "id: " . $row["id"]. " - Name: " . $row["movie_name"]. " " . $row["movie_quality"]. "<br>";
$id = $row["id"];
$movie_quality = $row["movie_quality"];
$release_date = strftime("%Y", strtotime($row["movie_release_date"]));
$movie_lists .= "<div class='item item-1'><a href='#'><img src='inventory_images/$id.jpg'/></a>
<a href='#'><div class='overlay'>
<p class='movie_quality $movie_quality'>$movie_quality</p>
<p class='movie_year year'>$release_date</p>
</div></a>
</div>";
}
} else {
$movie_lists = "";
}
$conn->close();
?>
Below is the code for CSS for the listing.
.recent_movies_slider .recent_movie_lists {float:left; width:97%;}
.slider-horizontal {width:90%; margin:25px auto; *background:#eee; height:240px; z-index:1;}
.slider-horizontal .item {height:200px; width:150px; margin:20px 10px 0;}
.slider-horizontal .item img {height:200px; width:150px;}
.slider-vertical {width:364px; margin:25px 0; float:left; background:#eee; height:300px;}
.slider-vertical .item {height:80px; width:324px; margin:10px 0 10px 20px;}
.overlay { position: relative; top:-204px; left:0; *right:0; *bottom:0; width:150px; height:200px; z-index:2; display:block; *background:red; *background-color: rgba(0,0,0,0.5); color:#fff;}
.overlay:hover {background:rgba(48, 160, 186, 0.43) url("../default_images/play-button.png") no-repeat; background-position:50% 50%;}
.movie_quality {
position: absolute;
bottom: 5px;
left: 5px;
text-transform:uppercase;
}
.hd {background:#B43104; padding:2px; border-radius:2px;}
.cam {background:#DBA901; padding:2px; border-radius:2px;}
.year {background:#086A87; padding:2px; border-radius:2px;}
.movie_year {
position: absolute;
bottom: 5px;
right: 5px;
}
and below is the HTML to echo out the result
<div class="recent_movie_lists">
<div id="slider" class="slider-horizontal">
<?php echo $movie_lists; ?>
</div>
</div>
Try setting this: $movie_lists = (all your code); instead of $movie_lists .= (all your code).
Sorry for all the stuff above, as allready answered in the comments. Why don't you just echo out the while loop in your div?
<div class="recent_movie_lists">
<div id="slider" class="slider-horizontal">
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
//echo "id: " . $row["id"]. " - Name: " . $row["movie_name"]. " " . $row["movie_quality"]. "<br>";
$id = $row["id"];
$movie_quality = $row["movie_quality"];
$release_date = strftime("%Y", strtotime($row["movie_release_date"]));
echo "<div class='item item-1'><a href='#'><img src='inventory_images/$id.jpg'/></a>
<a href='#'><div class='overlay'>
<p class='movie_quality $movie_quality'>$movie_quality</p>
<p class='movie_year year'>$release_date</p>
</div></a>
</div>";
}
} else {
echo "";
}
?>
</div>
</div>
As I'm assuming your keeping the HTML and PHP in the same file.

Keep values in input fields - php array

I have a php array that includes inputs for posting. It uses a counter for each array record, and this counter is applied to the name of the input to be used in performing some actions with the post - this is working great.
The issue is that I would like to keep the users' existing inputs and re-populate the input fields in the array if their post doesn't pass validation.
I have done this before with static fields, simply storing the post variable and echoing it in the "value" --- but I can't figure out how to do this when working with an array. Anyone have any ideas?
$counter = 0;
echo "<form method='post'>";
echo "<table class='mainlist' width='680'>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr height='60'>";
echo "<td class='mainlist'><input type=text name=options[$counter] autocomplete=off onclick='this.select()' class='txt'></td>";
echo "</tr>";
$counter = $counter + 1;
}
echo "</table>";
Full code per request:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$userid = $_SESSION['login_user'];
$companyid = $_POST['companyid'];
$options = $_POST['options'];
$counter = $_POST['hiddencounter'];
$runningtotal=0;
$totaloptions = array_sum($options);
$result = mysqli_query($connection, "SELECT options_balance FROM user_options_balance WHERE user_id = '".$userid."'");
for ($i=0; $i<$counter; $i++)
{
if(empty($options[$i]))
{ /* IF NO INPUT ON OPTIONS */
/* DO NOTHING */
}
else
{
$checknewcompanies = mysqli_query($connection, "SELECT company_id FROM user_company_total_invested WHERE user_id = '".$userid."' and company_id = '" .$companyid[$i]."'");
if($checknewcompanies->num_rows == 1)
{ // do nothing
}
else
{
$runningtotal = $runningtotal + 1;
}
} /* END OF ELSE IF NOT EMPTY OPTIONS */
} /* END OF FOR LOOP */
$checkcurrentcompanies = mysqli_query($connection, "SELECT company_id FROM user_company_total_invested WHERE user_id = '".$userid."'");
$countcompanies = $checkcurrentcompanies->num_rows;
$countcheck = $runningtotal + $countcompanies;
if($countcheck <= 4)
{
while($row = mysqli_fetch_array($result))
{
$balance = $row['options_balance'];
}
if ($totaloptions>$balance)
{
$notenoughoptions= "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! You don't have enough options! Try investing less!</div>";
}
else
{
// loop through array
for ($i=0; $i<$counter; $i++)
{
if(empty($options[$i])){ /* IF NO INPUT ON OPTIONS */
/* DO NOTHING */
}
else {
if(!ctype_digit($options[$i]) or !is_numeric($options[$i])){
$charactercheck= "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! Please enter only positive numbers to invest!</div>";
}
else {
$checkcompanies = mysqli_query($connection, "SELECT company_id FROM company_main WHERE company_id = '".$companyid[$i]."'");
if($checkcompanies->num_rows != 1)
{
$companynotexist= "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! That company doesn't exist!</div>";
}
else
{
// loop through array
for ($i=0; $i<$counter; $i++)
{
if(empty($options[$i]))
{ /* IF NO INPUT ON OPTIONS */
/* DO NOTHING */
}
else
{
$query = "INSERT INTO user_company_invested(user_id, company_id, user_company_options_invested)
VALUES($userid,$companyid[$i],$options[$i])";
mysqli_query($connection, $query);
} /* END OF ELSE IF NOT EMPTY OPTIONS */
} /* END OF FOR LOOP */
$balancecheck = mysqli_query($connection, "SELECT options_balance FROM user_options_balance WHERE user_id = '".$userid."'");
while($row = mysqli_fetch_array($balancecheck))
{
$balance2 = $row['options_balance'];
}
if($balance2 > 0)
{
header('Location: user_invest.php');
}
else
{
header('Location: user_market.php');
}
} // end company check
} //end character check
} //end empty option check
} //end loop
} /* END OF NOT ENOUGH OPTIONS CHECK */
}
else
{
$toomanycompanies = "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! You can invest in a maximum of 4 companies per week. Please choose fewer companies, or invest more in some of your existing companies!</div>";
/* echo "Maximum number of companies you can invest in is 4";
echo "<br />";
echo "Companies you already are invested in: ".$countcompanies;
echo "<br />";
echo "New companies you are trying to invest in: ".$runningtotal;
echo "<br />";
echo "Total: ".$countcheck;*/
}
} /* END OF ISSET CHECK */
else
{
}
?>
<?php
$result = mysqli_query($connection,"SELECT * from company_main");
$counter=0;
echo "<form method='post'>";
echo "<table class='mainlist' width='680'>";
while($row = mysqli_fetch_array($result))
{
echo "<tr height='60'>";
echo "<td class='mainlist' width=140 align='center'>" . "<img src='".$row['company_logo']."' width='40'/>" . "</td>";
echo "<td class='mainlist' align='left' width=390 style='font-size: 15px;'>" . $row['company_name'] . "</td>";
echo "<input type=hidden name=companyid[$counter] value=" . $row['company_id'] . " />";
echo "<td class='mainlist'><input value='{$_POST['options[$counter]']}' type=text name=options[$counter] autocomplete=off onclick='this.select()' class='txt' style=' background-color: #FCFCFC;
border: solid 1px #CCCCCC;
font-size: 12px;
padding: 5px;
height: 20px;
text-align: right;'></td>";
echo "</tr>";
$counter=$counter+1;
}
echo "</table>";
echo "<input type='hidden' name='hiddencounter' value='$counter'>";
echo "
<table>
<tr>
<td width='630' height='50'></td>
<td align='right' width='60' style='color: #848580; font-size: 20px;'>Total: </td>
<td align='right' width='40' style='color: #94D90B; font-size: 20px; font-weight: bold; padding-right:20px;'><span id='sum'>0</span></td><td width='10'></td>
</tr><tr height='20px'></tr><tr>
<td width='570' align='center' style='color: #94D90B; font-size: 12px;'>";?>
<?php echo $notenoughoptions; ?>
<?php echo $charactercheck; ?>
<?php echo $toomanycompanies; ?>
<?php echo "
</td>
<td colspan='2' width='100' align='right'><input name='userinvestoptionsdynamic' type='submit' value='Invest!'></td><td width='10'></td>
</tr>
<tr height='20px'></tr>
</table>";
echo "</form>";
?>
The correct syntax is:
echo "{$arrayname($keyname)}";
So for example echo('value=' . $_POST['options'][$counter]); becomes:
echo "value={$_POST['options'][$counter]}";

The first result of search term did not come out

Why always do the first result of my search term will not come out?
I noticed that it will only appear when I navigate to the page number 0.
How can I solve this?
I hope that when I navigate to page number 1, the first result will come out too!
PHP Code:
<?php
//php code goes here
include 'connect.php'; // for database connection
include 'script_suggestion.php';
include 'script_close_suggestion_box.php';
$query = $_GET['q']; // query
$button = $_GET ['submit'];
if (isset($_GET['page'])) {
$page_number = (int)$_GET['page'];
$page_number = mysqli_real_escape_string($page_number);
} else {
$page_number = 1;
}
$results_per_page = 10;
?>
HTML Code:
<html>
<head>
<title>
Brandon's Search Engine
</title>
<style type="text/css">
#title a {
font-size: 17pt;
margin: 5px;
padding: 2px;
border-color: black;
text-decoration: underline;
width: 544px;
}
#search-result {
display: block;
border: 1px solid grey;
border-color: grey;
}
#search-result:hover {
background-color: #dddddd;
width: 544px;
}
#link {
font-size: 17pt;
margin: 5px;
padding: 2px;
width: 544px;
}
#description {
font-size: 17pt;
margin: 5px;
padding: 2px;
width: 544px;
}
#search-page-number {
display: block;
width: auto;
height: auto;
border: 1px solid gray;
margin: 2px;
padding-left: 5px;
padding-right: 5px;
padding-bottom: 2px;
padding-top: 2px;
list-style: none;
float: left;
text-align: center;
}
#search-page-number:hover {
background-color: #dddddd;
}
#suggestion {
border: 1px solid black;
visibility: hidden;
position: absolute;
background-color: white;
z-index: 10;
}
#suggestion a {
font-size: 12pt;
color: black;
text-decoration: none;
display: block;
width: 548px;
height: auto;
text-align: left;
padding: 2px;
}
#suggestion a:hover {
background-color: #dddddd;
width: 544px;
padding: 2px;
}
</style>
</head>
<body>
<form method="GET" action="search.php">
<table>
<tr>
<td>
<h2>
Brandon's Search Engine
</h2>
</td>
</tr>
<tr>
<td>
<input type="text" value="<?php echo htmlspecialchars($_GET['q']); ?>" name="q" style="height: 27px; width: 550px; padding: 2px" name="q"
onkeyup="getSuggestion(this.value)" autocomplete="off" onblur="closeBox()" placeholder="Search Now"/>
<input type="submit" value="Search" style="height: auto; width: 60px; padding: 2px" />
<div id="suggestion" style="width: 548px">
</div>
</td>
</tr>
</table>
<br>
<hr>
<table>
<tr>
<td>
<?php
//count
$count_sql = "SELECT count(*) as c FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR keywords LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' ";
$search_count = mysqli_fetch_array(mysqli_query($con,$count_sql));
$number_of_result = $search_count['c'];
//SQL query
$page_number = (int)$_GET['page'];
$stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR keywords LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' LIMIT " . $page_number . " , $results_per_page";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
//$number_of_result = mysqli_num_rows($result);
if ($number_of_result < 1) {
echo "<b>No results found!</b>";
echo "<p>";
echo "Your search - <b>$query</b>" . " - did not match any documents. Please try different keywords.";
}
elseif ($number_of_result > 1) {
echo "<b>$number_of_result results found!</b>";
echo "<p>";
//results found here and display them
while (($row = \mysqli_fetch_array($result))) {//10 results per page
$title = $row["title"];
$description = $row["description"];
$link = $row["link"];
echo "<div id='search-result'>";
echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
//echo "<br />";
echo "<div id='link'><small>" . $link . "</small></div>";
//echo "<p>";
echo "<div id='description'><small>" . $description . "</small></div>";
echo "</div>";
echo "<br />";
}
}
elseif ($number_of_result == 1) {
echo "<b>$number_of_result result found!</b>";
echo "<p>";
//results found here and display them
while (($row = \mysqli_fetch_array($result))) {//10 results per page
$title = $row["title"];
$description = $row["description"];
$link = $row["link"];
echo "<div id='search-result'>";
echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
//echo "<br />";
echo "<div id='link'><small>" . $link . "</small></div>";
echo "<br />";
echo "<div id='description'><small>" . $description . "</small></div>";
echo "</div>";
echo "<br />";
}
}
?>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="page" value="<?php echo 1; ?>" />
<div id="page-number">
<?php
$max_page_number = ceil($number_of_result / $results_per_page);
if ($number_of_result == 0) {
echo " ";
}
elseif ($number_of_result != 0) {
echo "You are on page $page_number of $max_page_number.";
}
//ie if 35 results are therer then we require 4 pages that are 0 to max_page_number
//current page number is equal to page_number
//echo $max_page_number;
echo "<ul>";
//both the condition are not the neccesary
if ($max_page_number >= 1) { // if more than 2 pages
if ($page_number != 1) { //First
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=1>First</a>";
echo "</li>";
}
if ($page_number != 1) { //Previous
echo "<li id='search-page-number'>";
$prev = $page_number - 1;
echo "Previous";
echo "</li>";
}
for($index = 1 ; $index <= $max_page_number ; $index++) {
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=".($index).">";
echo ($index) . "</a>";
echo "</li>";
}
if ($page_number != $max_page_number) { //Next
echo "<li id='search-page-number'>";
$next = $page_number + 1;
echo "Next";
echo "</li>";
}
if ($page_number != $max_page_number) { //Last
echo "<li id='search-page-number'>";
echo "Last";
echo "</li>";
}
} elseif (($max_page_number == 1 ) ) {
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=1>1</a>";
echo "</li>";
}
echo "</ul>";
?>
</div>
</td>
</tr>
<tr>
<td align="center">
To insert your site in result fill in the form at here.
</td>
</tr>
</table>
</form>
</body>
</html>
Your query ends with:
"LIMIT " . $page_number . ", $results_per_page"
But that's not how the LIMIT clause works in SQL. It's defined to be:
LIMIT offset, row_count
offset is a row number, starting from 0. So if you do:
LIMIT 1, 10
You'll get records 2 through 11, not 1 through 10. The correct way to do it is:
"LIMIT " . ($page_number-1)*$results_per_page . ", $results_per_page"
Something else you should find useful is the SQL_CALC_FOUND_ROWS option to the SELECT statement. This tells MySQL to calculate how many total rows matched the criteria, even though you used LIMIT to return just a subset. This way you don't have to do two queries, one with COUNT(*) and another to get a page of data. After doing a query with this option, you can use SELECT FOUND_ROWS() to get the full count.
$safequery = mysqli_real_escape_string($con,$query);
$stmt = "SELECT SQL_CALC_FOUND_ROWS *
FROM searchengine
WHERE title LIKE '%" . $safequery . "%'
OR keywords LIKE '%" . $safequery . "%'
OR link LIKE '%" . $safequery . "%'
LIMIT " . ($page_number-1)*results_per_page . " , $results_per_page";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
$count_sql = "SELECT FOUND_ROWS() AS c";
$search_count = mysqli_fetch_array(mysqli_query($con,$count_sql));
$number_of_result = $search_count['c'];

How do I pass variable from a form to javascript popup form?

I have a form with a button which opens a javascript/css popup window. On the popup window I have a textarea which will be used to add a comment to a database field. The problem is that I need to pass it a value from the main page (the one that calls the popup) which will identify which entry in the database to update. But I am stuck trying to get it to work. Here is my code. I need to have the variable sent to the update.php page. Please help.
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
if(isset($_GET['sort']) && isset($_GET['col']) ){
$order = $_GET['sort'];
$column = $_GET['col'];
}
else{
$order = 'ASC';
$column = 'cron_id';
}
$page = 'Testing Site';
require_once('includes/head.php');
require_once('includes/mysql.php');
require_once('includes/class.tdcron.php');
require_once('includes/class.tdcron.entry.php');
date_default_timezone_set('America/Los_Angeles');
$result = mysql_query("SELECT * FROM cron WHERE active=1 ORDER BY $column $order") or die (mysql_error());
mysql_close();
$pass = "<img src='images/Checked.png' alt='Pass' width='16' height='16'/>";
$fail = "<img src='images/Stop.png' alt='Failed' width='16' height='16'/>";
$warn = "<img src='images/Warning.png' alt='Warning' width='16' height='16' />";
$com = "<img src='images/pencil.png' alt='Warning' width='16' height='16' />";
echo "<div id='tableContainer' class='tableContainer'>";
echo "<table width='100%' border='0' padding='0' cellpadding='0' cellspacing='0' class='scrollTable'>";
echo "<thead class='fixedHeader'>";
echo "<tr>";
if ($order=="ASC") { echo "<th>Status</th>"; }
else { echo "<th>Status</th>"; }
echo '<th>Schedule</th>';
if ($order=="ASC") { echo "<th>Job</th>"; }
else { echo "<th>Job</th>"; }
echo '<th>Description</th>';
if ($order=="ASC") { echo "<th>Destination</th>"; }
else { echo "<th>Destination</th>"; }
echo '<th>Errors</th>';
if ($order=="ASC") { echo "<th>Job Type</th>"; }
else { echo "<th>Job Type</th>"; }
if ($order=="ASC") { echo "<th>Category</th>"; }
else { echo "<th>Category</th>"; }
if ($order=="ASC") { echo "<th>Last Ran</th>"; }
else { echo "<th>Last Ran</th>"; }
echo '<th>Next Run</th>';
echo '<th>Log</th>';
echo '</tr></thead><tbody class="scrollContent">';
while($row = mysql_fetch_array($result)){
if($row['ok'] == 1){$status = $pass;}
elseif($row['ok'] == 0){$status = $fail;}
else{$status = $warn;}
echo '<tr>';
echo
'<td>
**<form name="frm_comment" action="" onsubmit="return false;" >' . $status . ' ' .
'<input type="image" src="images/pencil.png" onclick="popup_show(\'popup\', \'popup_drag\', \'popup_exit\', \'mouse\', -10, -5);" width=\'16\' height=\'16\' />
</form>**
</td>';
echo '<td>' . $row['schedule'] . '</td>';
echo '<td>' . $row['job'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['destination'] . '</td>';
echo '<td>' . $row['errormsgs'] . '</td>';
echo '<td>' . $row['jobtype'] . '</td>';
echo '<td>' . $row['catagory'] . '</td>';
echo '<td>' . date('D M d # g:i A', $row['ran_at']) . '</td>';
echo '<td>' . date('D M d # g:i A', tdCron::getNextOccurrence($row['mhdmd'])) . '</td>';
echo "<td><a href='log/" . $row['log'] . "' target='_blank' >View Log</a></td>";
echo '</tr>';
}
echo '</tbody>';
echo "</table>";
echo "</div>";
// ***** Popup Window ****************************************************
echo'<div class="sample_popup" id="popup" style="display: none;">
<div class="menu_form_header" id="popup_drag">
<img class="menu_form_exit" id="popup_exit" src="images/form_exit.png" alt="Close Form" /> Comments
</div>
<div class="menu_form_body">
<form name="up" action="update.php" onsubmit="return validateForm()" method="post" >
<input type="hidden" name="' . $row['job'] . '" />
<table>
<tr>
<td><textarea class="field" onfucus="select();" name="comment" rows="8" cols="44"></textarea>
</tr>
<tr>
<td align="right" ><br /><input class="btn" type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
</div>';
require_once('includes/footer.php');
?>
Javascript code start
// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Re-distribute this code or any part of it.
// Instead, you may link to the homepage of this code:
// http://www.php-development.ru/javascripts/popup-window.php
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as part of another product.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind.
// You expressly acknowledge and agree that use of this code is at your own risk.
// USAGE
//
// function popup_show(id, drag_id, exit_id, position, x, y, position_id)
//
// id - id of a popup window;
// drag_id - id of an element within popup window intended for dragging it
// exit_id - id of an element within popup window intended for hiding it
// position - positioning type:
// "element", "element-right", "element-bottom", "mouse",
// "screen-top-left", "screen-center", "screen-bottom-right"
// x, y - offset
// position_id - id of an element relative to which popup window will be positioned
// ***** Variables *************************************************************
var popup_dragging = false;
var popup_target;
var popup_mouseX;
var popup_mouseY;
var popup_mouseposX;
var popup_mouseposY;
var popup_oldfunction;
// ***** popup_mousedown *******************************************************
function popup_mousedown(e)
{
var ie = navigator.appName == "Microsoft Internet Explorer";
popup_mouseposX = ie ? window.event.clientX : e.clientX;
popup_mouseposY = ie ? window.event.clientY : e.clientY;
}
// ***** popup_mousedown_window ************************************************
function popup_mousedown_window(e)
{
var ie = navigator.appName == "Microsoft Internet Explorer";
if ( ie && window.event.button != 1) return;
if (!ie && e.button != 0) return;
popup_dragging = true;
popup_target = this['target'];
popup_mouseX = ie ? window.event.clientX : e.clientX;
popup_mouseY = ie ? window.event.clientY : e.clientY;
if (ie)
popup_oldfunction = document.onselectstart;
else popup_oldfunction = document.onmousedown;
if (ie)
document.onselectstart = new Function("return false;");
else document.onmousedown = new Function("return false;");
}
// ***** popup_mousemove *******************************************************
function popup_mousemove(e)
{
var ie = navigator.appName == "Microsoft Internet Explorer";
var element = document.getElementById(popup_target);
var mouseX = ie ? window.event.clientX : e.clientX;
var mouseY = ie ? window.event.clientY : e.clientY;
if (!popup_dragging) return;
element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px';
element.style.top = (element.offsetTop +mouseY-popup_mouseY)+'px';
popup_mouseX = ie ? window.event.clientX : e.clientX;
popup_mouseY = ie ? window.event.clientY : e.clientY;
}
// ***** popup_mouseup *********************************************************
function popup_mouseup(e)
{
var ie = navigator.appName == "Microsoft Internet Explorer";
var element = document.getElementById(popup_target);
if (!popup_dragging) return;
popup_dragging = false;
if (ie)
document.onselectstart = popup_oldfunction;
else document.onmousedown = popup_oldfunction;
}
// ***** popup_exit ************************************************************
function popup_exit(e)
{
var ie = navigator.appName == "Microsoft Internet Explorer";
var element = document.getElementById(popup_target);
popup_mouseup(e);
element.style.display = 'none';
}
// ***** popup_show ************************************************************
function popup_show(id, drag_id, exit_id, position, x, y, position_id)
{
var element = document.getElementById(id);
var drag_element = document.getElementById(drag_id);
var exit_element = document.getElementById(exit_id);
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
element.style.position = "absolute";
element.style.display = "block";
if (position == "element" || position == "element-right" || position == "element-bottom")
{
var position_element = document.getElementById(position_id);
for (var p = position_element; p; p = p.offsetParent)
if (p.style.position != 'absolute')
{
x += p.offsetLeft;
y += p.offsetTop;
}
if (position == "element-right" ) x += position_element.clientWidth;
if (position == "element-bottom") y += position_element.clientHeight;
element.style.left = x+'px';
element.style.top = y+'px';
}
if (position == "mouse")
{
element.style.left = (document.documentElement.scrollLeft+popup_mouseposX+x)+'px';
element.style.top = (document.documentElement.scrollTop +popup_mouseposY+y)+'px';
}
if (position == "screen-top-left")
{
element.style.left = (document.documentElement.scrollLeft+x)+'px';
element.style.top = (document.documentElement.scrollTop +y)+'px';
}
if (position == "screen-center")
{
element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )/2+x)+'px';
element.style.top = (document.documentElement.scrollTop +(height-element.clientHeight)/2+y)+'px';
}
if (position == "screen-bottom-right")
{
element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth ) +x)+'px';
element.style.top = (document.documentElement.scrollTop +(height-element.clientHeight) +y)+'px';
}
drag_element['target'] = id;
drag_element.onmousedown = popup_mousedown_window;
exit_element.onclick = popup_exit;
}
// ***** Attach Events *********************************************************
if (navigator.appName == "Microsoft Internet Explorer")
document.attachEvent ('onmousedown', popup_mousedown);
else document.addEventListener('mousedown', popup_mousedown, false);
if (navigator.appName == "Microsoft Internet Explorer")
document.attachEvent ('onmousemove', popup_mousemove);
else document.addEventListener('mousemove', popup_mousemove, false);
if (navigator.appName == "Microsoft Internet Explorer")
document.attachEvent ('onmouseup', popup_mouseup);
else document.addEventListener('mouseup', popup_mouseup, false);
END Javascript CODE
CSS Code Start
div.sample_popup { z-index: 1; }
div.sample_popup div.menu_form_header
{
border: 1px solid black;
border-bottom: none;
width: 400px;
height: 20px;
line-height: 19px;
vertical-align: middle;
background: url('../images/form_header.png') no-repeat;
text-decoration: none;
font-family: Times New Roman, Serif;
font-weight: 900;
font-size: 13px;
color: #FFFFFF; /*#206040;*/
cursor: default;
}
div.sample_popup div.menu_form_body
{
width: 400px;
height: 200px;
border: 1px solid black;
background: url('../images/form.png') no-repeat left bottom;
}
div.sample_popup img.menu_form_exit
{
float: right;
margin: 4px 5px 0px 0px;
cursor: pointer;
}
div.sample_popup table
{
width: 100%;
border-collapse: collapse;
}
div.sample_popup th
{
width: 1%;
padding: 0px 5px 1px 0px;
text-align: left;
font-family: Times New Roman, Serif;
font-weight: 900;
font-size: 13px;
color: #004060;
}
div.sample_popup td
{
width: 99%;
padding: 0px 0px 1px 0px;
}
div.sample_popup form
{
margin: 0px;
padding: 8px 10px 10px 10px;
}
div.sample_popup input.field
{
width: 95%;
border: 1px solid #808080;
font-family: Verdana, Sans-Serif;
font-size: 12px;
}
div.sample_popup input.btn
{
margin-top: 2px;
border: 1px solid #808080;
background-color: #DDFFDD;
font-family: Verdana, Sans-Serif;
font-size: 11px;
}
CSS CODE END
You're using a JS/CSS popup, so just pass $row['job'] in your call to popup_show() (assuming you are able to modify or overload that JS function), and then populate it in the hidden field of your popup HTML with Javascript. The way you're doing it now, you'd have to duplicate the block of Popup HTML once for each row in your resultset for it to work.

Categories