Hi guys, I'm trying to do the while loop.
The while loop will loop through all the orders.
It works but somehow it doesn't while loop through the order status.
For example, order 4 status is pending, but order 5 status shows nothing.
I suspect I placed the brackets wrongly.
This is my code.
<form action="results-action" method="post" enctype="multipart/form-data">
<fieldset>
<table width="600" border="1">
<tr><td><h2>Pending Order</h2></td></tr>
<tr>
<th scope="col">Order ID</th>
<th scope="col">Name</th>
<th scope="col">Address</th>
<th scope="col">Product Name</th>
<th scope="col">Produt Quantity</th>
<th scope="col">Price</th>
<th scope="col">Order status</th>
</tr>
<?php
while ($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><input type="text" value='<?=$row['virtuemart_order_id']?>' name="orderid" id="virtuemart_order_id"></td>
<td><?=$row['first_name']?></td>
<td><?=$row['address_1']?></td>
<td><?=$row['order_item_name']?></td>
<td><?=$row['product_quantity']?></td>
<td><?=$row['product_final_price'] ?></td>
<td><select name="change">
<?php
while ($row2 = mysqli_fetch_array($result2)) {
?>
<option value="<?=$row2['order_status_code'] ?>"><?=$row2['order_status_name'] ?></option>
<?php
} //end inner while
?>
</td>
</tr>
<?php
} //end outer while
?>
</table>
</fieldset>
<fieldset>
<table>
<tr>
<td><input type="submit" value="Update status" name="update status"> </td>
</tr>
</table>
</fieldset>
</form>
If you want to get the same rows every time in the inner while you will have to reset the internal pointer of the mysqli result set. For this, you can use the mysqli_data_seek()
You will end up with something like this:
while ($row = mysqli_fetch_array($result)) {
// snip ...
while ($row2 = mysqli_fetch_array($result2)) {
// snip
}
mysqli_data_seek($result2, 0);
// snip
}
Please also ensure the <select> has unique name, otherwise all your status will be captured wrongly.
<select name="change_<?=$row['row_id']?>">
Something like that.
Related
I am trying to hide the table row for user_id. I only want to show the full name, user name, and actions in the table. I tried to remove the code for the user id row, but it affected the other functionalities like the edit and delete.
here is the code:
<form method="post" id="editForm">
<table class="table">
<tbody>
<tr>
<th scope="col">USER ID</th>
<th scope="col">FULL NAME</th>
<th scope="col">USER NAME</th>
<th scope="col">ACTIONS</th>
</tr>
<?php $a = 0?>
<?php while ($row = mysqli_fetch_array($res)) {
echo "<tr id=".$a++.">
<th scope='row' class='row-data'>".$row['user_id']."</th>
<td class='row-data'>".$row['full_name']."</td>
<td class='row-data'>".$row['user_name']."</td>
<td><input type='button'
value='EDIT'
onclick='editUser()'' /></td>
<td><input type='button'
value='DELETE'
onclick='deleteUser()' /></td>
</tr>
</tbody>";
}; ?>
You could try modifying the editUser() and deleteUser() Javascript methods to accept a userId parameter. It would probably clean up some of the code as well on the JS side. Just a suggestion though. That snippet then might look something like this:
<form method="post" id="editForm">
<table class="table">
<tbody>
<tr>
<th scope="col">FULL NAME</th>
<th scope="col">USER NAME</th>
<th scope="col">ACTIONS</th>
</tr>
<?php $a = 0?>
<?php while ($row = mysqli_fetch_array($res)) {
echo "<tr id='".$a++."'>
<td class='row-data'>".$row['full_name']."</td>
<td class='row-data'>".$row['user_name']."</td>
<td><input type='button'
value='EDIT'
onclick='editUser(".$row['user_id'].")'' /></td>
<td><input type='button'
value='DELETE'
onclick='deleteUser(".$row['user_id'].")' /></td>
</tr>
</tbody>";
}; ?>
Otherwise you could use Ken's solution which would probably work with your existing code.
Instead of removing the column, you can set the display style to 'none' for this column
(add style="display:none;")
Hence (1) change
<th scope="col">USER ID</th>
to
<th scope="col" style="display:none;">USER ID</th>
and (2) change
<th scope='row' class='row-data'>".$row['user_id']."</th>
to
<th scope='row' class='row-data' style="display:none;">".$row['user_id']."</th>
Right now I am writing a program in core PHP, but I am not able to write a perfect oops concept as I m rewriting the code many times.
for Eg.
public function all()
{
$init = new Database;
$sql = "SELECT * FROM categories";
// Result
$result = $init->conn->query($sql);
if ($result->num_rows > 0) {
?>
<table class="table table-hover">
<thead>
<tr>
<th>Action</th>
<th scope="col">id</th>
<th scope="col">Category name</th>
<th scope="col">Category description</th>
</tr>
</thead>
<tbody>
<?php
while ($row = $result->fetch_assoc()) {
?>
<tr>
<td>
<form action="update_categories.php?update_id=<?php echo $row['id'] ?>" method="post">
<button type="submit" class="btn btn-primary" name="update">Update</button>
</form>
<form action="delete_categories.php?id=<?php echo $row['id'] ?>" method="post">
<button type="submit" name="delete" class="btn btn-danger">Delete</button>
</form>
</td>
<td><?php echo $row["id"] ?></td>
<td><?php echo $row["category_name"] ?></td>
<td><?php echo $row["category_description"] ?></td>
</tr>
<?php
} ?>
</tbody>
<?php
} else {
?>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">Category name</th>
<th scope="col">Category description</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">no result</th>
<td>no result</td>
<td>no result</td>
</tr>
</tbody>
<?php
}
}
So here you can see I have to fetch the data from the database but in this function, I have included Html too so if you want to add database data to another place I have to write the function for that again and fetch the values.
Is there any way I can only fetch the value and i can use the function to print it wherever I want.
I am writing a plugin where you put in a shortcode in a page and it displays a table of data.
However, the page content prior to the shortcode is being inserted randomly into the middle of the table. When I refresh the page the content typed above the shortcode randomly moves within the table produced by the shortcode.
Content under the shortcode does not appear within the shortcode return.
Does anyone have any idea why this might be happening. This is super strange.
------------------ wordpress page edit ---------------
Here is some content.
Here is another paragraph.
[view_contributions]
End of page content.
------------------end of wordpress page edit ----------------------------
It then produces
------ displays --------
[Shortcode data table with "Here is some content. Here is another paragraph." randomly inserted into a cell somewhere. Then more data table]
End of page content.
-------- end of display -----
This is so odd. It's as if shortcode is rendering first but then WordPress injects the page content into whatever the shortcode is rendering. Any ideas what could cause this?
EDIT: Added entirety of code in case something really strange is happening...
function soco_view_contributions_shortcode() {
$view_contributions = Soco_Contributions::soco_display_contributions();
return $view_contributions;
}
add_shortcode( 'view_contributions', 'soco_view_contributions_shortcode');
public function soco_display_contributions() {
$contribution_results = Soco_Contributions::soco_get_contributions_view();
ob_start;
?>
<div name="div-output-container">
<form name="frm-search-contributions">
<table width="100%" border="0">
<tbody>
<tr>
<th scope="col">Start Date</th>
<th scope="col">End Date</th>
<th scope="col">Minimum</th>
<th scope="col">Maximum</th>
<th scope="col">Name</th>
<th scope="col">Event</th>
</tr>
<tr>
<td><input type="date" name="start-date"></td>
<td><input name="end-date" type="date" ></td>
<td><input type="number" name="low-number"></td>
<td><input type="number" name="high-number"></td>
<td><text name="txt-auto-name"> </textarea></td>
<td><select> </select></td>
</tr>
</tbody>
</table>
<input type="submit">
<input type="reset">
</form>
<table width="100%" border="0">
<tbody>
<tr>
<th scope="col">Date</th>
<th scope="col">Amount</th>
<th scope="col">Cycle</th>
<th scope="col">Name</th>
<th scope="col">Event</th>
</tr>
<?php foreach ($contribution_results as $cr) { ?>
<tr>
<td><?php echo $cr->contribution_date ?></td>
<td><?php echo $cr->amount ?></td>
<td><?php echo $cr->cycle_amount ?></td>
<td><?php echo $cr->last_name.', '.$cr->first_name ?></td>
<td> </td>
</tr>
<?php } ?>
</tbody>
</table>
<button name="btnDownload" id="btnDownload" title="Click this button to download the above dataset." >Download CSV File</button>
</div>
<?php
$contribution_output = ob_get_clean();
return $contribution_output;
}
It seems that you are attempting to return an output buffer as string. When ob_start() is called, all output is suppressed until ob_end(), ob_end_flush() or ob_end_clean() is called so logically, you can't return it. Simply call them within the function itself and return the contents of the output buffer (ob_get_contents()) as a string:
add_shortcode('view_contributions','soco_view_contributions_shortcode');
function soco_view_contributions_shortcode( ) {
ob_start();
?>
<h1>Shortcode Output</h1>
<p><?php echo "Some other output" ?></p>
<?
return ob_end_clean();
}
Why PHP doesn't throw a fatal error when attempting to return an entire buffer from a function surprises me.
The problem turned out to be mixing ECHO and RETURN in the output buffer. To fix this I turned the whole thing into a concatenated string to output instead.
The echos that are in the foreach loop I think were messing up the output buffer. So I removed ob_start all together and will just output a final HTML string.
Not a great solution but at least it is working now and not producing random results. If anyone has suggestions or examples on how to mix ob_start with php logic inside of it that would be great. It seems weird to me that ob_start() has issues with this.
$contribution_output = '<div name="div-output-container">
<form name="frm-search-contributions">
<table width="100%" border="0">
<tbody>
<tr>
<th scope="col">Start Date</th>
<th scope="col">End Date</th>
<th scope="col">Minimum</th>
<th scope="col">Maximum</th>
<th scope="col">Name</th>
<th scope="col">Event</th>
</tr>
<tr>
<td><input type="date" name="start-date"></td>
<td><input name="end-date" type="date" ></td>
<td><input type="number" name="min-amount"></td>
<td><input type="number" name="max-amount"></td>
<td>
<input type="text" name="donor_name">
<input type="hidden" name="hdn-donor-id" value="">
</td>
<td><select> </select></td>
</tr>
</tbody>
</table>
<input type="submit">
<input type="reset">
</form>
<div name="contribution-results-container" >
<table width="100%" border="0">
<tbody>
<tr>
<th scope="col">Date</th>
<th scope="col">Amount</th>
<th scope="col">Cycle</th>
<th scope="col">Name</th>
<th scope="col">Event</th>
</tr>';
foreach ($contribution_results as $cr) {
$contribution_output .= '
<tr>
<td>'.$cr->contribution_date.'</td>
<td>'.$cr->amount.'</td>
<td>'.$cr->cycle_amount.'</td>
<td>'.$cr->last_name.', '.$cr->first_name.'</td>
<td> </td>
</tr>';
}
$contribution_output .= '</tbody>
</table>
<button name="btnDownload" id="btnDownload" title="Click this button to download the above dataset." >Download CSV File</button>
</div>
</div>';
<?php session_start();
require_once('SessionSet.php');
require_once('connection.php');
include('top.php');
if(isset($_GET['ClassID']) && isset($_GET['SectionId']) )
{
$ClassID = $_GET['ClassID'];
$SectionId = $_GET['SectionId'];
$ClassName = $_GET['ClassName'];
$SectionName = $_GET['SectionName'];
$GetCurrentMonth = date('M');
/* select latest Academic Year*/
$GetAcademicQ = "select * from study_year order by StudyYearId desc limit 1";
$GetAcademicQR = mysqli_query($con,$GetAcademicQ);
$GetAcademicRow = mysqli_fetch_assoc($GetAcademicQR);
$AcademciyearId = $GetAcademicRow['StudyYearId'];
$YearName = $GetAcademicRow['YearName'];
/* Get Students and Students Class + Fee Records */
$GetStudentClassQ = "select * from studentclass where
AcademicYearId='$AcademciyearId' and StudentClassId='$ClassID'
and StudentSectionId='$SectionId';";
$GetStudentClassQR = mysqli_query($con,$GetStudentClassQ);
$GetStudentClassNum = mysqli_num_rows($GetStudentClassQR);
if($GetStudentClassNum>0)
{
while($GetStudentClassRow = mysqli_fetch_assoc($GetStudentClassQR))
{
$StudentID = $GetStudentClassRow['StudentID'];
$RollNumber = $GetStudentClassRow['RollNumber'];
$RollNumber = $GetStudentClassRow['RollNumber'];
$StuentClassFee = $GetStudentClassRow['StuentClassFee'];
/* Get Stduent Name and bio data */
$GetStudentQ = "select * from students where Student_ID='$StudentID';";
$GetStudentQR = mysqli_query($con,$GetStudentQ);
$GetStudentRow = mysqli_fetch_assoc($GetStudentQR);
$Name = $GetStudentRow['Name'];
$FatherName = $GetStudentRow['FatherName'];
$StudentPhoto = $GetStudentRow['StudentPhoto'];
$Student_ID = $GetStudentRow['Student_ID'];
/* Get Stduent Name and bio data */
$GetfeeQ = "select * from fee where FeeStudentID='$StudentID';";
$GetfeeQR = mysqli_query($con,$GetfeeQ);
$GetfeeRow = mysqli_fetch_assoc($GetfeeQR);
$FeeAmount = $GetfeeRow['FeeAmount'];
$FeePaid = $GetfeeRow['FeePaid'];
?>
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<table class="table table-hover table-bordered print-table" style="width:100% !important" align="center">
<!--Office Copy-->
<tr class="warning">
<th>Student ID</th>
<td>
<?php echo $Student_ID;?>
</td>
<th>Class</th>
<td>
<?php echo $ClassName;?>
</td>
<th>Section Name</th>
<td>
<?php echo $SectionName;?>
</td>
<th>Roll Number</th>
<td>
<?php echo $RollNumber;?>
</td>
<th>Academic Year </th>
<td>
<?php echo $YearName;?>
</td>
<!--td rowspan="5" style="text-align:center"><img src="StudentImages/<?php/* echo $StudentPhoto;*/?>"/ alt="Stdudent Image not found" style="width:150px; height:200px"></td-->
</tr>
<tr class="warning">
<th>Student Name</th>
<td colspan="4">
<?php echo $Name;?>
</td>
<th>Father Name</th>
<td colspan="4">
<?php echo $FatherName;?>
</td>
</tr>
<tr class="warning">
<th>Fee Month </th>
<td>
<?php echo $GetCurrentMonth;?>
</td>
<th>Fee Amount</th>
<td style="font-size:20px;">
<?php echo $StuentClassFee;?>
</td>
<th>Previous Dues</th>
<td style="font-size:20px;">
<?php echo $FeeAmount-$FeePaid;?>
</td>
<th>Due Date</th>
<td>12 -
<?php echo $GetCurrentMonth;?>
</td>
<th>After Due Date</th>
<td>
<?php echo $StuentClassFee+50;?>
</td>
</tr>
<hr>
<!--Student Copy-->
</table>
<table class="table table-hover table-bordered print-table" style="width:100% !important" align="center" >
<tr class="warning">
<th>Student ID</th>
<td>
<?php echo $Student_ID;?>
</td>
<th>Class</th>
<td>
<?php echo $ClassName;?>
</td>
<th>Section Name</th>
<td>
<?php echo $SectionName;?>
</td>
<th>Roll Number</th>
<td>
<?php echo $RollNumber;?>
</td>
<th>Academic Year </th>
<td>
<?php echo $YearName;?>
</td>
<!--td rowspan="5" style="text-align:center"><img src="StudentImages/<?php/* echo $StudentPhoto;*/?>"/ alt="Stdudent Image not found" style="width:150px; height:200px"></td-->
</tr>
<tr class="warning">
<th>Student Name</th>
<td>
<?php echo $Name;?>
</td>
<th>Father Name</th>
<td>
<?php echo $FatherName;?>
</td>
<th>Fee Month </th>
<td>
<?php echo $GetCurrentMonth;?>
</td>
<th>Fee Amount</th>
<td style="font-size:20px;">
<?php echo $StuentClassFee;?>
</td>
<th>Previous Dues</th>
<td style="font-size:20px;">
<?php echo $FeeAmount-$FeePaid;?>
</td>
</tr>
</table>
</div>
<!-- row end here -->
</div>
</div>
<!-- page-wrapper end here -->
<?php
}
}
else
{
}
?>
<?php
}
?>
i am building a php school management application. when I try to print report after pressing ctrl+p one recored is being shown on each page. but i want to show atleast 3 records on a single page after giving printing command. I have attached snapshots of records before and after print command.
enter image description here
here is picture after giving print command
enter image description here
Your question has nothing to do with PHP, this is a question about CSS, specifically print styles.
In the absence of an example of plain HTML and CSS, take a look at the CSS properties page-break-before, page-break-after and page-break-inside. In this case you may want to look at something like:
#media print {
.row, table {
page-break-before: avoid;
page-break-after: avoid;
}
}
Learn a little bit more about the page-break-* properties at this CSS Tricks article. If you are generally new to CSS print styles, I wrote a primer for .NET magazine.
Bear in mind that whatever styles you use, these are only suggestions to the browser. Paper size, page orientation, font size, zoom level, user margins, etc. will all work together to mess with your plans. Content that you force to be too wide for the page may also be an issue.
Finally, don't use any inline styles. Use your CSS file for that (so get rid of that width:100% inline style I saw.
If you want more help, post the raw HTML output and your CSS.
I have the following code:
<table id="box-table-a" class="tablesorter">
<thead>
<tr>
<th scope="col">B-House/Dorm Name</th>
<th scope="col">Address</th>
<th scope="col">Price Range</th>
<th scope="col">Date Added</th>
<th scope="col">Status</th>
</tr>
</thead>
<?php
$q=mysql_query("select * from property");
while( $f=mysql_fetch_array($q, MYSQL_ASSOC))
{ $p_id=$f["p_id"];
echo"
<tbody>
<tr>
<td onblurr='hover2()' onmouseover='hover(".$p_id.")' onclick='showUser(".$p_id.")'>
<span style='cursor:pointer'>".$f['p_name']."</span></td>
<td id='pretty'>".$f['address']."</td>
<td>".$f['p_name']."</td> <td>".$f['payment_type']."</td> <td>".$status."</td> </tr>
</tbody>
";
}
?>
</table>
Any idea what may be wrong here?
Don't add <tbody></tbody> to every loop in the while! Tablesorter is very sensitive.
You did'nt sort your DB :
$q=mysql_query("select * from property ORDER BY p_name");