How to Show Popup window on clicking dynamically generated link - php

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");
});

Related

PHP - How to change font size of HTML table?

I'm generating table in a foreach loop
echo "<tr>";
echo "<td align='left' bgcolor='$bgclr'>".$monthName."</td>";
echo "<td align='center' bgcolor='$bgclr'>".$id."</td>";
echo "<td align='center' bgcolor='$bgclr'>".$total."</td>"
echo "</tr>";
I need to increase font size of the table, but i'm not sure how. Does the html table has attribute to set font size or I should use CSS ?
Just use font style css in style attribute :
echo "<tr>";
echo "<td align='left' bgcolor='$bgclr' style='font-size:10px'>".$monthName."</td>";
echo "<td align='center' bgcolor='$bgclr' style='font-size:10px'>".$id."</td>";
echo "<td align='center' bgcolor='$bgclr' style='font-size:10px'>".$total."</td>"
echo "</tr>";
use the html styling on the echoed elements. For example echo '<table style="font-size: 100px">';
You need to define font size in one variable and then use in inline as below code:
foreach{
$fontsize = 'font-size: '.((isset(FONT_SIZE_IN_FOREACH))?FONT_SIZE_IN_FOREACH:12);
echo "<tr>";
echo "<td align='left' bgcolor='$bgclr' style='$fontsize'>".$monthName."</td>";
echo "<td align='center' bgcolor='$bgclr'>".$id."</td>";
echo "<td align='center' bgcolor='$bgclr'>".$total."</td>"
echo "</tr>";
}
You can add class to the table and write css for that class.
HTML:
<table class='fontsize'>
</table>
CSS:
.fontsize {
font-size:16px;
}

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>";
}

Notice: Undefined index:

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'

Displaying user avatar or default avatar on search

Im having a problem with my PHP search script. I'm building a social networking site where one can search for a user, an event or a club. I would like the search results to display a user avatar thumb or a default thumb if none has been uploaded.
Im testing on localhost.
User avatar's are stored in the User_Images (c:\wamp\www\NNL\User_Images)folder while the default avatar is stored in c:\wamp\www\NNL\Style\Images\default_avatar.png.
The following is my PHP code:
<?php
while ($row_user = mysql_fetch_assoc($user))
{
echo "\n<table width='500' border='0'>";
echo "\n\t<tr>";
echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>
<img src=User_Images/$row_user[picture_thumb_url] !=''? $row_user[picture_thumb_url]: '../Style/Images/default_avatar.png'
border='0' height='50' width='50'/></a></td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_user['user_first_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_user['user_last_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_user['username']. "</td>";
echo "<td width='30'><a class='text_12_link_green' href='user_view.php?user_id=".$row_user['user_id']."'>View</a></td>";
echo "\n\t</tr>";
echo "\n</table>";
}
?>
<?php
while ($row_event = mysql_fetch_assoc($event))
{
echo "\n<table width='500' border='0'>";
echo "\n\t<tr>";
echo "<td width='50' height='50' align='center' valign='middle'><a href='#table_index.php'>
<img src='Images/$row_event[event_thumb_url]' border='0' height='50' width='50'/></a></td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_venue']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_date']. "</td>";
echo "<td width='30'><a class='text_12_link_green' href='#user_view.php?user_id=".$row_user['username']."'>View</a></td>";
echo "\n\t</tr>";
echo "\n</table>";
}
?>
<?php
while ($row_establishment = mysql_fetch_assoc($establishment))
{
echo "\n<table width='500' border='0'>";
echo "\n\t<tr>";
echo "<td width='50' height='50' align='center' valign='middle'><a href='#table_index.php'>
<img src='Establishment_Images/$row_establishment[establishment_thumb_url]' border='0' height='50' width='50'/></a></td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['establishment_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['location_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['establishment_pricing']. "</td>";
echo "<td width='30'><a class='text_12_link_green' href='#user_view.php?user_id=".$row_user['username']."'>View</a></td>";
echo "\n\t</tr>";
echo "\n</table>";
}
?>
The problem is in the $row_user while loop where im trying to echo $row_user thumb. Right now, if a user has an avatar, it displays the image, however it returns no image at all if a user has no avatar. Where am I going wrong?
you can do this although it's not exactly readable.
echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>
<img src=User_Images/" . ( $row_user['picture_thumb_url'] != '' ? $row_user['picture_thumb_url'] : '../Style/Images/default_avatar.png' ) . " border='0' height='50' width='50'/></a></td>";
You're best of doing the conditional beforehand then echo the variable:
Updated:
$thumbnail = $row_user['picture_thumb_url'] != '' ? $row_user['picture_thumb_url'] : '../Style/Images/default_avatar.png';
echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>
<img src=User_Images/$thumbnail border='0' height='50' width='50'/></a></td>";
You cannot put an 'if' statement into your 'echo'.
Go this way:
if($row_user[picture_thumb_url] !='')
$thumb = $row_user[picture_thumb_url];
else
$thumb = '../Style/Images/default_avatar.png';
And then:
echo "<img src=\"$thumb\">";

Categories