This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
I want to display all rows from the table and i want to get update button in each row with the date option displayed. But i am getting below error:
undefined index br, rg, batch
I didn't get where i went wrong. I am giving my code. When i click the update button in the respective row, the SQL table gets updated with the respective date to the respective rollnumber.
<html>
<head>
<link rel="stylesheet" type="text/css" href="header.css" />
<script src="jquery.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"> </script>
<script>
$( function() {
$( ".date" ).datepicker({dateFormat:'yy-mm-dd'});
} );
</script>
<style>
body
{
background-color: #FFFFF2;
}
.date
{
width:70px;
}
.design
{
border: 1px solid red;
border-collapse:collapse;
text-align:center;
}
tr
{
height:35px;
}
th
{
background-color:lightgreen;
border: 1px solid red;
height:50px;
}
td
{
border: 1px solid red;
font-size:13px;
height:10px;
}
.design tr:hover
{
background-color:#FFA600;
font-weight:bold;
}
</style>
</head>
<?php
include('connect.php');
$br=$_POST['branch'];
$rg=$_POST['reg'];
$batch=$_POST['batch'];
$br1=0;
$year=0;
$sem=0;
if($rg=='R13')
{
if($br==1)
{
$br1="CIVIL";
}
else if($br==2)
{
$br1="EEE";
}
else if($br==3)
{
$br1="MECH";
}
else if($br==4)
{
$br1="ECE";
}
else if($br==5)
{
$br1="CSE";
}
else
{
$br1="IT";
}
echo"<center><u><h2>Degree Eligibility List($br1) ($batch batch)</h2></u></center>";
$sl=1;
$i=1;
$k=0;
$mrk=0;
$int=0;
$ext=0;
$bl=0;
$marks=0;
$total=0;
$crd=0;
$per=0;
$grade=0;
echo"<center><table class='design'>";
echo"<thead><th>S.No</th>
<th>Roll Number</th>
<th>Obtained</th>
<th>MaxMarks</th>
<th>Percent</th>
<th>credits</th>
<th>Backlogs</th>
<th>Eligibility</th>
<th>PC mode</th>
<th>PC apply date</th>
<th>PC recieve date</th>
</thead>";
$sql1="select rollno from pc where branch='$br' and batch='$batch'";
$ret1=mysql_query($sql1);
while($row1=mysql_fetch_array($ret1))
{
//echo"<tr>";
//echo"<td>".$sl++."</td>";
$rno=$row1['rollno'];
$sql="select * from data where rollno='$rno' order by year asc, sem asc, subcode asc, my desc, type desc";
$ret=mysql_query($sql);
while($row=mysql_fetch_array($ret))
{
$int=$row['internal'];
$ext=$row['external'];
$j=$row['credits'];
$temp=$row['subcode'];
if(strcmp($temp,$k)<>0)
{
$sql2="select * from sforms where scode='$temp'";
$ret_sub=mysql_query($sql2);
$row_fetch=mysql_fetch_array($ret_sub);
$max=$row_fetch['maxmarks'];
if($row['external']=='-1')
{
$mrk=$int;
}
else
{
$mrk=$row['internal']+$row['external'];
}
if($j==0)
{
$bl++;
$marks=$marks+$mrk;
$total=$total+$max;
}
else
{
$marks=$marks+$mrk;
$total=$total+$max;
$crd=$crd+$j;
}
$k=$temp;
}
}
if($total<>0)
{
$per=round(($marks/$total)*100,2);
echo"<tr>";
echo"<td>".$sl++."</td>";
echo"<td>$rno</td>";
echo"<td>$marks</td>";
echo"<td>$total</td>";
echo"<td>$per</td>";
echo"<td>$crd</td>";
echo"<td>$bl</td>";
if($bl==0)
{
echo"<td>Eligible</td>";
echo"<td><form method='post' action=''>
<select name='mode' required>
<option value=''>--select--</option>
<option value='T'>Tatkal</option>
<option value='C'>College</option>
</select></td>";
echo"<td><input type='text' name='date' class='date' required><input type='submit' name='Submit' class='submit' value='Update' /></form></td><td></td></tr>";
}
else
{
echo"<td></td><td></td><td></td><td></td></tr>";
}
}
$marks=0;
$total=0;
$per=0;
$bl=0;
$crd=0;
}
echo"</table></center>";
}
// use this code for edit button ..
<td><a href="set your url.." title="Edit" style="color:blue;font-size: 16px;color: #1caadc;font-weight: bolder;"><i class="fa fa-pencil-square-o"></i>
</a></td>
$br=$_POST['branch'];
$rg=$_POST['reg'];
$batch=$_POST['batch'];
Try to print these values and check. Make sure you are passing the values from the form.
Related
Hi there i am trying to create a screen in php.
in which i select scenario and the screen displayed accordingly.
but i am stuck in a simple problem that my simple select query is not working
which is
$deptQuery = "Select * from mcb_department";
echo mysql_real_escape_string($deptQuery);
mysql_query($deptQuery) or die("adfasdf");
in same code if change the table name it just work fine, also this table is created in the db as well with the same name i have shared.
here is my complete code.
<?php
include "include/conn.php";
include "include/session.php";
if(isset($_SESSION['logged_user']) && $_SESSION['logged_user'] != '99999'){
header('location: login.php');
}
$query = mysql_query("select curdate() as todayDate");
$show = mysql_fetch_array($query);
if(isset($show)){
$todayDate= $show['todayDate'];
}
$group[] = array();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta Content="no-cache, no-store, must-revalidate" http-Equiv="Cache-Control" />
<meta Content="no-cache" http-Equiv="Pragma" />
<meta Content="0" http-Equiv="Expires" />
<link href="styles/style.css" type="text/css" rel="stylesheet" />
<link href="styles/popupstyle.css" type="text/css" rel="stylesheet" />
<link href="styles/ts.css" type="text/css" rel="stylesheet" />
<link href="styles/calendar.css" type="text/css" rel="stylesheet" />
<style>
table {
font-family: arial;
border-collapse: collapse;
width: 100%;
font-size: 11px;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 3px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body >
</body>
<select id='select_opt'>
<option> Select Assigment </option>
<option value="1"> assign quiz to all Employees </option>
<option value="2"> assign quiz to Sapcific Group </option>
<option value="3"> assign quiz to Sapcific Department </option>
<option value="4"> assign quiz to Sapcific Employee </option>
</select>
<!-- all Users -->
<div id='allUsers' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action="" mathod="post">
<select>
<option value=""> select Quiz</option>
</select>
<input type="submit" >
</form>
</div>
<!-- group -->
<div id='group' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action='group_assigment.php' mathod="post">
<table>
<tr>
<th>All <input type="checkbox"> </th>
<th>Group Name</th>
<th>Group Code</th>
</tr>
<?php
$group[] = array();
$groupQuery = "Select * from mcb_groups";
$query = mysql_query($groupQuery);
?>
<tr>
<?php if($query){
while($group = mysql_fetch_array($query)){
?>
<td><input type="checkbox" value="<?php echo $group['group_name']; ?>"></td>
<td><?php echo $group['group_name']; ?></td>
<td><?php echo $group['group_code']; ?></td>
</tr>
<?php }
} else{ echo "";} ?>
</table>
</form>
</div>
<!--
####################################
department
####################################
-->
<div id='Department' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action='group_assigment.php' mathod="post">
<table>
<tr>
<th>all <input type="checkbox"> </th>
<th>name</th>
<th>code</th>
<th>group</th>
</tr>
<tr>
<?php
$deptQuery = "Select * from mcb_department";
echo mysql_real_escape_string($deptQuery);
mysql_query($deptQuery);
?>
<td><input type="checkbox"></td>
<td>code</td>
<td>name</td>
<td>group</td>
</tr>
</table>
<input type="submit" >
</form>
</div>
<!--
####################################
Employee
####################################
-->
<div id='employee' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action="" mathod="post">
<label>employee id : </label><input type="text" >
<input type="submit" >
</form>
</div>
<script language="javascript" type="text/javascript">
var elem = document.getElementById("select_opt");
elem.onchange = function(){
console.log("yes i am running");
if( document.getElementById("select_opt").value == "1" ){
document.getElementById("allUsers").style.display = "Block";
document.getElementById("group").style.display = "none";
document.getElementById("Department").style.display = "none";
document.getElementById("employee").style.display = "none";
}
else if( document.getElementById("select_opt").value == "2" ){
document.getElementById("group").style.display = "Block";
document.getElementById("allUsers").style.display = "none";
document.getElementById("Department").style.display = "none";
document.getElementById("employee").style.display = "none";
}
else if( document.getElementById("select_opt").value == "3" ){
document.getElementById("Department").style.display = "block";
document.getElementById("group").style.display = "none";
document.getElementById("allUsers").style.display = "none";
document.getElementById("employee").style.display = "none";
}
else if( document.getElementById("select_opt").value == "4" ){
document.getElementById("employee").style.display = "block";
document.getElementById("Department").style.display = "none";
document.getElementById("group").style.display = "none";
document.getElementById("allUsers").style.display = "none";
}
else{
}
};
</script>
</
html>
regard,
Shafee jan
in same code if change the table name it just work fine
Then I would make sure you're connected to the right database. It's surprisingly common for developers to have multiple versions of their database, either on different MySQL instances or else on the same instance under a different schema name. Then they get mixed up, connecting to one database with MySQL Workbench while their app is connecting to a different database.
I would advise that you temporarily add a query to your page to run SHOW TABLES and then dump the result of that query to the log, to confirm that the mcb_department table is present in the database that your PHP script is connected to.
$deptQuery = "Select * from mcb_department";
echo mysql_real_escape_string($deptQuery);
mysql_query($deptQuery);
Where's your error checking? You need to check the return value of mysql_query() every time you run a query, so if there's a problem, you output the error message to your log. Only this way can you start to solve some of these problems.
$result = mysql_query($deptQuery);
if (!$result) {
trigger_error("Error in file " . __FILE__ . " near line " . __LINE__
. " for query $deptQuery: " . mysql_error());
die("Database error");
}
PS: The advice of some commenters that mysql_* functions are deprecated is true, but probably irrelevant to your question. Folks who focus on the API, when you have said the API is working, are just being pedantic.
I have an input, in which a code is entered and filled the table below with information from mysql optenida, the question is that I want every time a code is entered, the table all the data is added (without deleting the previous ). I got the idea to do with Ajax, but do not know where to start. So you see there is an easier way that I'm not seeing (finding on google). I do not like to add this data to a table, I would like it to be temporarily (until the table is confirmed, will be added to the db).
Any ideas?
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style>
table {
width:100%;
border: 1px solid black;
border-collapse: collapse;
}
td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="input_codigo" placeholder="Codigo del producto" autocomplete="off" autofocus required><br><br>
</form>
<table>
<tr>
<td><b>Codigo</b></td>
<td><b>Descripcion</b></td>
<td><b>Precio</b></td>
<td><b>Cantidad</b></td>
<td><b>Importe</b></td>
</tr>
<?php
session_start();
error_reporting(E_ALL ^ E_NOTICE);
require ("conectar.php");
$_SESSION["codigo"] = $_POST["input_codigo"];
$sql = "SELECT * FROM $tabla WHERE codigo = ".$_SESSION['codigo']."";
$result = $conexion->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>".$row["codigo"]."</td>
<td>".$row["descripcion"]."</td>
<td>$".$row["venta"]."</td>
<td><input type='number' name='cantidad' value='1' min='1' max='5'></td>
<td>$".$row["venta"]."</td>
</tr>
";
}
} else {
echo "";
}
$conexion->close();
?>
</table>
</body>
</html>
Maybe something like this i write below.
Added jQuery and Ajax request to get the data and then add it to the table.
Changed the PHP a little so that the main HTML is not returned if it is and AJAX request.
Hope it works for you (i didnt test it).
<?php
session_start();
error_reporting(E_ALL ^ E_NOTICE);
$bAjaxRequest = false;
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$bAjaxRequest = true;
}
// if not and ajax request deliver the complete HTML
if(!$bAjaxRequest) {
?>
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style>
table {
width:100%;
border: 1px solid black;
border-collapse: collapse;
}
td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<form action="index.php" method="post" id="frmQuery" name="frmQuery">
<input type="text" name="input_codigo" id="input_codigo" placeholder="Codigo del producto" autocomplete="off" autofocus required><br><br>
</form>
<table id="tblData" name="tblData">
<tr>
<td><b>Codigo</b></td>
<td><b>Descripcion</b></td>
<td><b>Precio</b></td>
<td><b>Cantidad</b></td>
<td><b>Importe</b></td>
</tr>
<?php
} // end if(!$bAjaxRequest) {
// we are always going to return the TR's or ""
require ("conectar.php");
// ALWAYS, BUT ALWAYS VERIFY/VALIDATE USER INPUT!!!
$_SESSION["codigo"] = mysql_real_escape_string($_POST["input_codigo"]); // for example
$sql = "SELECT * FROM $tabla WHERE codigo = ".$_SESSION['codigo']."";
$result = $conexion->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>".$row["codigo"]."</td>
<td>".$row["descripcion"]."</td>
<td>$".$row["venta"]."</td>
<td><input type='number' name='cantidad' value='1' min='1' max='5'></td>
<td>$".$row["venta"]."</td>
</tr>
";
}
} else {
echo "";
}
$conexion->close();
// if not and ajax request deliver the complete HTML
if(!$bAjaxRequest) { ?>
</table>
<script type="text/javascript">
function loadData(codigo) {
$.post( "index.php", { input_codigo: codigo }, function( data ) {
$("#tblData").append(data);
});
}
$(function() {
// jQuery POST are never cached, but if you change to GET you'll need this next line
//$.ajaxSetup ({ cache: false });
$("#frmQuery").submit(function(e) {
e.preventDefault();
loadData($("#input_codigo").val());
});
});
</script>
</body>
</html>
<?php
}
?>
I have an editable grid where I want to edit the CSS such that the textarea to show the maximum width, but somehow I can't increase the width of the text area.
My database has three columns:
ID
Name
Gossip
I'm retrieving everything and displaying it in an editable grid using PHP.
index.php code
<?php
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
die('Check the database connection again!');
}
$userQuery = 'SELECT Id,Name,Gossip FROM bollywood';
$stmt = $db->query($userQuery);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var textBefore = '';
$('#grid').find('td input').hover(function() {
textBefore = $(this).val();
$(this).focus();
}, function() {
var $field = $(this),
text = $field.val();
$(this).blur();
// Set back previous value if empty
if (text.length <= 0) {
$field.html(textBefore);
} else if (textBefore !== text) {
// Text has been changed make query
var value = {
'row': parseInt(getRowData($field)),
'column': parseInt($field.closest('tr').children().find(':input').index(this)),
'text': text
};
$.post('user.php', value)
.error(function() {
$('#message')
.html('Make sure you inserted correct data')
.fadeOut(3000)
.html(' ');
$field.val(textBefore);
})
.success(function() {
$field.val(text);
});
} else {
$field.val(text);
}
});
// Get the id number from row
function getRowData($td) {
return $td.closest('tr').prop('class').match(/\d+/)[0];
}
});
</script>
<title></title>
</head>
<body>
<?php if ($stmt): ?>
<div id="grid">
<p id="message">Click on the field to Edit Data</p>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Gossip</th>
</tr>
</thead>
<tbody>
<?php while ($row = $stmt->fetch_assoc()): ?>
<tr class="<?php echo $row['Id']; ?>">
<td><input type="text" value="<?php echo $row['Id']; ?>" /> </td>
<td><input type="text" value="<?php echo $row['Name']; ?>" /></td>
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p>No actors added yet</p>
<?php endif; ?>
</body>
</html>
user.php code
<?php
// Detect if there was XHR request
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$fields = array('row', 'column', 'text');
$sqlFields = array('Id', 'Name', 'Gossip');
foreach ($fields as $field) {
if (!isset($_POST[$field]) || strlen($_POST[$field]) <= 0) {
sendError('No correct data');
exit();
}
}
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
sendError('Connect error');
exit();
}
$userQuery = sprintf("UPDATE bollywood SET %s='%s' WHERE Id=%d",
$sqlFields[intval($_POST['column'])],
$db->real_escape_string($_POST['text']),
$db->real_escape_string(intval($_POST['row'])));
$stmt = $db->query($userQuery);
if (!$stmt) {
sendError('Update failed');
exit();
}
}
header('Location: index.php');
function sendError($message) {
header($_SERVER['SERVER_PROTOCOL'] .' 320 '. $message);
}
style.css code
body {
font: normal 14px Comic Sans, Comic Sans MS, cursive;
}
table {
width: 500px;
}
td, th {
border: 1px solid #d8d8bf;
}
th {
padding: 5px;
font: bold 14px Verdana, Arial, sans-serif;
}
td {
padding: 10px;
width: 200px;
}
td input {
margin: 0;
padding: 0;
// width:200px;
font: normal 14px sans-serif;
/** Less flicker when :focus adds the underline **/
border: 1px solid #fff;
}
td input:focus {
outline: 0;
border-bottom: 1px dashed #ddd !important;
}
#grid input {
// width: 200%;
}
You doing it wrong
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
Should be:
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
textarea is html tag name but not input type. so change this.
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
to
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
also add this css.
<style>
textarea {
resize: both;
width:700px;
}
</style>
also are you sure that you can get content using this.
<?php echo $row['Gossip']; ?>
So I'm trying to make a "Simple" php + javascript drag and drop, here's my code:
<title>Web Editor</title>
<?php
mysql_connect("$host","$user","$pass");
mysql_select_db("$db");
if(isset($_POST['submit'])){
$name=$_FILES['file']['name'];
$temp=$_FILES['file']['tmp_name'];
move_uploaded_file($temp,"uploaded/".$name);
$url="http://www.bluejayke.com/edit/uploaded/$name";
}
?>
<?php
if(isset($_POST['submit'])){
mysql_query("INSERT INTO uploadedvideos(id,name,url) VALUES('','$name','$url')");
echo "</br>" . $name . " uploaded";
}
$query="SELECT * FROM uploadedvideos";
$result = mysql_query($query);
?>
<div class='wrapper' id='wrapper'>
<table cellpadding="0" cellspacing="0" border="1">
<tr>
<td style="width:400px; height:50px;"><form action="index.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit" value="Upload">
</form></td>
</tr>
<tr>
<td style="width:400px; height:500px;">
<div style="width:100%; height:100%; overflow:auto; ">
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1");
</script>
<?php
while($row=mysql_fetch_array($result))
{
$id=$row['id'];
$name=$row['name'];
$url=$row['url'];
echo "<div style='position:absolute;cursor:pointer;' id='".$id."'><a href='javascript: click(\"$url\")'>$name</br><embed id='$id' src='$url' width='120' height='120' draggable='true' ondragstart='drag(event)'></embed></a><input type='button' id='delete' value='X' onclick='return Deleteqry($id)' /></div><br> ";
?>
<script type="text/javascript">
var dragging = false
$(function () {
var target<?php echo $id ?> = $('#<?php echo $id; ?>')
target<?php echo $id ?>.mousedown(function() { dragging<?php echo $id; ?> = true })
$(document).mouseup(function() { dragging<?php echo $id; ?> = false })
$(document).mousemove(function(e) {
if(dragging<?php echo $id; ?>){
target<?php echo $id ?>.css('left', e.pageX)
target<?php echo $id ?>.css('top', e.pageY)
}
})
})
</script>
<?php
}
?>
</div>
</table>
</div>
<div class='wactch' id='watching' height='480' width='720'>Loading..</div>
<script>
/*document.onmousemove=mouseMove;
function mouseMove(ev)
{
ev = ev || window.event;
var mousePos=mouseCords(ev);
}
function mouseCords(ev)
{
if(ev.pageX || ev.pageY)
{
return{x:ev.pageX,y:ev.pageY);
}
return
{
x:ev.clientX+document.body.scrollLeft-document.body.clientLeft, y:ev.clientY.document.body.scrollTop-document.body.clientTop
};
}
}*/
function Deleteqry(id)
{
if(confirm("Are you sure you want to delete this picture?")==true)
window.location="index.php?del="+id;
return false;
}
function allowDrop(ev)
{
ev.preventDefault();
}
function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}
function drop(ev)
{
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
window.onload=function()
{
click("http://www.bluejayke.com/edit/uploaded/dpnewslogo.png");
}
function click(url)
{
document.getElementById("watching").innerHTML='<embed src="'+url+'" width=720 height=480></embed>';
}
</script>
<?php
if($_GET['del']){
$delete_id=$_GET['del'];
mysql_query("DELETE FROM `uploadedvideos` WHERE `uploadedvideos`.`id` = $delete_id");
header("location: index.php");
}
?>
<style type="text/css">
.wrapper
{
width:500px;
overflow: hidden;
float: left;
}
#watching {
float: right;
}
.div1 {width:750px;height:120px;padding:10px;border:1px solid #aaaaaa; oveflow: hidden;}
</style>
The important part is in the while loop. The result of this code is all the divs I made in the while loop are piled up on top of each other, when I want them in a vertical line-like structure. Anyone have any insight on this? It's something with the div's styling I think, but I'm not sure how to resolve it while still keeping the drag and drop function.
Your divs are being positioned absolute. You simply need to change them to position:relative;
http://www.w3schools.com/css/css_positioning.asp
i want to open a specific window according to a drop down selection, the function works fine on the first row of a set of data (pulling it from a database)
Since i don't know how many rows are going to come each time the script is running, i've created a loop and writting the function as many times as rows there are coming, having them named different.
The thing is that when i change the drop down from the first row, the correct window opens, for instance custom.php?id=1, but when i open the second one, if i select comunicarse from the list, it opens custom.php?id=2 (id=2 is the user's id)
Here is the code, and i really hope you can understand me....
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<style>
table {
border-style:ridge;
border-width:1px solid;
border-collapse:collapse;
font-family:sans-serif;
font-size:12px;
width:100%;
}
table thead th, table.excel tbody th {
background:#CCCCCC;
border-style:ridge;
border-width:1;
text-align: center;
vertical-align:bottom;
}
table tbody th {
text-align:center;
}
table tbody td {
vertical-align:bottom;
}
table tbody td {
padding: 0 3px;
border: 1px solid 0000000;
}
table td {
padding: 0 3px;
border: 1px solid 0000000;
}
</style>
<link rel="stylesheet" href="../css/style.css" type="text/css">
<?php
include("../../cons/dbinfo.php");
$busco_react = "SELECT *
FROM `envios_mercadolibre`
WHERE status != 'ENTREGADA' AND status != 'CANCELADA' AND aviso != 1";
$bus1 = mysql_query($busco_react);
while ($b1 = mysql_fetch_array($bus1)){
$para = $b1['id'];
echo '<script language="Javascript" type="text/javascript">
function ReactToChange'.$para.'()
{
if (document.getElementById("DropDownList").value === "custom")
{
window.open("custom.php?id='.$para.'")
}
else if (document.getElementById("DropDownList").value === "comunicarse")
{
window.open("comunicarse.php?id='.$para.'")
}
else if (document.getElementById("DropDownList").value === "esperando")
{
window.open("esperando.php?id='.$para.'")
}
else if (document.getElementById("DropDownList").value === "compro")
{
window.open("compro.php?id='.$para.'")
}
else {}
}
</script>';
}
?>
</head>
<body>
<table width = "2200px">
<tr><td colspan="3" align="center">Back to index</td></tr>
</table>
<br />
<?php
echo "<form method='post' action='sendemails.php'>";
echo "<table border='1' cellpading ='0' cellspacing ='0'>";
echo "<thead><tr><th>MAIL</th><th>Email Address</th><th>Content</th>
<th>Extra 1</th><th>Extra 2</th><th>Full Address</th><th>Full Name</th></tr>
</thead><tbody>";
$bus = "SELECT * FROM `envios_mercadolibre` WHERE status != 'ENTREGADA' AND status != 'CANCELADA' AND aviso != 1";
$bu = mysql_query($bus) or die("este");
while ($b = mysql_fetch_array($bu)){
$contenido = $b['contenido'];
$extra1 = $b['extra1'];
$extra2 = $b['extra2'];
$usuario_id = $b['usuario_id'];
$para1 = $b['id'];
$datosUsuario = "SELECT nombre, apellido, email from usuarios WHERE id = $usuario_id";
$datosU = mysql_query($datosUsuario) or die("foo");
while ($c = mysql_fetch_array($datosU)){
$nombre = $c['nombre'];
$apellido = $c['apellido'];
$email = $c['email'];
$todoelnombre = $nombre.", ".$apellido;
echo "<tr>
<td><select id='DropDownList' onchange='ReactToChange$para1()'>
<option value='later'>LATER</option>
<option value='comunicarse'>COMUNICARSE CON NOSOTROS</option>
<option value='esperando'>ESPERANDO CALIFICACION EN MERCADO LIBRE</option>
<option value='compro'>NO COMPRO</option>
<option value='custom'>CUSTOM</option>
</select></td>
<td>$email</td>
<td>$contenido</td>
<td>$extra1</td>
<td>$extra2</td>
<td>$todaladire</td>
<td>$todoelnombre
<input type='hidden' name ='datos-$para1' value ='$email' />
</td>
</tr>
";
}
}
echo "<tr><TD colspan ='7' align='center'><input type='submit' /></td></tr></table>";
?>
</div>
</body>
</html>
It's hard to tell an exact answer without seeing your database structure, but at first I would not create your javascript function inside the while loop, as it will make several functions. On the top of that you really do not need the first SELECT if you use a parameterized javascript function that you call later with the apropriate parameters.
I have modified your code, please take a look at a more effective javascript function and its calling below:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<style>
table {
border-style:ridge;
border-width:1px solid;
border-collapse:collapse;
font-family:sans-serif;
font-size:12px;
width:100%;
}
table thead th, table.excel tbody th {
background:#CCCCCC;
border-style:ridge;
border-width:1;
text-align: center;
vertical-align:bottom;
}
table tbody th {
text-align:center;
}
table tbody td {
vertical-align:bottom;
}
table tbody td {
padding: 0 3px;
border: 1px solid 0000000;
}
table td {
padding: 0 3px;
border: 1px solid 0000000;
}
</style>
<link rel="stylesheet" href="../css/style.css" type="text/css">
<script language="Javascript" type="text/javascript">
function ReactToChange(para,ptype)
{
window.open(ptype+".php?id="+para);
}
</script>
</head>
<body>
<table width = "2200px">
<tr><td colspan="3" align="center">Back to index</td></tr>
</table>
<br />
<?php
echo "<form method='post' action='sendemails.php'>";
echo "<table border='1' cellpading ='0' cellspacing ='0'>";
echo "<thead><tr><th>MAIL</th><th>Email Address</th><th>Content</th>
<th>Extra 1</th><th>Extra 2</th><th>Full Address</th><th>Full Name</th></tr>
</thead><tbody>";
$bus = "SELECT * FROM `envios_mercadolibre` WHERE status != 'ENTREGADA' AND status != 'CANCELADA' AND aviso != 1";
$bu = mysql_query($bus) or die("este");
while ($b = mysql_fetch_array($bu)){
$contenido = $b['contenido'];
$extra1 = $b['extra1'];
$extra2 = $b['extra2'];
$usuario_id = $b['usuario_id'];
$para1 = $b['id'];
$datosUsuario = "SELECT nombre, apellido, email from usuarios WHERE id = $usuario_id";
$datosU = mysql_query($datosUsuario) or die("foo");
while ($c = mysql_fetch_array($datosU)){
$nombre = $c['nombre'];
$apellido = $c['apellido'];
$email = $c['email'];
$todoelnombre = $nombre.", ".$apellido;
echo "<tr>
<td><select id='DropDownList' onchange='ReactToChange($para1,this.options[this.selectedIndex].value)'>
<option value='later'>LATER</option>
<option value='comunicarse'>COMUNICARSE CON NOSOTROS</option>
<option value='esperando'>ESPERANDO CALIFICACION EN MERCADO LIBRE</option>
<option value='compro'>NO COMPRO</option>
<option value='custom'>CUSTOM</option>
</select></td>
<td>$email</td>
<td>$contenido</td>
<td>$extra1</td>
<td>$extra2</td>
<td>$todaladire</td>
<td>$todoelnombre
<input type='hidden' name ='datos-$para1' value ='$email' />
</td>
</tr>
";
}
}
echo "<tr><TD colspan ='7' align='center'><input type='submit' /></td></tr></table>";
?>
</div>
</body>
</html>
instead of writing multiple function you can write
function ReactToChange(para)
{
//only call document.getElementById("DropDownList").value once - good programming practice
var dropdownvalue = document.getElementById("DropDownList").value;
if (dropdownvalue === "custom")
{
window.open("custom.php?id='"+para+"'")
}
else if (dropdownvalue === "comunicarse")
{
window.open("comunicarse.php?id='"+para+"'")
}
...
}
<select id='DropDownList' onchange='ReactToChange($para1)'>
<option value='later'>LATER</option>
...
</select>
Now your code is shorter because you have just one function to handle everything
Note that you are passing the "Id" as parameter
If you have thousands of records, you would have generated thousands of functions slowing the page down
Not sure whether .value will always work properly. Consider the following changes at this point in your code:
function ReactToChange'.$para.'()
{
var dropdown = document.getElementById('DropDownList'),
selectedValue = dropdown.options[dropdown.selectedIndex];
// now make all comparisons against selectedValue
// ...
if (selectedValue === 'comunicarse') {
window.open("comunicarse.php?id='.$para.'")
}
// ...
}