Without searching a value it displays no record - php

In this below code i am searching a value.if the value is searched it displays the result but if the value is not present it should displays no result. In my case if i execute and not search any value it displays no record .Please any one help me.
<form action="<?php echo site_url('search1_site/index');?>" method = "post">
<input type="text" name = "keyword" />
<input type="submit" id="opn" value = "Search" />
</form>
<?php
if($results){
?> <div id='hideme'>
CLOSE<a href='#' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a> <div style="background:#FFFFFF; width: 500px; height: 500px; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px" id="modal" >
<table class="display2 table table-bordered table-striped">
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo "no results";
}
?>
</table></div></div>
<script>
$('a.modal').bind('click', function(event) {
event.preventDefault();
$('#modal').fadeIn(10);
});
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
</script>

Try adding name attribute to your submit button and check if it's set before the if...else block.
<!-- HTML -->
<input type="submit" name="submit" id="opn" value = "Search" />
// PHP
<?php
if (isset($_POST['submit'])) { // Here
// Do the search here
if($results){
?> <div id='hideme'>
CLOSE<a href='#' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a> <div style="background:#FFFFFF; width: 500px; height: 500px; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px" id="modal" >
<table class="display2 table table-bordered table-striped">
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo "no results";
}
} // If closing
?>
Is this something similar to what you're looking for?

If the variable $results is array of results use something like this:
if (count($results) > 0)
{
// show results
} else
{
echo "No results";
}

Related

methode $_POST is empty php

The problem is $_POST["nomuniv"] & cod $_POST["coduniv"], they are empty and I do not understand why despite all of input names being correct.
webpage1:
<style type="text/css">
input[type=text],button{
width: 100%;padding: 12px 20px;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;`enter code here`
box-sizing: border-box;
}
::-webkit-input-placeholder {
font-size: 13px;
color: #000;
}
</style>
<?php
include 'fonctionUnivesrite.php';
$array = selectFCT();//selection data from DB
for ($i = 0; $i < count($array); $i++) {
?>
<form method="post" action="../universites/supprimer_universite.php?id=<?php echo $array[$i][0]; ?>">
<table class="table table-striped " style="width: 70%;" align="center">
<tr>
<td style="width: 5%;" ><?php echo $i; ?> </td>
<td style="width: 30%;">
<input type="text" name="nomuniv" id="nomuniv" placeholder="<?php echo $array[$i][1]; ?>">
</td>
<td style="width: 20%;">
<input type="text" name="coduniv" id="coduniv" placeholder="<?php echo $array[$i][2]; ?>" >
</td>
<td style="width: 10%;">
<input type="submit" name="modifier" class="btn btn-warning" value="Modifier">
</td>
<td style="width: 10%;">
<input type="submit" name="supprimer" class="btn btn-danger" value="Supprimer">
</td>
</tr>
<?php
}
?>
</table>
</form>
webpage2:../universites/supprimer_universite.php
include './fonctionUnivesrite.php';
if (isset($_GET["id"])) {
if(isset($_POST["modifier"])){
try {
echo $_GET["id"]." nom ".$_POST["nomuniv"]." cod ".$_POST["coduniv"];
modifierFCT($_GET["id"],$_POST["nomuniv"],$_POST["coduniv"]);
//echo $_GET["id"]." nom ".$_POST["nomuniv"]." cod ".$_POST["coduniv"];
} catch (Exception $exc) {
echo "Error : " . $exc->getMessage();
}
}
elseif(isset($_POST["supprimer"])) {
try {
deletFCT($_GET["id"]);
} catch (Exception $exc) {
echo "Error : " . $exc->getMessage();
}
}
}
Your problem is simple ,
You didnt add a value attribute to the input fileds ,
In webpage 1
Try to add inside
<input value=" your php code " />
Since when you use $_POST it will access the value , according to the name

While loop not displaying all results from query

I'm having problems showing all the results in my modal. There are three rows I want to display in the modal: Billing months for June 2016, May 2016, and April 2016, but only the latest(June 2016) will show. Here's the part of my code:
if(isset($_GET['id']))
{
$page_id = $_GET['id'];
$select_query = "SELECT * FROM billing_info INNER JOIN customer_login ON billing_info.account_no=customer_login.account_no WHERE billing_info.account_no='$page_id' ";
$run_query = mysqli_query($conn,$select_query);
while($row = mysqli_fetch_array($run_query))
{
$id = $row['user_id'];
$cust_fname = $row['cust_fname'];
$cust_mname = $row['cust_mname'];
$cust_lname = $row['cust_lname'];
$branch = $row['branch'];
$account_no = $row['account_no'];
$billing_month = $row['billing_month'];
$pres_reading = $row['pres_reading'];
$prev_reading = $row['prev_reading'];
$payment_status = $row['payment_status'];
$due_date = $row['due_date'];
$int_pres = intval($row["pres_reading"]);
$int_prev = intval($row["prev_reading"]);
$difference = $int_pres-$int_prev;
$payment = $difference*26.678;
$cust_fname = ucfirst($cust_fname);
$cust_mname = ucfirst($cust_mname);
$cust_lname = ucfirst($cust_lname);
$branch = ucfirst($branch);
?>
<div id="openModal" class="modalDialog" style="width:100%;">
<div id="form-sms" style="height: 500px; overflow: scroll;">
<div class="close"> X</div>
<form method="get" action="customer_view.php?id=<?php echo $id; ?>" name="id" enctype="multipart/form-data">
<table width="100%" bgcolor="white" align="center">
<style type="text/css">
td.hundred{
width: 80%;
text-align: center;
}
input {
width: 100%;
}
input[type="text"]{
width: 90%;
text-align: left;
}
input[type="submit"]{
width: 100%;
text-align: center;
}
textarea{
width: 90%;
text-align: left;
margin-left: 10%;
}
td {
padding: 10px;
}
.tdhover:hover {
color: #AFEEEE;
}
</style>
<tr >
<td align="center" colspan="10"><h1><?php echo $cust_fname." ".$cust_mname." ".$cust_lname." - ".$account_no." - ".$branch." Details" ?></h1></td>
</tr>
<tr bgcolor="#20B2AA">
<th>Billing Month</th>
<th>Present Reading</th>
<th>Previous Reading</th>
<th>Payment</th>
<th>Status</th>
<th>Due Date</th>
<th>Water Usage (in m<sup>3</sup>)</th>
<th>Edit</th>
</tr>
<tr bgcolor="#AFEEEE">
<td><?php echo $billing_month; ?></td>
<td><?php echo $pres_reading; ?></td>
<td><?php echo $prev_reading; ?></td>
<td><?php echo "Php " . $payment; ?></td>
<td><?php echo $payment_status; ?></td>
<td><?php echo $due_date; ?></td>
<td><?php echo $difference; ?></td>
<td>Edit</td>
</tr>
<tr style="margin-top: 10px;">
<td bgcolor="#20B2AA" align="center" class="tdhover" colspan="10">Add Billing Information</td>
</tr>
</table>
</form>
</style>
</table>
</form>
</div>
</div>
<?php } }?>
You should loop/parse the data only for <tr> and <td> Not for all tag like <table> and <div> outer the table. Html will loop all of inside { ... } sign.
Then, your style code should be placed the upper (not fix with html/php). This your code should be:
<style type="text/css">
td.hundred{
width: 80%;
text-align: center;
}
input {
width: 100%;
}
input[type="text"]{
width: 90%;
text-align: left;
}
input[type="submit"]{
width: 100%;
text-align: center;
}
textarea{
width: 90%;
text-align: left;
margin-left: 10%;
}
td {
padding: 10px;
}
.tdhover:hover {
color: #AFEEEE;
}
</style>
<?php
if (isset($_GET['id'])) {//open the isset
$page_id = $_GET['id'];
$select_query = "SELECT * FROM billing_info INNER JOIN customer_login ON billing_info.account_no=customer_login.account_no WHERE billing_info.account_no='$page_id' ";
$run_query = mysqli_query($conn, $select_query);
?>
<div id="openModal" class="modalDialog" style="width:100%;">
<div id="form-sms" style="height: 500px; overflow: scroll;">
<div class="close"> X</div>
<form method="get" action="customer_view.php?id=<?php echo $id; ?>" name="id" enctype="multipart/form-data">
<table width="100%" bgcolor="white" align="center">
<?php
while ($row = mysqli_fetch_array($run_query)) { //open the while
$id = $row['user_id'];
$cust_fname = $row['cust_fname'];
$cust_mname = $row['cust_mname'];
$cust_lname = $row['cust_lname'];
$branch = $row['branch'];
$account_no = $row['account_no'];
$billing_month = $row['billing_month'];
$pres_reading = $row['pres_reading'];
$prev_reading = $row['prev_reading'];
$payment_status = $row['payment_status'];
$due_date = $row['due_date'];
$int_pres = intval($row["pres_reading"]);
$int_prev = intval($row["prev_reading"]);
$difference = $int_pres - $int_prev;
$payment = $difference * 26.678;
$cust_fname = ucfirst($cust_fname);
$cust_mname = ucfirst($cust_mname);
$cust_lname = ucfirst($cust_lname);
$branch = ucfirst($branch);
?>
<tr >
<td align="center" colspan="10"><h1><?php echo $cust_fname . " " . $cust_mname . " " . $cust_lname . " - " . $account_no . " - " . $branch . " Details" ?></h1></td>
</tr>
<tr bgcolor="#20B2AA">
<th>Billing Month</th>
<th>Present Reading</th>
<th>Previous Reading</th>
<th>Payment</th>
<th>Status</th>
<th>Due Date</th>
<th>Water Usage (in m<sup>3</sup>)</th>
<th>Edit</th>
</tr>
<tr bgcolor="#AFEEEE">
<td><?php echo $billing_month; ?></td>
<td><?php echo $pres_reading; ?></td>
<td><?php echo $prev_reading; ?></td>
<td><?php echo "Php " . $payment; ?></td>
<td><?php echo $payment_status; ?></td>
<td><?php echo $due_date; ?></td>
<td><?php echo $difference; ?></td>
<td>Edit</td>
</tr>
<tr style="margin-top: 10px;">
<td bgcolor="#20B2AA" align="center" class="tdhover" colspan="10">Add Billing Information</td>
</tr>
<?php } //while closing
?>
</table>
</form>
</style>
</table>
</form>
</div>
</div>
Hopefully it will be success for you ;)

Submiting form without refreshing a page

I have multiple divs , show/hide on button click div , inside one of these divs I have a table and to filter this table to search a specific user I use a PHP code and a submit form the problem is after submitting the form the page refreshes and the 1st div appears although the request worked and when I revisit the table div the filtering appears. I used this code to stop the refresh but the form is not being submitted:
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('#myform').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'admin.php',
data: $('#myform').serialize(),
success: function () {
alert('table is filtered');
}
});
});
});
</script>
and here is my form:
<div class="in5 n5" id="users">
<br>
<form method="post" action="" id="myform" >
<table style="width:25%;height: 13%;table-layout: fixed; font-family: signika;background-color:white;color:white;border-bottom:1px solid white;">
<tr>
<td width="30%" style="text-align:center;">
<button style="width:100%;height: 100%;border:0; font-size: 20px;font-family: signika;background: transparent;">Show all</button>
</td>
<td>
<div style="height:100%;width: 100%;">
<input type="text" name="valueToSearch" placeholder="Search user" style="height:100%;width: 70%; font-size: 20px;" >
<input value="Search" id="search" name="search" type="submit" style="width:30%; height: 100%; float: right; background-color: gray; color:white; font-size: 20px; ">
</div>
</td>
</tr>
</table>
<table style="width:100%;height:10%; background-color: white; font-size: 20px; border-bottom: 1px solid #cccccc; table-layout: fixed;border-collapse: collapse;">
<tr>
<td style="width:3%;">ID</td>
<td style="width:10%;">Username</td>
<td style="width:10%;">Email</td>
<td style="width:10%;">First name</td>
<td style="width:10%;">Last name</td>
<td style="width:5%;">Gender</td>
<td style="width:10%;">Birthday</td>
<td style="width:8%;">Country</td>
<td style="width:7%;">City</td>
<td style="width:10%;">Bio</td>
<td style="width:5%;">Access</td>
<td style="width:7%;">Picture</td>
<td style="width:5%;">Ban user</td>
</tr>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr >
<td style="width:3%; overflow: hidden;" title="<?php echo $row[0]; ?>">
<input style="border:0;background: transparent; font-size: 20px;" readonly="readonly" name="id" value="<?php echo $row[0]; ?>">
</td>
<td style="width:10%; overflow: hidden;" title="<?php echo $row[1]; ?>"><?php echo $row[1]; ?></td>
<td style="width:10%; overflow: hidden;" title="<?php echo $row[2]; ?>"><?php echo $row[2]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[4]; ?>"><?php echo $row[4]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[5]; ?>"><?php echo $row[5]; ?></td>
<td style="width:5%; overflow: hidden;"title="<?php echo $row[6]; ?>"><?php echo $row[6]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[7]; ?>"><?php echo $row[7]; ?></td>
<td style="width:8%; overflow: hidden;"title="<?php echo $row[8]; ?>"><?php echo $row[8]; ?></td>
<td style="width:7%; overflow: hidden;"title="<?php echo $row[9]; ?>"><?php echo $row[9]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[11]; ?>"><?php echo $row[11]; ?></td>
<td style="width:5%; overflow: hidden;">
<?php if($row['12']=="moderate"){ ?>
<a href="lock.php?id=<?php echo $row[0]; ?>">
<img class="img2" src="icons/access.png" ></a>
<?php } else{ ?>
<a href="access.php?id=<?php echo $row[0]; ?>">
<img class="img2" src="icons/locked.png" >
</a> <?php } ?>
</td>
<td style="width:7%; overflow: hidden;">
<a href="#image" title="See profile picture" class="cover" >
<?php if($row[10]==""){ ?>
<img class="cimg2 " src="images/profile.png"> <?php
} else { ?>
<img class="cimg2 " src="img/<?php echo $row[10] ?>" >
<?php }?>
</a>
</td>
<td style="width:5%; overflow: hidden;">
<a title="Delete user" href="deleteuser.php?id=<?php echo $row[0]; ?>" style="border:0;background: transparent;">
<img src="icons/ban.png"></a></td>
</tr>
<?php endwhile;?>
</table>
</form>
and the PHP code:
<?
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `r` WHERE CONCAT(`id`, `username`,`email`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `r`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "x");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
the problem is on submit the page is not refreshing and the alert appears but also the table is not filtering.
Use on click not on submit and input type button
$('#myform').on('click', function (e) {
Oops! You missed a concept also ! When using ajax you need to manipulate your DOM(Document Object Model) by yourself on callback functions
You are missing return false; at the end of submit event. The form submit event when customized and e.preventDefault() is used then your implementation overrides the default behavior thus it needs to tell the form if it needs to submit the whole page or not.
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('#myform').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'admin.php',
data: $('#myform').serialize(),
success: function () {
//filter the table using javascript code by changing the elements etc.
alert('table is filtered');
}
});
return false;
});
});
</script>
If this not works then there must be some uncertainty like there may be some **runtime error ** which is preventing your script to propagate.

Change cursor style when drag and drop in css

I make a drag and drop on image sorting, the code work very well, but now client want that when a user Drag row the cursor style is a "pointer".
Now default cursor style is "move". I change every where in css but in vain, no changing happen.
Can any one help with css.
Any suggestions.
Here is my code
<table class="widefat fixed" cellspacing="0" id="image_sort" style="width:100%; table-layout:inherit;">
<thead>
<tr>
<th scope="col" class="column-slug"><?php _e('Image','lgs') ?></th>
<th scope="col"><?php _e('Image Links To','lgs') ?></th>
<th scope="col" class="column-slug"><?php _e('Actions','lgs') ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="col" class="column-slug"><?php _e('Image','lgs') ?></th>
<th scope="col"><?php _e('Image Links To','lgs') ?></th>
<th scope="col" class="column-slug"><?php _e('Actions','lgs') ?></th>
</tr>
</tfoot>
<tbody>
<form method="post" action="options.php">
<?php settings_fields('wp_logo_slider_images'); ?>
<?php foreach((array)$wp_logo_slider_images as $image => $data) : ?>
<tr id="list_item_<?php echo $image ?>" class="list_item">
<input type="hidden" name="wp_logo_slider_images[<?php echo $image; ?>][id]" value="<?php echo $data['id']; ?>" />
<input type="hidden" name="wp_logo_slider_images[<?php echo $image; ?>][file]" value="<?php echo $data['file']; ?>" />
<input type="hidden" name="wp_logo_slider_images[<?php echo $image; ?>][file_url]" value="<?php echo $data['file_url']; ?>" />
<input type="hidden" name="wp_logo_slider_images[<?php echo $image; ?>][thumbnail]" value="<?php //echo $data['thumbnail']; ?>" />
<input type="hidden" name="wp_logo_slider_images[<?php echo $image; ?>][thumbnail_url]" value="<?php echo $data['thumbnail_url']; ?>" />
<th scope="row" class="column-slug"><img src="<?php echo $data['thumbnail_url']; ?>" /></th>
<td><?php //echo $image; ?><input type="text" name="wp_logo_slider_images[<?php echo $image; ?>][image_links_to]" value="<?php echo $data['image_links_to']; ?>" size="30" /></td>
<td class="column-slug"><input type="submit" class="button-primary" value="Update" /> Delete</td>
</tr>
<?php endforeach; ?>
<input type="hidden" name="wp_logo_slider_images[update]" value="Updated" />
</form>
</tbody>
</table>
<?php
function image_sort(){
wp_enqueue_script('jquery');
?>
<!--<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>-->
<?php
wp_enqueue_script('jquery-ui-sortable');
?>
<script type="text/javascript">
jQuery(document).ready( function(e) {
jQuery('#image_sort').sortable({
items: '.list_item',
opacity: 0.5,
cursor: 'move',
axis: 'y',
update: function() {
var ordr = jQuery(this).sortable('serialize') + '&action=list_update_order';
jQuery.post(ajaxurl, ordr, function(response){
//alert(response);
});
}
});
});
</script>
<?php
}
add_action('admin_head','image_sort');
function order_list(){
global $wp_logo_slider_images;
$list = $wp_logo_slider_images;
$new_order = $_POST['list_item'];
$new_list = array();
foreach($new_order as $v){
if(isset($list[$v])){
$new_list[$v] = $list[$v];
}
}
update_option('wp_logo_slider_images',$new_list);
}
add_action('wp_ajax_list_update_order','order_list');
?>
This can be done using :active pseudo class.
div{
width: 300px;
height: 300px;
background-color: cornflowerblue;
}
div:active{
cursor: pointer !important;
}
Working Fiddle
Why you can't Use jQuery. To change cursor style
Using jQuery
check this jsFiddle
jQuery(document).ready(function(){
jQuery('a.clickme').click(function(){
jQuery('body').css('cursor', 'pointer');
$(this).css('cursor', 'pointer');
});
});
Using CSS
check this jsFiddle
HTML
<div>
Link1<br />
Link2<br />
Link2 <br />
</div>
CSS
div{
width: 200px;
height:100px;
border:1px solid #000;
}
div:hover, div:active{
cursor: pointer;
}

Passing value inside JavaScript function and saving it into a PHP variable

I am creating an application like that of Facebook photo albums having comments.
I have a webpage, which shows the pics inside an album, when a pic is clicked, a lightbox opens up, and the caption and comments on the pic will be shown. Here's the pictures.php code
<?php
session_start();
ob_start;
include('connection.php');
?>
<html>
<head>
<title>Photos</title>
<style type="text/css">
.wraptocenter
{
width: 200px;
height: 150px;
overflow: hidden;
}
.wraptocenter img
{
vertical-align: top;
}
.black_overlay
{
display: none;
position: fixed;
top: 0%;
left: 0%;
width: 100.7%;
height: 100%;
background-color: black;
z-index: 1001;
-moz-opacity: 0.8;
opacity: .80;
filter: alpha(opacity=80);
}
.white_imagebox
{
display: none;
position: fixed;
top: 5%;
left: 6%;
width: 900px;
height: 500px;
padding: 0px;
border: 0px solid #a6c25c;
background-color: white;
z-index: 1002;
overflow: visible;
}
</style>
<script type="text/javascript" src="AJAX/AjaxInsertPicComment.js"></script>
<script>
function showpic(image_path,image_id,album_id,pic_caption)
{
document.getElementById('AlbumDiv').style.display = "block";
document.getElementById('fade').style.display = "block";
document.getElementById('image').src = image_path; // this line added
img = new Image();
img.src = image_path;
document.getElementById('t_albumid').value = album_id;
document.getElementById('t_imageid').value = image_id;
document.getElementById('t_albid').value = album_id;
document.getElementById('t_picid').value = image_id;
document.getElementById('albumid').value = album_id;
document.getElementById('imageid').value = image_id;
document.getElementById('t_imagepath').value = image_path;
document.getElementById('caption_holder').value = pic_caption;
if(img.width > 500 && img.height > 450)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
else if(img.height > 450 && img.width < 500)
{
document.getElementById('image').style.height = "450px";
delete img;
return false;
}
else if(img.height < 450 && img.width > 500)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
else if(img.width < 500 && img.height < 450)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
delete img;
alert("humm");
return false;
}
</script>
</head>
<body>
<div id="photo_holder">
<table width="1000px" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td width="50px" align="center"/>
<td align="center" colspan="2" background="Images/header_menu.png" style="padding-right:2px;">
<?php include('header.php');?>
</td>
<td width="50px" align="center"/>
</tr>
<tr>
<td width="50px" align="center" ></td>
<td width="600px" align="center">
<?php
$album_id=$_REQUEST['txt_albumid'];
echo $album_id;
/* how many columns */
$column_number='3';
/* html table start */
?>
<div id="photo_container" align="center" width="600px">
<table border="1px" cellspacing="5" cellpadding="0" align="left">
<?php
$sql="SELECT * FROM candidate_pics WHERE album_id='$album_id'";
$result=mysql_query($sql,$con);
// $row=mysql_fetch_array($result);
$recordcounter=1; /* counts the records while they are in loop */
while($row=mysql_fetch_array($result))
{
/* decide if there will be new Table row (<TR>) or not ... left of division by column number is the key */
if($recordcounter%$column_number==1)
{
echo "<tr>";
}
?>
<td align="center" width="200px">
<div class="wraptocenter" align="center">
<?php $_SESSION['pic_id']=$row[pic_id];?>
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
</div>
</td>
<?php
/* decide if there will be end of table row */
if($recordcounter%$column_number==0)
{
echo "</tr>";
}
$recordcounter++; /* increment the counter */
}
if(($recordcounter%$column_number)!=1){ echo "</tr>"; }
?>
</table>
</div>
</td>
<td width="300px" align="center" >
<div id="photo_uploader">
<form method="post" action="photo_upload.php" enctype="multipart/form-data">
<table width="300px" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" width="100px">Upload Pic::</td>
<td align="center" width="200px">
<input type="file" name="file" id="file" style="width: 200px;"/>
</td>
</tr>
<tr>
<td align="center" width="100px"/>
<td align="center" width="200px">
<input type="submit" name="submit_pic" id="submit_pic" value="Click to upload" style="width: 200px;"/>
<input name="txt_albumid" type="hidden" value="<?php echo $album_id;?>"/>
</td>
</tr>
</table>
</form>
</div>
</td>
<td width="50px" align="center" ></td>
</tr>
</table>
</div>
<div id="AlbumDiv" class="white_imagebox">
<table align="center" cellpadding="0" cellspacing="0" border="0" width="900px">
<tr>
<td colspan="2" height="25px">
<div id="close">
<a href="javascript:void(0)"
onclick="document.getElementById('AlbumDiv').style.display =
'none';document.getElementById('fade').style.display='none'">
<img src="images/close-icon.png" style="border-style: none; border-color: inherit;
border-width: 0px; height: 17px; width: 16px;" align="right" /></a>
</div>
</td>
</tr>
<tr>
<td width="600px" align="center">
<table width="600px" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="50px" align="center"/>
<td align="center" width="500px">
<div id="image_holder" style="width: 500px; height: 450px;
background-color:#666666;">
<input type="image" id="image" name="image"/>
</div>
</td>
<td width="50px" align="center"/>
</tr>
<tr>
<td/>
<td>
<input type="text" id="caption_holder" name="caption_holder"
style="width:500px;"/>
</td>
<td/>
</tr>
</table>
</td>
<td width="300px" align="center">
<table width="300px" cellpadding="0" cellspacing="0" border="0" align="top">
<tr>
<td align="center" width="100px">
<form method="post" action="photo_delete.php">
<input type="submit" name="delete" id="delete" value="Delete"
class="button" style="width: 100px;"/>
<input type="hidden" name="t_imageid" id="t_imageid"/>
<input type="hidden" name="t_imagepath" id="t_imagepath"/>
<input type="hidden" name="t_albumid" id="t_albumid"/>
</form>
</td>
<td align="center" width="100px">
<form>
<input type="button" name="edit" id="edit" value="Edit" class="button"
style="width: 100px;"
onclick="document.getElementById('pic_caption').style.visibility = 'visible';
document.getElementById('enter_caption').style.visibility = 'visible';"/>
</form>
</td>
<td align="center" width="100px">
<form method="post" action="">
<input type="submit" name="cover_pic" id="cover_pic" value="Set CoverPic" class="button"
style="width: 100px;"/>
<input type="hidden" name="t_albumname" id="t_albumname"/>
<input type="hidden" name="t_imagename" id="t_imagename"/>
</form>
</td>
</tr>
<tr>
<td height="100px" colspan="3">
<form method="post" action="photo_edit.php">
<input type="text" name="pic_caption" id="pic_caption" style="visibility:hidden;"/>
<input type="submit" name="enter_caption" id="enter_caption" style="visibility:hidden;"/>
<input type="hidden" name="t_picid" id="t_picid"/>
<input type="hidden" name="t_albid" id="t_albid"/>
</form>
</td>
</tr>
<tr>
<td height="300px" colspan="3">
<div id="" style="overflow-y:scroll; height:300px;">
<table width="282px" cellpadding="0" cellspacing="0" border="0"
align="center">
<tr>
<td>
<?php
echo $_SESSION[pic_id];?>
<div id="message_report">
</div>
</td>
</tr>
<tr>
<td>
<form method="post" action=
"javascript:get(document.getElementById('pic_comment_form'));" name=
"pic_comment_form" id="pic_comment_form">
<table width="280px" cellpadding="0" cellspacing="0" border="0"
align="center" >
<tr>
<td width="100px">
<input type="text" name="comment" id="comment" style="width:100px"/>
</td>
<td width="80px"/>
<td width="100px">
<input type="submit" name="comment_enter" id="comment_enter" style="width:100px"/>
</td>
<tr>
<td>
<input type="hidden" name="albumid" id="albumid"/></td>
<td>
<input type="hidden" name="imageid" id="imageid"/></td>
<td>
<input type="hidden" name="user" id="user"
value="<?php echo $_SESSION[logged_user];?>"/></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div id="fade" class="black_overlay">
</div>
</body>
</html>
The code
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
pass the album_id, pic_id to the javascript functions which is then passed to the objects in the lightbox such as id="t_albumid", id="t_imageid"
I need to write a SQL query in the lightbox like this:
SELECT * FROM candidate_pics_comment WHERE pic_id='$VariableHavingPicId
but for this I must use the variable in the JavaScript image_id and pass it again to the lightbox div in the JavaScript. The code:
document.getElementById('t_imageid').value = image_id;
assigns the object, the value as image_id, but how can we assign the image_id to a php variable so that I can use it in the sql query?
I mean in the JavaScript can it be something like this:
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$var = //assign the value image_id;?>
// rest of the code here;
}
I know it's not possible, but is there some trick to achieve this?
Moreover as I was experimenting, I did something like this:
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$_SESSION[pic_id]="hmmm";?>
//rest codes;
}
Then when I used echo $_SESSION[pic_id] in php script, it displayed hmmm
So I was thinking can it be done something like this?
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$_SESSION[pic_id]=//assign image_id to session variable;?>
//rest codes;
}
Besides I used AJAX application, but I saw that AJAX returns the response to the objects innerHTML, how ca it be stored in a php variable?
Update
My question is that, I am passing values from this
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
to the JavaScript fiunction
function showpic(image_path,image_id,album_id,pic_caption)
Now how can I assign image_id to a PHP variable which I can use in the div AlbumDiv which is used for the lightbox. If that not possible how can a session variable be assign the value of image_id, is it possible inside the JavaScript function?
ajax is the only option to get something from JavaScript to PHP.
If you are using jQuery then take a look at the docs here
Otherwise I recommend you use a Library like jQuery or jQuery itself

Categories