I'm loading data from an xml file into a html table then adding a check box column at the end with the view of saving the data from each row where the check box is checked, for now I just want to display the rows with the check box checked.
In my first page I have the code below which successfully loads the xml data in to the html table and displays it as I wanted, forgive my code, it is a bit messy as I'm new to PHP.
<?php
<form method="POST" action="saved.php">
echo "<input type='submit' name='save' value='Save Checked Rows' />";
$all = simplexml_load_file('list.xml');
echo "<div style='height:200px; overflow-y: scroll;'>";
echo "<table border=\"1\">";
echo "<th>Title</th><th>Description</th><th>Link</th><th>Save</th>\n";
echo "<tr>";
$c=0;
foreach ($all as $current) {
$title=$current->title;
$description=$current->description;
$link=$current->link;
echo "<td>{$title}</td><td>{$description}</td><td><a href=$link>$link</a></td><td><input type='checkbox' name='save[]' value='$c' /></td>";
$c++;
echo "</tr>\n"; }
echo "</table>";
echo "</div>";
echo "</form>"
?>
On my second page I have the code below which displays the value of every check box that is checked when I submit the first page
<?php
Session_start();
?>
<?php
foreach($_POST['save'] as $key){
echo $key;}
}
?>
I need to get the data from the other table cells on the checked rows, the only idea that worked so far was putting an input in to the cell but I don't want that because the cells have to be uneditable. Thanks for the help !
For that there is an atribute in html which you can use i,e read only
Related
<div class="form-group">
<td><label for="genre">Names</label></td>
<td>
<?php
foreach($array as $row){
echo "<div class='form-check form-check-inline'>";
echo "<label class='form-check-label'>";
echo "<input class='form-check-input' type='checkbox' name='genre_checked[]' value='".$row->name."'>";
echo $row->name;
echo "<label>";
echo "</div>";
}?>
</td>
</div>
I'm making a form to submit to my controller and inside that form, i am printing an array inside a "" but the way i've coded it is that it will print in a single column from top to bottom and makes the "td" height increase. I wanted to make use of the extra space so instead of increasing the height i atleast wanted to make use of the td width.
Nevermind. After a few hours of sleep. Took only 5mins.
<?php
foreach($genre as $row){
echo "<div class='col-lg-2'>";
echo "<input type='checkbox' name='genre_checked[]' value='".$row->genre_name."'>";
echo $row->genre_name;
echo "</div>";
}?>
I have these codes and am not good at php please can someone help me on how to echo the videos to appear horizontall in my page thanks in advance
<?php
$h=2;
$k=mysql_query("SELECT * from aupload where type='audios' and view>='$h' order by view DESC");
while ($la=mysql_fetch_array($k)){
?>
<center>
<table width='100%'height=''>
<tr>
<?php echo"<td>" . "<a href='uploads/$la[filename]'><img src='uploads/$la[size]' width='180px' height='180px'>
<br><b>$la[filename]</b><br><a href='music1.php?id=".$la['id']."'><input type='button' value='DOWNLOAD'><input type='button' value='$la[view]'> </a></a>
"?></td>
</tr>
</table><br>
</center>
<?php }?>
<?php
include('connect.php');
$k=mysql_query("SELECT * from aupload where type='audios'");
#$la=mysql_fetch_array($k)
?>
<?php
$h=2;
$y=mysql_query("SELECT * from aupload where type='videos' and view>='$h' order by view DESC ");
?>
<table border='0' id='myTable'width='100%'>
<?php
while ($x=mysql_fetch_array($y)){
echo "<tr>";
echo "<td>" . "<video id='myVideo' onclick='message()' width='180px' height='180px' controls><source src='uploads/$x[filename]' '></video>" . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='' height=''>"."<a href='music2.php?id=$x[id]' > <b>$x[filename]</b><br><input type='button' value='DOWNLOAD'></a>" ."<input type='button' value='$x[view]'></a></a>". "</td>";
echo "</tr>";
}
echo "</table>"; echo"</center>";
?>
the problem is when I upload two or more videos they appear vertically but I just want them to appear horizontally when echo them please someone help and thanks
Use frames is the best way to display a video, try this code
This is actually a HTML question, not a PHP question. In HTML, designates a table row, and can contain many or table cell elements. So you want to have the a echoed before the while loop, then print just the elements in the while loop, then print the . This will put all the elements in a single table row.
I have a table with several buttons with "SHOW" text. Everytime I click one of those buttons I'd like that rows with class ".infotr" appears and when I click again the same button those rows disappear. (I mean the ".infotr" rows of the same table of the clicked button.)
<?php
$sql="SELECT * FROM mytable WHERE ID='$id'";
$res=mysqli_query($db,$sql);
while($row = mysqli_fetch_array($res))
{
echo "<table id='tablemodificamobile'>";
echo "<tr id='firsttr'>";
echo "<td id='amid' class='modificatd'>".$myid."</td>";
echo "<td id='amtitle' class='modificatd'>".$row['Title']."</td>";
echo "<td id='amshow' class='modificatd'><input type='button' id='mostramodbtn' value='SHOW'></input></td>";
echo "</tr>";
echo "<tr class='infotr'><td class='addinfo'>New Price: ".$row['NewPrice']."</td></tr>";
echo "<tr class='infotr'><td class='addinfo'>Old Price: ".$row['OldPrice']."</td></tr>";
echo "<tr class='infotr'><td class='addinfo'><input type='button' value='SAVE' id='modit'></input></td></tr>";
echo "</table>";
}
?>
This is what I tried but it doesn't work:
$('#mostramodbtn').click(function() {
$(this).parents("tr").nextAll().show();
});
Use this:
$(document).on('click','#mostramodbtn',function() {
$(this).parents("tr").nextAll().toggle("slow");
});
You are creating the element dynamically so you need to bind the even on document with .on function.
Learn more about .on() function in jQuery here.
I am a newbie to PHP and MySQL, so please ignore my bad practice of coding :)
Ok, here's the scenario:
I have a page, checkin.php which has two forms;
Form 1: Takes some input and displays data from database along with multiple checkboxes.
Form 2: It is dynamically generated if any data is found above.
Here's the code:
//Echoing out the query results
echo "<form method='POST' action='checkin.php'>";
echo "<tbody>";
foreach ($checkin_status as $row) {
echo "$rowStart";
echo "$row[book_id]";
echo "$insertColumn";
echo "$row[branch_id]";
echo "$insertColumn";
echo "$row[card_no]";
echo "$insertColumn";
echo "$row[fname]" . " " . "$row[lname]";
echo "$insertColumn";
echo "$row[date_out]";
echo "$insertColumn";
echo "$row[due_date]";
echo "$insertColumn";
//Checkbox creation
$checkin_recall_value = "$row[book_id]" . " " . "$row[branch_id]" . " " . "$row[card_no]";
echo "<div style='text-align: center;'><input type='checkbox' name='checkin' value='$checkin_recall_value'></div>";
echo "$rowEnd";
}
echo "</tbody>";
//Checkin button in foot
echo "<tfoot>";
echo "<td colspan='7' style='text-align: center; padding-right: 20px;'><input id='checkin_button' type='submit' value='Check In' title='Click to check in!'></td>";
echo "</tfoot>";
echo "</form>";
The form is generated with checkboxes along side the returned tuples.
Now when I am selecting some checkboxes and trying to display, it WONT...
Here is the code:
if(!empty($_POST['checkin'])) {
//Retrieving the recall variables as an array from POST and assigning to $main_array
$main_array = array();
//echo "I am here";
if(is_array($_POST['checkin'])) {
foreach($_POST['checkin'] as $value)
{
$sub_array = explode(" ", $value);
array_push($main_array, $sub_array);
}
}
print_r($main_array);
}
Its returning an empty array...
Please help me fix this.
IF you want to have multiple html elements with the same name, you must define it as an array, adding []:
<input type='checkbox' name='checkin[]' value='$checkin_recall_value'>
I have created button using this:
$i=1;
while($row=mysql_fetch_array($e))
{
echo '<td><img src="'.$path.$row['photo'].'" border="0" width=100 height=50/></td>';
echo $row['fname'];
echo "<input type=\"button\" value=\"send request\" name=\"$i\" onclick=\"sendreq('".$row['uname']."')\"/>";
//echo $i;
echo "<br/>";
$i=$i+1;
}
and passing the username onclick of the button through sendreq() function.This is javascript function. I just want to hide this button when sendreq() job is done.
You could use the javascript to assign is the display:none; CSS attribute, though I am uncertain whether it would have to be applied to an encapsulating div or whether it would work directly on the image itself.
$i=1;
while($row=mysql_fetch_array($e))
{
echo '<td><img src="'.$path.$row['photo'].'" border="0" width=100 height=50/>
</td>';
echo $row['fname'];
echo "<input id='btnSubmit' type=\"button\" value=\"send request\" name=\"$i\"
onclick=\"sendreq('".$row['uname']."');
document.GetElementById('btnSubmit').hide(); \"/>";
//echo $i;
echo "<br/>";
$i=$i+1;
}
after the method is executed, the element will hide.
you can add this line at the end of the function.
<script>
jQuery("#btnSubmit").hide();
</script>
hope this helps...
edit your input button tag like this
assign a id to button (such as i used remove as id here) and add this code on last of the function sendreg
document.getElementById("remove").style.display='none';
or use jquery functions like
$("#remove").hide();
or $("#remove").fadeOut(3000);