hi everyone im creating simple posting grade online.
the problem is how i can save all value inside the while loop
here is the code
$sql1 = mysql_query("SELECT * FROM tblsubjecschedule where sched_id='".$col."' ")or die(mysql_error());
while($val=mysql_fetch_array($sql1)){
$Subject=$val['Subject'];
}
echo "<tr><td width=''><font face='Arial' size='3pt'>Subjec Code</td><td width=''><font face='Arial' size='3pt'>".$Subject."</td></tr><tr>
<td width=''><font face='Arial' size=''>Student Name</td>
<td width=''><font face='Arial' size=''>Course</td>
<td width=''><font face='Arial' size=''>Prelim</td>
<td width=''><font face='Arial' size=''>Midterm</td>
<td width=''><font face='Arial' size=''>Semi</td>
<td width=''><font face='Arial' size=''>Final</td>
</tr>";
echo "</thead>
<tfoot></tfoot>
<tbody>";
$sql = mysql_query("SELECT * FROM tblstudntsub where Sublink='".$control."' order by studname ASC")or die(mysql_error());
$a=0;
$b=1;
while($row=mysql_fetch_assoc($sql)){
$id=$row['id'];
$name=$row['studname'];
$cor=$row['course'];
$yl=$row['YearLevel'];
echo"<tr bgcolor='#E6E6E6'>
<td align='left'><p align='left'>".$b.".".$name."</p><input type='hidden' name='cont[$a]' value=".$id."></td>
<td><p align='left'>".$cor."</p></td>
<td> <input type='text' name='pre[$a]' value=''style='width:40px;'></td>
<td> <input type='text' name='mid[$a]' value=''style='width:40px;' ></td>
<td> <input type='text' name='semi[$a]' value=''style='width:40px;' ></td>
<td> <input type='text' name='fin[$a]' value=''style='width:40px;' ></td>
</tr>";
$a++;
$b++;
}
echo " <tr><td>
<input type='submit' name='save[$a]' value='Save'/>
</td></tr>";
echo "</tbody><table>";
sorry for my bad grammar hope you understand what i mean.
THANK YOU IN ADVANCE
Create an array to save all the subject,
Like
$subject= array();
$i=0;
while($row=mysql_fetch_assoc($records))
{
$subject[$i]=$row['subject'];
$i++;
}
Hope it helps
better to write code inside the loop like this
while(.......)
{
...
?>
<tr>
<td>fdsf</td>
</tr>
<?php
}
?>
Construct an array for each value and store data to it.
Related
I'm trying to create echo image in while loops with table, but I'm getting the error . please see part of the code
$image = $rows['image'];
$sql = "SELECT * FROM boxes ";
$result = $db->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
if ($row['status'] == 1)
$visible = "visible";
else
$visible = "hidden";
if ($row['side'] == 1)
$side = "right";
else if ($row['side'] == 2)
$side = "left";
else $side = "not set yet";
echo "
<tr>
<td width=\"15%\" rowspan=\"3\"><img src="data:image' image \. ($row['image']).'" />';</td>
<td width=\"85%\" colspan=\"5\">".$row['title_boxe'] . "</td>
</tr>
<tr>
<td colspan=\"5\">desc</td>
</tr>
<tr>
<td>Visible</td>
<td>sss</td>
<td><form method='post'><input type='hidden' name='id' value='" . $row['id_boxe'] . "'/>
<input type='submit' name='update' value='Update' class=\"btn btn-primary\"/></form></td>
<td> </td>
</tr>
<tr>
<td colspan=\"6\">hr</td>
</tr>
<tr>
<td colspan=\"6\"> </td>
</tr>
";
}
}
?>
</tbody>
</table>
what wrong with this line of code inside of php that i can figure out how to solve this...
<td width=\"15%\" rowspan=\"3\"><img src="data:image' image \. ($row['image']).'" />';</td>
many thanks for your help.
Seems that you echo is wrong ( and to me is not clear what you are doing with <src='data:image image .. if you need a \ but this interfer
with quote escape it using \
echo "
<tr>
<td width='15%' rowspan='3'><img src='../image/box-manage/" . $row['image'] ."' />;</td>
<td width='85%' colspan='5'>". $row['title_boxe'] . "</td>
</tr>
<tr>
<td colspan='5'>desc</td>
</tr>
<tr>
<td>Visible</td>
<td>sss</td>
<td><form method='post'><input type='hidden' name='id' value='" . $row['id_boxe'] . "'/>
<input type='submit' name='update' value='Update' class='btn btn-primary'/></form></td>
<td> </td>
</tr>
<tr>
<td colspan='6'>hr</td>
</tr>
<tr>
<td colspan='6'> </td>
</tr>";
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 8 years ago.
I am trying to delete some rows when users check them with check button. I have created a button called delete, but I have a problem. It said to me that variable delete that I use here
// Check if delete button active, start this if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM Aktivitet WHERE Id_Akt='$del_id'"; $result = mysql_query($sql); } is not defined... But why because I have declared it as the name of Delete button...here I have created the Delete button;
print("<tr>");
print("<td><input name='delete' type='submit' id='delete' value='Delete'></td>");
print("</tr>");
Please can you help me? What can I do? My php file is below:
<?php
$con = mysql_connect('127.0.0.1','root','');
if (!$con)
{
die('Lidhja me databazen nuk mund te kryhet' .mysql_error(). ' </body></html>');
}
if(!mysql_select_db("Axhenda",$con))
die('Nuk mund te hapet databaza Axhenda'.mysql_error(). '</body></html>');
$result = mysql_query("SELECT * FROM Aktiviteti where Data= '$_POST[dataoutput]'");
mysql_close($con);
?>
<div class="title"> Aktivitetet per daten <?php print ("$_POST[dataoutput]"); ?></div>
<table>
<?php
print("<th >");
print("<form name='form1' method='post' action=''>");
print("<td>Emertimi takimit</td>");
print("<td>Pershkrimi takimit</td>");
print("<td>Oraa takimit</td>");
print("</th >");
while($rows=mysql_fetch_row($result))
{
if (!empty($rows))
{
print("<tr >");
print("<td align='center' bgcolor='#FFFFFF'><input
name='checkbox[]' type='checkbox' id='checkbox[]' value='$rows[0]'></td>");
print("<td bgcolor='#FFFFFF'>$rows[2]</td>");
print("<td bgcolor='#FFFFFF'>$rows[3]</td>");
print("<td bgcolor='#FFFFFF'>$rows[5]</td>");
print("</tr>");
}
else
echo "ska aktivitet";
}
print("<tr>");
print("<td><input name='delete' type='submit' id='delete' value='Delete'></td>");
print("</tr>");
?>
<?php
// Check if delete button active, start this
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM Aktivitet WHERE Id_Akt='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">";
}
}
print("</form>");
?>
</table>
I modified the function like below, but it still dont delete anything:
if(isset($_POST['delete'])){
$checkbox = $_POST['checkbox'];
$count = count($checkbox);
for($i = 0; $i < $count; $i++) {
$id = (int) $checkbox[$i];
if ($id > 0) { // and check if it's bigger then 0
mysql_query("DELETE FROM Aktiviteti WHERE Id_Akt= $id");
}
}
}
please help me..
Tested on my own server. You will need to modify it for your own columns as well as other elements that need to be translated in your language.
Change settings for the following:
DEFINE ('DB_HOST', 'xxx');
DEFINE ('DB_USER', 'xxx');
DEFINE ('DB_PASSWORD', 'xxx');
DEFINE ('DB_NAME', 'xxx');
And: (Note: the # is just a reference character. You can change it to what you like.)
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Link ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Link Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Link Email</strong></td>
And change: (The rows you wish to show up. There are two of these. One is to show the rows, while the other is used for deletion.)
<td bgcolor="#FFFFFF"><?php echo $row['id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row['name']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row['email']; ?></td>
And change: (delete.php is this file to redirect to after deleting)
echo "<meta http-equiv=\"refresh\" content=\"3;URL=delete.php\">";
And change: ( your_table ) and the id depending on which column you want to ORDER BY
$query = "select * from your_table ORDER BY id ASC";
And change:
$sql = "DELETE FROM your_table WHERE link_id='$del_id'";
And change: all instances of link_id being the id (column name) associated with the deletion.
Full script: (delete.php)
<html>
<head>
<title></title>
</head>
<body>
<h2>Choose and delete selected items.</h2>
<?php
DEFINE ('DB_HOST', 'xxx');
DEFINE ('DB_USER', 'xxx');
DEFINE ('DB_PASSWORD', 'xxx');
DEFINE ('DB_NAME', 'xxx');
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die("could not connect");
$query = "select * from your_table ORDER BY id ASC";
$result = mysqli_query($dbc,$query)
or die('Error querying database');
$count=mysqli_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="3" bgcolor="#FFFFFF"><strong>Delete multiple items</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Link ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Link Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Link Email</strong></td>
</tr>
<?php
while ($row=mysqli_fetch_array($result)) {
?>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name="checkbox[]" type="checkbox" value="<?php echo $row['link_id']; ?>">
</td>
<td bgcolor="#FFFFFF"><?php echo $row['id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row['name']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row['email']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" value="Delete"></td>
</tr>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="3" bgcolor="#FFFFFF"><strong>Delete multiple items</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Link ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Link Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Link Email</strong></td>
</tr>
<?php
while ($row=mysqli_fetch_array($result)) {
?>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name="checkbox[]" type="checkbox" value="<?php echo $row['link_id']; ?>">
</td>
<td bgcolor="#FFFFFF"><?php echo $row['id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row['name']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row['email']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" value="Delete"></td>
</tr>
<?php
if(isset($_POST['delete']))
{
$checkbox = $_POST['checkbox'];
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM your_table WHERE link_id='$del_id'";
$result = mysqli_query($sql);
}
// if successful redirect to delete.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"3;URL=delete.php\">";
// echo "Got results.";
}
}
mysqli_close($dbc);
?>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
Try this:
if(isset($_POST['delete'])){
foreach($_POST['checkbox'] as $del_id){
$sql = "DELETE FROM Aktivitet WHERE Id_Akt='$del_id'";
$result = mysql_query($sql);
}
}
Hi to all i have a problem, i want to remove the duplicate value from my looping
eg.
I have a 4 record,
It must be 4 records display from my output, the problem is, it display a 16 records that's why I need to remove duplicate from my looping statement
See my code below
coming from submit
<input type='text' value='<?php echo "$row[partyid]"; ?>' name='phonenum[]' readonly />
for ($i=0; $i<sizeof($phonenum);$i++)
{
$sql = "SELECT *
FROM
$table2,
$table3
WHERE
$table2.billdate = '$date'
AND $table3.tel_three LIKE '%$phonenum[$i]%'
";
<?php if( $rs == null ):?>
<tr>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
</tr>";
<?php else:?>
<?php while( $row = mysql_fetch_assoc($rs) ):
?>
<tr>
<form action='flookup.php' method='post'>
<td align='center'><?php echo "<font size=1>".$row['billdate']."</font>"; ?></td>
<td align='center'><?php echo "<font size=1>".$row['calldate']."</font>"; ?></td>
<td align='center'><?php echo "<font size=1>".$row['partyid']."</font>"; ?></td>
<td align='center'><?php echo "<font size=1>".$row['billedamount']."</font>"; ?></td>
<td align='center'>
<?php echo "<font size=1>".$row['partyid']."</font>"; ?>
<input type='hidden' value="<?php echo $row['partyid']; ?>" name='phonenum' readonly />
</td>
<td align='center'><?php echo "<font size=1>".$row['value']."</font>"; ?>
<input type='hidden' value="<?php echo $row['value']; ?>" name='sipvalue' readonly />
<td align='center'><input type='text' value="<?php echo $row['value']; ?>" name='value' readonly />
</td>
</tr>
<?php endwhile;?>
<?php endif;
}
?>
You need to modify your SQL statement to add a joining condition between $table2 and $table3
$sql = "SELECT *
FROM
$table2,
$table3
WHERE
$table2.billdate = '$date'
AND $table3.tel_three LIKE '%$phonenum[$i]%'
AND $table2.something = $table3.something
";
I have a table in my DB which I call to show everything in that table on a page one of the items in the table is an image which when moused over needs to show a popup showing data from a separate table which corresponds to that item. I have a JQuery which calls the data depending on the row from the 1st table but when I try to actually put the two together I get the first table showing fine but now I get no pop up on mouseover.
This page is currently included in the index.php page which has the scripts to call the .js / .css files.
Here's the code for what I am trying to do:
<html>
<table border='0' cellpadding='0' cellspacing='0' class="center2">
<tr>
<td width='60'><img src="images/box_tl.png"></td>
<td style="background: url(images/box_tm.png)" align="center"><img src="images/news.png"></td>
<td width='25'><img src="images/box_tr.png"></td>
</tr>
<tr>
<td style="background: url(images/box_ml.png)"><h2>.</h2></td>
<td style="background: url(images/box_mm.png)">
<?php
include 'connect.php';
$query = mysql_query("SELECT * FROM tbl_img") or die(mysql_error());;
echo "<table border='0' cellpadding='1' cellspacing='1' width'90%' id='1' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Mob Name</th> <th>Id</th> <th>Health</th> <th>Body</th> <th>Effects</th> <th>Spawn</th></tr></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query )) {
$mob_id = $row['mob_id'];
$mob = $row['mob'];
$body = $row['body'];
$mob_name = $row['mob_name'];
$health = $row['health'];
$level = $row['level'];
// Print out the contents of each row into a table
echo "<tr><td>";
echo "<img src='/testarea/include/mobs/$mob' />";
echo "</td><td>";
echo $mob_name;
echo "</td><td>";
echo $level;
echo "</td><td>";
echo $health;
echo "</td><td>";
echo
"
<a onmouseover='popup($('#hidden-table').html(), 400);' href='somewhere.html'><img src='/testarea/include/mobs/dead/$body' /></a>
";
echo "
<div id='hidden-table' style='display:none;'>
<table border='0' cellpadding='0' cellspacing='0' class='center3'>
<tr>
<td width='14'><img src='images/info_tl.png'></td>
<td style='background: url(images/info_tm.png)' align='center'></td>
<td width='14'><img src='images/info_tr.png'></td>
</tr>
<tr>
<td style='background: url(images/info_ml.png)'><h2>.</h2></td>
<td style='background: url(images/info_mm.png)'>
";
$query2 = mysql_query("SELECT * FROM tbl_drop WHERE mob_name='$mob_name'") or die(mysql_error());;
echo "<table border='0' cellpadding='1' cellspacing='1' width='250' id='2' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Item Name</th> <th>Qty</th></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query2 )) {
$id = $row['id'];
$item_img = $row['item_img'];
$qty = $row['qty'];
$item_name = $row['item_name'];
// Print out the contents of each row into a table
echo "<tr><td width='50'>";
echo "<img src='/testarea/item/$item_img' />";
echo "</td><td width='150'>";
echo $item_name;
echo "</td><td width='50'>";
echo $qty;
echo "</td></tr>";
}
echo "</tbody></table>";
echo "
</td>
<td style='background: url(images/info_mr.png)'><h2>.</h2></td>
</tr>
<tr>
<td width='14'><img src='images/info_bl.png'></td>
<td style='background: url(images/info_bm.png)' align='center'><h2>.</h2></td>
<td width='14'><img src='images/info_br.png'></td>
</tr>
</table>
</div>"
;
echo "</td><td>";
echo "test";
echo "</td><td>";
echo "test";
echo "</td></tr>";
}
echo "</tbody></table>";
?>
</td>
<td style="background: url(images/box_mr.png)"><h2>.</h2></td>
</tr>
<tr>
<td width='60'><img src="images/box_bl.png"></td>
<td style="background: url(images/box_bm.png)" align="center"><h2>.</h2></td>
<td width='25'><img src="images/box_br.png"></td>
</tr>
</table>
</html>
you have two semi-colons on this line...could be the problem
$query = mysql_query("SELECT * FROM tbl_drop WHERE mob_name='$mob_name'") or die(mysql_error());;
everything works perfect bar the div 'hidden-table' not showing, if i remove the 'style:display:none' then it shows the table with correct data so i know its working and i have tried the taking the popup out of the echo and displaying it separately just to see if it shows which it does.
seems the problem occurs only when its in the echo and seems centred around the 'onmousover'
full page code:
<html>
<table border='0' cellpadding='0' cellspacing='0' class="center2">
<tr>
<td width='60'><img src="images/box_tl.png"></td>
<td style="background: url(images/box_tm.png)" align="center"><img src="images/news.png"></td>
<td width='25'><img src="images/box_tr.png"></td>
</tr>
<tr>
<td style="background: url(images/box_ml.png)"><h2>.</h2></td>
<td style="background: url(images/box_mm.png)">
<?php
include 'connect.php';
$query = mysql_query("SELECT * FROM tbl_img") or die(mysql_error());;
echo "<table border='0' cellpadding='1' cellspacing='1' width'90%' id='1' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Mob Name</th> <th>Id</th> <th>Health</th> <th>Body</th> <th>Effects</th> <th>Spawn</th></tr></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query )) {
$mob_id = $row['mob_id'];
$mob = $row['mob'];
$body = $row['body'];
$mob_name = $row['mob_name'];
$health = $row['health'];
$level = $row['level'];
// Print out the contents of each row into a table
echo "<tr><td>";
echo "<img src='/testarea/include/mobs/$mob' />";
echo "</td><td>";
echo $mob_name;
echo "</td><td>";
echo $level;
echo "</td><td>";
echo $health;
echo "</td><td>";
echo
"
<a onmouseover='popup($('#hidden-table').html(), 400);' href=''><img src='/testarea/include/mobs/dead/$body' /></a>
";
echo "
<div id='hidden-table' style='display:none;'>
<table border='0' cellpadding='0' cellspacing='0' class='center3'>
<tr>
<td width='14'><img src='images/info_tl.png'></td>
<td style='background: url(images/info_tm.png)' align='center'></td>
<td width='14'><img src='images/info_tr.png'></td>
</tr>
<tr>
<td style='background: url(images/info_ml.png)'><h2>.</h2></td>
<td style='background: url(images/info_mm.png)'>
";
$query2 = mysql_query("SELECT * FROM tbl_drop WHERE mob_name='$mob_name'") or die(mysql_error());
echo "<table border='0' cellpadding='1' cellspacing='1' width='250' id='2' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Item Name</th> <th>Qty</th></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query2 )) {
$id = $row['id'];
$item_img = $row['item_img'];
$qty = $row['qty'];
$item_name = $row['item_name'];
// Print out the contents of each row into a table
echo "<tr><td width='50'>";
echo "<img src='/testarea/item/$item_img' />";
echo "</td><td width='150'>";
echo $item_name;
echo "</td><td width='50'>";
echo $qty;
echo "</td></tr>";
}
echo "</tbody></table>";
echo "
</td>
<td style='background: url(images/info_mr.png)'><h2>.</h2></td>
</tr>
<tr>
<td width='14'><img src='images/info_bl.png'></td>
<td style='background: url(images/info_bm.png)' align='center'><h2>.</h2></td>
<td width='14'><img src='images/info_br.png'></td>
</tr>
</table>
</div>"
;
echo "</td><td>";
echo "test";
echo "</td><td>";
echo "test";
echo "</td></tr>";
}
echo "</tbody></table>";
?>
</td>
<td style="background: url(images/box_mr.png)"><h2>.</h2></td>
</tr>
<tr>
<td width='60'><img src="images/box_bl.png"></td>
<td style="background: url(images/box_bm.png)" align="center"><h2>.</h2></td>
<td width='25'><img src="images/box_br.png"></td>
</tr>
</table>
</html>
You're inadvertently ending your onmouseover event when you try to reference your jQuery selector. The use of single quotes for different reasons is the reason. Try this instead:
function ShowPop()
{
popup($('#hidden-table').html(), 400);
}
<a onmouseover='ShowPop()' href=''><img ..... /></a>