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'>
Related
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.
Longtime reader of stackoverflow but second question.
This is what i am doing
echo "<td><a href = 'http://localhost/map/index.php'
value='$id' >Delete</a></td>";
This is what we do when we use submit button
<?php
echo "<body style='background-color:gray'>";
if (isset ($_POST['submit'])){
include("connection.php");
echo " <table id='t01' border='20px solid black' width='100%' >";
echo "<tr>";
echo "<th> DETAILS ABOUT DELETION</th>";
echo "<td>DELETED SUCCESSFULLY </td></tr>";
$id = $_POST["submit"];
$select1="DELETE FROM app where id='$id'";
$result = $conn->query($select1);
if ($conn->query($result)==true){
echo "<td>DELETED SUCCESSFULLY </td></tr>";
}
echo "</table>";
//echo "DELETED SUCCESSFULLY";
}
?>
I just want to do something like that * without using input type=submit* ..... But dont know how to do
Any advice will be appreciated ... Thanks in advance
firstly pass the id in the url like so:
echo "<td><a href = 'http://localhost/map/index.php?id=$id'>Delete</a><td>";
then check it with:
if (isset ($_GET['id'])){
...
you basically swapping POST for GET
I have problem with positioning html tags I did try to solve the problem but for me the code looks fine however the output tells something different I did try do to sort out the output of SQL query however I wasn't able to achieve this and when I did asked for help in the forum in reply I get that it would be much easier to do it in PHP. So I have produce following code but I am not getting required results:
<body>
<div class="container">
<?php
$sdate = '';
foreach($rows as $row) {
if($row['shieldDate'] != $sdate){
$sdate = $row['shieldDate'];
echo '<h2>';
echo $row['shieldDate'],' ','opponent',' ',$row['shieldTeam'];
echo '</h2>';
echo "
<p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>
<table class='table'>
<thead>
<tr>
<th>Player</th>
<th>Score</th>
</tr>
</thead>
<tbody>
";
echo "<tr>";
echo "<td>";
echo $row["firstname"],' ', $row["lastname"];
echo "</td>";
echo "<td>";
echo $row["score"];
echo "</td>";
echo "</tr>";
}else{
echo "<tr>";
echo "<td>";
echo $row["firstname"],' ', $row["lastname"];
echo "</td>";
echo "<td>";
echo $row["score"];
echo "</td>";
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
</body>
I am trying to acheive following output:
However I am getting:
You don't close your tbody and table tags between two dates.
Each time you encounter a new date, you open a new table tag, but you never close it before having a new h2 date title. Add a line to close it.
$sdate = '';
foreach($rows as $row) {
if($row['shieldDate'] != $sdate){
// It's a new date
if (!empty($sdate)) {
// It's not the first date: close previous table
echo '</tbody></table>';
}
$sdate = $row['shieldDate'];
echo '<h2>';
echo $row['shieldDate'],' ','opponent',' ',$row['shieldTeam'];
echo '</h2>';
echo "<p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>
<table class='table'>
<thead>[...]</thead>
<tbody>";
[...]
} else {
[...]
}
}
if (!empty($sdate)) {
// There has been at least one date (at least one table): close it
echo '</tbody></table>';
}
Note that the [...] content is the same in if and else instructions.
You could do this to have something cleaner. The less duplicate code you have, the more easy it is to read. The more easy to read your code is, the better.
foreach($rows as $row) {
if($row['shieldDate'] != $sdate){
// Do your h2 and open table stuff
}
echo "<tr>";
echo "<td>";
// etc. No need to put it in the if AND in the else instructions.
}
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
So I'm trying to get the bootstrap accordion to dynamically show the Top 5 teams judged by most wins, I also use it for other rankings.
The problem is whenever I click tab 2, 3, or 4 it only opens tab 1 in the accordion. I know the issue is from "href='#collapse41'" being the same from every loop. I assume this will require a unique ID for each accordion div tab but I don't know how to implement it correctly. I could be 100% wrong, if so please correct me!
I've done about 15 searches on this and only found one answer, which wasn't very detailed or helpful. Any help or pointers to learn how to do this would be much appreciated.
(The reason I renamed it to #collapse41 is because I have multiple accordions on the same page.)
<div class="accordion" id="accordion2">
<?php
include 'db.php'; //connect to database
$result = mysql_query("SELECT * FROM teams ORDER BY wins DESC LIMIT 5");
$rank = 1;
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) {
echo "<div class='accordion-group'>";
echo "<div class='accordion-heading'>";
echo "<a class='accordion-toggle' data-toggle='collapse' data-parent='#accordion4' href='#collapse41'>";
echo "<td>{$row['name']} <br /> </td>";
echo "</a>";
echo "</div>";
echo "<div id='collapse41' class='accordion-body collapse'>";
echo "<div class='accordion-inner'>";
echo "<td>Rank: {$rank} <br /> </td>";
echo "<td>Wins: {$row['wins']} <br /> </td>";
echo "<td>Losses: {$row['losses']} <br /> </td>";
echo "</div>";
echo "</div>";
echo "</div>";
$rank++;
}
}
?>
</div>
You have to break the loop up....and loop once to get headings, and twice to get body...
So you need to echo the group div first....
echo "<div class='accordion-group'>";
Then start the loop to output headings...
Then run another loop to output divs....
if (mysql_num_rows($result)) {
//LOOP 1
while ($row = mysql_fetch_assoc($result)) {
//Build heading pieces
echo "<div class='accordion-heading'>";
echo "<a class='accordion-toggle' data-toggle='collapse' data-parent='#accordion-".$row['id']." href='#accordian-".$row['id']."'>";
echo "<td>{$row['name']} <br /> </td>";
echo "</a>";
echo "</div>";}
//LOOP 2
//Build inner pieces
while ($row = mysql_fetch_assoc($result)) {
echo "<div id='accordian-".$row['id']."' class='accordion-body collapse'>";
echo "<div class='accordion-inner'>";
echo "<td>Rank: {$rank} <br /> </td>";
echo "<td>Wins: {$row['wins']} <br /> </td>";
echo "<td>Losses: {$row['losses']} <br /> </td>";
echo "</div>";
echo "</div>"; }
echo "</div>";
$rank++;
}
}
Im not actually too sure of how your accordian is to be structured, so this may or may not be correct information, but whenever I do twiiter-bootstrap accordians, this is how I do it. If you could post your expected HTML output (template for accordian), that would help me greatly, and I can revamp my answer to suit what you actually need