Notice: Undefined index: - php

I have a problem with my code.
if I use select * from $table it's all good but
now with select distinct it shows me
Notice: Undefined index: L_code in /home/lab_users/web_tue25/web_pages/2014-12-09/stats03-04e.php on line 70
and it show the same for all the variables A/A etc.
Can anyone help me find my mistake(s)???
Thank you
<?php
include_once "dbconnect.php";
$sql = "SELECT DISTINCT akexam = '2003-04.e' FROM $table ";
$result = $dblink->query($sql);
if ($result->num_rows !== 0)
{
echo '<table border="1" style="width:100%; border: 1px solid black; border-collapse:collapse; text-align: center;">
<tr bgcolor= #787878>
<th>A/A</th>
<th>ak.εξαμ.</th>
<th>L_code</th>
<th>τ.ε</th>
<th>ck</th>
<th>rb</th>
<th>L_descr</th>
<th>ΔΗΛ</th>
<th>ΣΥΜ</th>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
<th>f</th>
<th>ΣΥΝ</th>
<th>ok</th>
<th>ok%</th>
</tr>';
while($row = $result->fetch_assoc())
{
echo '<tr bgcolor= purple>';
if(strstr($row["L_code"],"241"))
{
echo "<td style= text-align:left>".$row["A/A"]."</td>";
echo "<td style= text-align:left>".$row["akexam"]."</td>";
echo "<td style= text-align:left>".$row["L_code"]."</td>";
echo "<td>".$row["te"]."</td>";
echo "<td> <input type='checkbox' name= 'ch' value='1'></td>";
echo "<td> <input type='radio' name='labs' value='1'></td>";
echo "<td>".$row["L_descr"]."</td>";
echo "<td style= text-align:right>".$row["dhl"]."</td>";
echo "<td style= text-align:right>".$row["sym"]."</td>";
echo "<td style= text-align:right>".$row["a"]."</td>";
echo "<td style= text-align:right>".$row["b"]."</td>";
echo "<td style= color:blue>".$row["c"]."</td>";
echo "<td style= color:blue>".$row["d"]."</td>";
echo "<td style= color:blue>".$row["e"]."</td>";
echo "<td style= color:blue>".$row["f"]."</td>";
echo "<td style= text-align:right>".$row["syn"]."</td>";
echo "<td style= text-align:right>".$row["ok"]."</td>";
echo "<td style= text-align:right>".$row["ok%"].'%';"</td>";
}
else
{
echo '<tr bgcolor= baby blue>';
echo "<td style= text-align:left>".$row["A/A"]."</td>";
echo "<td style= text-align:left>".$row["akexam"]."</td>";
echo "<td style= text-align:left>".$row["L_code"]."</td>";
echo "<td>".$row["te"]."</td>";
echo "<td> <input type='checkbox' name= 'ch' value='1'></td>";
echo "<td> <input type='radio' name='theories' value='1'></td>";
echo "<td>".$row["L_descr"]."</td>";
echo "<td style= text-align:right>".$row["dhl"]."</td>";
echo "<td style= text-align:right>".$row["sym"]."</td>";
echo "<td style= text-align:right>".$row["a"]."</td>";
echo "<td style= text-align:right>".$row["b"]."</td>";
echo "<td style= color:blue>".$row["c"]."</td>";
echo "<td style= color:blue>".$row["d"]."</td>";
echo "<td style= color:blue>".$row["e"]."</td>";
echo "<td style= color:blue>".$row["f"]."</td>";
echo "<td style= text-align:right>".$row["syn"]."</td>";
echo "<td style= text-align:right>".$row["ok"]."</td>";
echo "<td style= text-align:right>".$row["ok%"].'%';"</td>";
}
echo '</tr>';
}
echo '</table>';
}
else
{
echo "0 results";
}

Yuo have to change the query.
if you select distinct akexam, you will found a list of different akexam values in the table. Your rows will be just $row["akexam"]
If you select distinct * you will select all the different rows in the table.
It will look like a normal select but it will discard the rows that are identical (if you have a primary key in the table all the rows are different, i warn you).
So please provide an explanation of why you want to select distinct and i can give you more precise solution.

You have to select each column individually.
SELECT DISTINCT `akexam`, `L_code`, .... /*Fetch other columns*/
FROM `table`
WHERE akexam = '2003-04.e'

Related

make a list of products with partial same product number

I want to make an (html) list of products that have the same unique number behind the full stop (.). For example, 1.0001 is white bread sold on Monday 2.0001 is white bread sold on Tuesday and so on.
Now I want to make a list that sums of all white bread sold throughout the week. This is what I have so far:
<?php
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='100' align='center'>Produkt</td><td width='100' align='center'>Baklijst</td>";
include("dbopen.php");
$result = mysql_query(
"SELECT order_item_name, SUM( product_quantity )
FROM wntl_virtuemart_order_items
WHERE wntl_virtuemart_order_items.order_item_sku REGEXP '0001$'
AND order_status = 'U'");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row['order_item_name'] . "</td>";
echo "<td align='center' width='200'>" . $row['SUM(product_quantity)'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
output:
Notice: Undefined index: SUM(product_quantity) in *.php on line 17
Try this:
<?php
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='100' align='center'>Produkt</td><td width='100' align='center'>Baklijst</td>";
include("dbopen.php");
$result = mysql_query(
"SELECT order_item_name, SUM( product_quantity ) AS Sum
FROM wntl_virtuemart_order_items
WHERE wntl_virtuemart_order_items.order_item_sku REGEXP '0001$'
AND order_status = 'U'");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row['order_item_name'] . "</td>";
echo "<td align='center' width='200'>" . $row['Sum'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>

post in one specfic array while loop

I want to post value in one row while doing loop in specific array by id, but when click on bottom then will post it in "response" row in all arrays of table!!
<?php
require_once('config.php');
$con->set_charset('utf8');
$query = "select * from contact order by id";
$result = mysqli_query($con,$query);
while($name = mysqli_fetch_array($result)){
echo '<table width="200" border="1" align="right">';
echo "<tr>";
echo "<td align='center'> <div align='center'> <b> $name[id] </b> </td>";
echo "<td align='center'> <div align='center'> <b> The number </b> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <div align='center'> <b> $name[ticketnumber] </b> </td>";
echo "<td align='center'> <div align='center'> <b> ticket number </b> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <b> $name[name] </b> </td>";
echo "<td align='center'> <b> name </b> </div> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <b> $name[phone] </b> </td>";
echo "<td align='center'> <b> phone </b> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <b> $name[email] </b> </td>";
echo "<td align='center'> <b> email </b> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <b> $name[subject] </b> </td>";
echo "<td align='center'> <b> subject </b> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <b> $name[response] </b> </td>";
echo "<td align='center'> <b> response </b> </td>";
echo "</tr>";
echo "<tr>";
echo ' <td align="center"> <form method="POST" action="showcontact.php">
<input type="text" name="response" height="50pt"/> <br/>
<input type="submit" value="send" name="send"> </form> </td>';
echo "<td align='center'> <b> answer </b> </td>";
echo "</tr>";
if(isset($_POST['response'])) {
$response = $_POST['response'];
$sql = ("UPDATE contact SET response = '$response' WHERE id= $name[id]");
$rst = mysqli_query($con,$sql);
if($rst){
echo "<td align='center'> <b> sent </b> </td>" ;
echo " <td align='center'> </td>";
} else {
echo "<td align='center'> <b> did not send </b> </td>";
echo " <td align='center'> </td>";
echo "</table>";
}
}
}
?>
Having everything in a loop makes it hard to read your code.
You need a contact id to attach a response to.
Here's a brief overview of how I'd do it:
loop through contacts
row begins
display contact info
display response form
row ends
end loop
response form:
give it a post method
add a hidden contact id field <--
response input (text)
submit button
Form processing logic:
if this is a post request, and we have an id and response:
do your SQL update
I'd place the form processing out the loop at the top of your script, or on another page.

Display number sequence based on the number of data in database

How can I display the number based on the number of data from database.
For example, the above picture, shows data extract from the database. In my database there are two data. Therefore I would like to display number 1 and 2 at the No column.
And if there is four data in the database, I would like to display number 1, 2, 3 and 4 at the No column.
Coding to display the above table
<?php
$sql= mysql_query ("SELECT * FROM employee INNER JOIN cash ON employee.emp_id = cash.emp_id WHERE cash_status='Pending'");
echo "<table id='dataTable' width='850' border='1' align='center'>";
echo "<tr>
<th height='50'>No</th>
<th height='50'>Employee Number</th>
<th height='50'>Name</th>
<th height='50'>Department</th>
<th height='50'>Date Apply</th>
<th height='50'>Date Cash To Be Use</th>
<th height='50'>Amount</th>
<th height='50'>Status</th>
<th height='50'>Cash Id</th>
<th height='50'>View</th>
</tr>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr>";
echo "<td align='center' height='30'></td>";
echo "<td align='center' height='30'>" .$row['emp_id']. "</td>";
echo "<td align='center' height='30'>" .$row['emp_name']. "</td>";
echo "<td align='center' height='30'>" .$row['emp_department']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_dapply']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_duse']. "</td>";
echo "<td align='center' height='30'>RM" .$row['cash_amount']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_status']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_id']. "</td>";
echo"<td height='30'><img src='../img/view_user.png' width='20' height='20'></td>";
echo "</tr>";
}
echo "</table>";
?>
Thanks.
Try with the Below Code :
<?php
$i = 0;
$sql= mysql_query ("SELECT * FROM employee INNER JOIN cash ON employee.emp_id = cash.emp_id WHERE cash_status='Pending'");
echo "<table id='dataTable' width='850' border='1' align='center'>";
echo "<tr>
<th height='50'>No</th>
<th height='50'>Employee Number</th>
<th height='50'>Name</th>
<th height='50'>Department</th>
<th height='50'>Date Apply</th>
<th height='50'>Date Cash To Be Use</th>
<th height='50'>Amount</th>
<th height='50'>Status</th>
<th height='50'>Cash Id</th>
<th height='50'>View</th>
</tr>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr>";
echo "<td align='center' height='30'>".$++i."</td>";
echo "<td align='center' height='30'>" .$row['emp_id']. "</td>";
echo "<td align='center' height='30'>" .$row['emp_name']. "</td>";
echo "<td align='center' height='30'>" .$row['emp_department']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_dapply']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_duse']. "</td>";
echo "<td align='center' height='30'>RM" .$row['cash_amount']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_status']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_id']. "</td>";
echo"<td height='30'><img src='../img/view_user.png' width='20' height='20'></td>";
echo "</tr>";
}
echo "</table>";
?>
#Hardy Change .$++i. to .++$i.

PHP script not passing url with a array variable

This code is not passing URL to make topic clickable main problem is in third line after while loop. I got this error :
Parse error: syntax error, unexpected 'id' (T_STRING), expecting ',' or ';' in D:\xmapp\htdocs\forum\main_forum.php on line 37
Code :
while($rows=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' bgcolor=#FFFFFF>",$rows['id'],"</td>";
echo "<td bgcolor='#FFFFFF'>",'$rows['topic']. ',"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['view'],"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['reply'],"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['datetime'],"</td>";
}
Please try this. there is syntax error in your code.
echo "<tr>";
echo "<td align='center' bgcolor=#FFFFFF>",$rows['id'],"</td>";
echo "<td bgcolor='#FFFFFF'>",''.$rows[topic]. ' ',"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['view'],"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['reply'],"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['datetime'],"</td>";
This should correct your problem, Use
echo "<td bgcolor='#FFFFFF'><a href='".$view_topic.".php?id=".$rows['id']."'>".$rows['topic']."</a></td>";
instead of
echo "<td bgcolor='#FFFFFF'>",'$rows['topic']. ',"</td>";
One more thing, Why dont you use php tag only when needed. If you do like this it will be clean and easy.
<?php
while($rows=mysql_fetch_array($result))
{
?>
<tr>
<td> <?php $rows['topic']; ?> </td>
.......
.......
</tr>
<?php } ?>
Try this :
while($rows = mysql_fetch_array($result)){
echo "<tr>";
echo "<td align='center' bgcolor=#FFFFFF>".$rows['id']."</td>";
echo "<td bgcolor='#FFFFFF'><a href='".$view_topic.".php?id=".$rows['id']."'>".$rows['topic']."</a></td>";
echo "<td align='center' bgcolor='#FFFFFF'>".$rows['view']."</td>";
echo "<td align='center' bgcolor='#FFFFFF'>".$rows['reply']."</td>";
echo "<td align='center' bgcolor='#FFFFFF'>".$rows['datetime']."</td>";
}

How to Show Popup window on clicking dynamically generated link

T have one page on which results are get created dynamically. And I
want to display popup window on clicking image named view.jpg. The
image is hyperlink. So please tell me how should i do it. I am showing
my code as follows.
code :
echo "<table width='' height='' border='1' align='center'>
<tr><td>Title</td>
<td >Type</td>
<td >Date</td>
<td>Expiry Date</td>";
if($typeofuser=='admin' || $typeofuser=='Accountant' || $typeofuser=='secretary')
{
echo "<td>View</td>
<td>Edit</td>
<td>Delete</td>";
}
echo "</tr>";
$qry2 = mysqli_query($con,"SELECT nId,nTitle,nDescription,nDate,nExpiryDate FROM tblnoticemanager where Society_id = '$socId' and category='General'") or die(mysqli_error($con));
while($NoticeData = mysqli_fetch_array($qry2))
{
echo "<tr>";
echo "<td align='center' class='tdletter' style='text-transform:capitalize;'>" .$NoticeData['nTitle']. "</td>";
echo "<td align='center' class='tdletter' ><div class='overflowDiv'>" . $NoticeData['nDescription']."</div></td>";
echo "<td align='center' class='tdletter'>" . $NoticeData['nDate'] ."</td>";
echo "<td align='center' class='tdletter'>" . $NoticeData['nExpiryDate'] ."</td>";
if($typeofuser=='admin' || $typeofuser=='Accountant' || $typeofuser=='secretary')
{
echo "<td align='center' class='tdletter'><div><a href='?id=".urlencode(base64_encode($NoticeData['nId']))."'><img src='images/view.png' width='30' height='30' align='center' /></a></div></td>";
echo "<td align='center' class='tdletter'><div><a href='?id=".urlencode(base64_encode($NoticeData['nId']))."' ><img src='images/edit.jpg' width='30' height='30' align='center'/></a></div></td>";
echo "<td align='center' class='tdletter'><span id='".$NoticeData['nId']."' class='trash'><img src='images/delete1.jpg' width='30' height='30' align='center' /></span></td>";
}
echo "</tr>";
}
echo "</table>";
You can use attribute selector [attribute='value']
$("[src='images/view.png']").click(function(){
alert("clicked");
});

Categories