I have a problem calculating the sum of the data from the database and from user input, can Y'all help me?
this is the PHP code
1st value (stok di database) is data from database, and 2nd value (stok fisik) is data from user input, and selisih is 2nd value - 1st value.
<div class="box-content nopadding" style="overflow: auto;">
<table width="400px" class="table table-hover table-nomargin table-bordered">
<thead>
<tr>
<th style="text-align: center; vertical-align:middle;" rowspan="2">No</th>
<th style="text-align: center; vertical-align:middle;" rowspan="2">Nama Barang</th>
<th style="text-align: center; vertical-align:middle;" colspan="2">Stok</th>
<th style="text-align: center; vertical-align:middle;" rowspan="2">Selisih</th>
</tr>
<tr>
<th style="text-align: center; vertical-align:middle;">Stok di Database</th>
<th style="text-align: center; vertical-align:middle;">Stok Fisik</th>
</tr>
</thead>
<tbody>
<?php
$data = $db->query("select id, nama_barang, stock from tbl_atk group by nama_barang");
for ($i = 0; $i < count($data); $i++) {
$no = $i + 1;
if ($no % 2 ==0) $bg ='#FBFBFB';
else $bg = '#FFFFFF';
// $total = 'result' - $data[$i]['stock'];
$tot_masuk = $tot_masuk + "stock_op";
$tot_keluar = $tot_keluar + $data[$i]['stock'];
$grand_tot = $tot_masuk - $tot_keluar;
?>
<tr>
<td style="text-align: center; vertical-align:middle;"><?php echo $no; ?></td>
<td><?php echo $data[$i]['nama_barang']?></td>
<td style="text-align: right;" class="so"><?php echo $data[$i]['stock']; ?></td>
<td><input type="number" class="form-control so" id="stock_op" name="stock_op" style="text-align: left"></td>
<td style="text-align: right; font-weight:bold;"><output class="result"></output></td>
</tr>
<?php
}
?>
<script src="../js/jquery.min.js"></script>
<script>
$(document).on('input','.so',function(){
var totalSum = 0;
var currentRow = $(this).closest('tr');
currentRow.find('.so').each(function(){
var inputVal = ($(this).is('input')) ? $(this).val() : parseInt($(this).html());
console.log(inputVal);
if($.isNumeric(inputVal)){
totalSum += parseFloat(inputVal);
}
});
currentRow.find('.result').val(totalSum);
});
</script>
<tr style="background-color:#eaeaea; font-weight:bold;">
<td style="text-align: center; vertical-align:middle;"></td>
<td style="text-align: right;">Selisih</td>
<td style="text-align: right;"><?php echo $tot_keluar; ?></td>
<td style="text-align: right;"><?php echo $tot_masuk; ?></td>
<td style="text-align: right;"><?php echo $grand_tot; ?></td>
</tr>
</tbody>
</table>
</div>
and this is the User Interface
Change the .so to so in the below input fields.
<td style="text-align: right;" class="form-control .so"><?php echo $data[$i]['stock']; ?></td>
<td><input type="number" class="form-control .so" id="stock_op" name="stock_op" style="text-align: left"></td>
Change id result to class result in below line
<td style="text-align: right; font-weight:bold;"><output id="result"></output></td>
New Update
Give a specific class to your stok fisik cell
<tr style="background-color:#eaeaea; font-weight:bold;">
<td style="text-align: center; vertical-align:middle;"></td>
<td style="text-align: right;">Selisih</td>
<td style="text-align: right;"><?php echo $tot_keluar; ?></td>
<td class="grandResult" style="text-align: right;"><?php echo $tot_masuk; ?></td>
<td style="text-align: right;"><?php echo $grand_tot; ?></td>
</tr>
change your jquery code to this
$(document).on('input','.so',function(){
var grandSum = 0;
var totalSum = 0;
var currentRow = $(this).closest('tr');
currentRow.find('.so').each(function(){
var inputVal = ($(this).is('input')) ? $(this).val() : parseInt($(this).html());
if($.isNumeric(inputVal)){
totalSum += parseFloat(inputVal);
}
});
currentRow.find('.result').val(totalSum);
$('input.so').each(function(){
var cVal = ($(this).is('input')) ? $(this).val() : parseInt($(this).html());
if($.isNumeric(cVal)){
grandSum += parseFloat(cVal);
}
});
$('.grandResult').val(grandSum);
});
Hello Fauzio, I have created a sample table with 3 columns,
1. t_id (ie. id )
2. t_name ( ie name barang)
3. t_value (ie stock di database)
I created a table and displayed the values of each rows in the table. all values from column t_value is added in java script array. then as user enters the value for that particular row.
On click of the button , the value for that particular row is picked from db_column and user column and the result is printed in the result column
<?php
$sql = "SELECT t_id,t_name, t_value FROM test_table";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
$main_array = array();
$count=0;
while($row = $result->fetch_assoc()) {?>
<tr>
<td class="no">
<?php echo $count;?>
</td>
<td class="name">
<?php echo $row["t_name"]."<br>";?>
</td>
<td class="db_value">
<?php
array_push($main_array,$row["t_value"]);
echo $row["t_value"]."<br>";?>
</td>
<td class="user_value">
<form method="post">
<input type="number" value="">
<button id="cal" type="button" class="<?php echo $count;?>"> Calculate </button>
</form>
</td>
<td class="result">
<input type="tel" name="" value="" id="result_<?php echo $count;?>">
</td>
</tr>
<?php $count++;}?>
</tbody>
</table>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
var main_array = new Array();
<?php foreach($main_array as $key => $val){ ?>
main_array.push('<?php echo $val; ?>');
<?php } ?>
jQuery('#cal').on('click', function() {
id = jQuery(this).attr('class');
value_1st = main_array[id];
value_2nd = jQuery(jQuery(this).closest('.user_value')).find('input[type="number"]').val();
result = value_1st + value_2nd;
input_field = jQuery(jQuery(jQuery(this).closest('.user_value')).next()).find('#result_' + id);
input_field.val(result);
});
});
</script>
Related
I want to display the invoice bill for each customer when admin clicks on view bill button for that customer. Also I want to display all the newspaper details in a single invoice when customer name is same.I have included the relevant code and database snapshots.
c_details.php
<?php
session_start();
include_once("connect.php");
$query="SELECT * FROM sub_details";
$result=mysqli_query($conn,$query);
?>
<table align="center">
<h3 style="color: black; font-weight: bold; text-align: center;">
Subscription details</h3><br>
<tr>
<th style="text-align: center;">Id</th>
<th style="text-align: center;">Name</th>
<th style="text-align: center; width: 900px">Newspaper</th>
<th style="text-align: center;">Duration</th>
<th style="text-align: center;">Price</th>
<th style="text-align: center; width: 800px">Subscription date</th>
<th style="text-align: center;">Remaining Days</th>
<th style="text-align: center;">Bill</th>
</tr>
<?php while($rows=mysqli_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $rows['id']; ?></td>
<td><?php echo $rows['name']; ?></td>
<td><?php echo $rows['newspaper']; ?></td>
<td><?php echo $rows['duration']; ?></td>
<td><?php echo $rows['price']; ?></td>
<td><?php echo $rows['sdate']; ?></td>
<?php echo var_dump($result->fetch_all(MYSQLI_ASSOC));
$date1=date_create();
$date2=date_create($rows['edate']);
$interval=date_diff($date2,$date1)->format("%a days");
?>
<td><?php echo $interval; ?></td>
<td>
<form action="invoice.php" method="GET">
<?php $invoiceId = $rows['name']; ?>
<button type="submit" onclick= "window.open('invoice.php?name= '<?php echo
$rows['name']; ?>)" class="btn btn-primary btn-lg" value="submit" >
View bill</button></td>
</form>
</tr>
<?php } ?>
</table>
invoice.php
<?php
include_once("connect.php");
$invoiceId = isset($_GET['name']) ? $_GET['name'] : null;
if($invoiceId) {
$query = "SELECT * FROM sub_details WHERE name = ? limit 1";
$result = mysqli_query($conn,$query);
?>
<?php while($rows=mysqli_fetch_assoc($result)) {
?>
<form style="text-align: left;margin-left: 30px" class="register-form" id="register-form">
<div class="form-group"> Bill no: <input type="text" name="id" value="<?php echo $rows['id']; ?>"></div><br>
<div class="form-group">Name: <input type="text" name="name" value="<?php echo $rows['name']; ?>"></div><br>
<div class="form-group">Address: <input type="text" name="address" value="<?php echo $rows['address']; ?>"></div><br><br>
</form>
</th>
</tr>
<td>
<table cellpadding="5px" cellspacing="6px" style="width: 75%; border-radius:20px;">
<tr>
<th>Newspaper</th>
<th >Duration</th>
<th >Price</th>
</tr>
<tr>
<td ><?php echo $rows['newspaper']; ?></td>
<td><?php echo $rows['duration']; ?></td>
<td><?php echo $rows['price']; ?></td>
</tr>
<tr>
<td>DELIVERY CHARGES</td>
<td colspan="3" style="padding-right:60px;text-align: right;">50</td>
</tr>
<tr>
<th>Total</th>
<?php
$t_price=$rows['price']+ 50; ?>
<th colspan="3" style="text-align: right;padding-right: 55px"><?php echo $t_price; ?></th>
</tr>
<tr>
<th colspan="4" >
<br><br><br><br><br><br><br>
</th>
</tr>
</table>
</td>
<tr>
<th colspan="4" style="border-top-color: #ffff4d">
<p style="text-align: left;">Note: Clients are requested to pay the bill before 5th of every month.</p>
</th>
</tr>
<?php } ?>
</table>
Database screenshots
First, you should pass the invoice ID for each record in c_details.php so that you can identify them later:
<button type="submit" onclick= "window.open('invoice.php?id='<?php echo $rows['id']; ?>)" class="btn btn-primary btn-lg" value="submit" >View bill</button>
It will produce URLs like invoice.php?id=<id>, where <id> is the ID for each record in the database. So, for example, a record with the ID 102 will be invoice.php?id=102.
On invoice.php, you can retrieve the ID with $_GET['id']. You should adjust your query to fetch the data for the given invoice:
$invoiceId = isset($_GET['id']) ? $_GET['id'] : null;
if($invoiceId) {
$query = $conn->prepare("SELECT * FROM sub_details, signup_c WHERE id = ? limit 1";
$query->bind_param('s', $invoiceId);
$query->execute();
$result = $query->get_result();
}
If you're using PHP 7.0 or later, you can simplify your code using the null coalescing operator:
$invoiceId = $_GET['id'] ?? null;
I strongly recommend you to learn about how to prevent SQL injections in PHP.
I have some code that at the moment, upon the page load up, doesn't display my table data, and when I type in a username into my text-box, it displays the data corresponding with the letters typed into the text-box to match the username characters.
I want it to automatically show my table data and make the username search optional, only display certain users when typed into the text-box.
My current code is below :
index.php
<form name="bulk_action_form" action="" method="POST"/>
<?php
if(isset($_POST['bulk_delete_submit'])) {
if(!empty($_POST['checked_id'])) {
$idArr = $_POST['checked_id'];
$username = $_SESSION['username'];
foreach($idArr as $id) {
mysqli_query($con, "DELETE FROM `users` WHERE `id` = '$id' AND `username` = '$username'");
echo "<p>".$id ."</p>";
}
$_SESSION['success_msg'] = 'Users have been deleted successfully.';
header("Location: admin_members.php");
} else {
echo '<div class="row" style="color: red; text-align: center; padding-bottom: 20px;"><i class="fa fa-spin fa-spinner"></i> You must select atleast one user to delete <i class="fa fa-spin fa-spinner"></i></div>';
}
}
?>
<div class="row">
<div class="card-box" style="border-radius: none; padding: 10px; border: 1px solid #E3E3E3; background: #EEEEEE;">
<button type="submit" class="btn btn-danger" name="bulk_delete_submit"><i class="fa fa-trash-o"></i></button>
</div>
</div>
<div id="result"></div>
</div>
</form>
(Ignore the , the result div is the main part, at listed for my JS code below).
JS in index.php
<script>
$(document).ready(function(){
$('#search_text').keyup(function(){
var txt = $(this).val();
if(txt != '') {
$.ajax({
url:"search.php",
method:"post",
data:{search:txt},
dataType:"text",
success:function(data)
{
$('#result').html(data);
}
});
} else {
$('#result').html('');
}
});
});
</script>
And then for my search.php
<?php
include_once('configuration/db.php');
?>
<div class="table-responsive">
<table class="table m-0">
<thead>
<tr class="gradeA">
<th><input type="checkbox" id="selectall"/></th>
<th style="text-align: center;">Username</th>
<th style="text-align: center;">Email</th>
<th style="text-align: center;">CPUKey</th>
<th style="text-align: center;">IP</th>
<th style="text-align: center;">Expirey</th>
<th style="text-align: center;">Enabled?</th>
<th style="text-align: center;">Profile Picture</th>
<th style="text-align: center;">User Level</th>
<th style="text-align: center;">Date/Time Registered</th>
<th style="text-align: center;">Account Credits</th>
<th style="text-align: center;">Free Gifted Credits</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$username = $_SESSION['username'];
$clients_result = mysqli_query($con, "SELECT id, username, email, cpukey, ip, time, enabled, profile_picture, userLevel, register_time, account_credits, free_gifted_credits FROM users WHERE username LIKE '%".$_POST["search"]."%'");
if(mysqli_num_rows($clients_result) > 0) {
while($payment_row = mysqli_fetch_array($clients_result)) {
echo '
<tr style="text-align: center; font-size: 12px;">
<td>
<input type="checkbox" name="checked_id[]" class="checkbox" value='.($payment_row['id']).'>
</td>
<td>
'.($payment_row['username']).'
</td>
<td>
'.($payment_row['email']).'
</td>
<td>
'.$payment_row['cpukey'].'
</td>
<td>
'.($payment_row['ip']).'
</td>
<td>
<b>'.$payment_row['time'].'</b>
</td>
<td>
'.($payment_row['enabled'] == 1 ? '<span class="label label-success">Yes</span>' : '<span class="label label-danger">No</span>').'
</td>
<td>
'.("<img src=".$payment_row['profile_picture']." alt='user-img' class='img-circle user-img' style='height: 20px; width: 20px;'>").'
</td>
<td>
'.userLevelValidation().'
</td>
<td>
'.$payment_row['register_time'].'
</td>
<td>
'.number_format($payment_row['account_credits'], 2, '.', '').'
</td>
<td>
'.number_format($payment_row['free_gifted_credits'], 2, '.', '').'
</td>
';
;
} }else{ ?> <tr><td colspan="12" style="text-align: center; padding: 30px; letter-spacing: 2px; color: red;"><i class="fa fa-spin fa-spinner"></i> <strong>Oh snap!</strong> No Purchase records found. <i class="fa fa-spin fa-spinner"></i></td></tr> <?php } ?>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
$('#selectall').click(function() {
$(this.form.elements).filter(':checkbox').prop('checked', this.checked);
});
</script>
Any help would be much appreciated.
I'm trying to delete the selected rows from the list I have in mysql so I won't have to delete the rows in my table one by one. When I press delete, my page refreshes without any php error but I don't get the result desired either. here is what I have:
<?php $product_set = find_all_products(); ?>
<body>
<form action="manage_products.php" method="delete">
<div class="page">
<article>
<div id="page">
<?php echo message(); ?>
<h2>Manage Products</h2>
<table>
<tr>
<th style="text-align: left; width: 125px;">Location</th>
<th style="text-align: left; width: 250px;">URL to the Product</th>
<th style="text-align: left; width: 100px;">First Name</th>
<th style="text-align: left; width: 100px;">Last Name</th>
<th style="text-align: left; width: 100px;">Size</th>
<th style="text-align: left; width: 100px;">Status</th>
<th style="text-align: left; width: 100px;">Checked</th>
<th colspan="2" style="text-align: left;">Actions</th>
</tr>
<?php while($product = mysqli_fetch_assoc($product_set)){ ?>
<tr>
<td><?php echo htmlentities($product["location"]);?></td>
<td><?php echo htmlentities($product["productURL"]); ?></td>
<td><?php echo htmlentities($product["fname"]); ?></td>
<td><?php echo htmlentities($product["lname"]); ?></td>
<td><?php echo htmlentities($product["size"]); ?></td>
<td><?php echo htmlentities($product["status"]); ?></td>
<td><input name="checkbox" type="checkbox" id="checkbox[]" value="<?php echo $product['id']; ?>"></td>
<td>Edit Order</td>
<td>Delete Order</td>
</tr>
<?php } ?>
</table>
<?php
// Check if delete button active, start this
if(isset($_GET['delete']))
{
$checkbox = $_GET['checkbox'];
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM product WHERE link_id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
$_SESSION["message"] = "Product deletion failed.";
redirect_to("created_products.php"); }
}
//mysqli_close($dbc);
?>
<br />
</div>
</div>
<br>
<input type="submit" name="submit" value="Delete" onclick="return val();"/>
</form>
<div class="clear-all"></div>
</article>
</div>
</body>
Also place all the code which is for deleting the rows in the starting of your file. Thank you #Traveller for this.
Instead of for loop, use WHERE IN
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM product WHERE link_id='$del_id'";
$result = mysql_query($sql);
}
Replace that with
$ids = implode(",", $_POST['checkbox']);
$sql = "DELETE FROM product WHERE link_id in ($ids)";
I am having a table with 7 columns(Complaintid id,name,school name etc...) and also have button. When I click the button I need to pass the complaintid of that row to another page. pls help me find a way to pass the value.
<html>
<body>
<?php
include '../library/dbconnect.php';
$query="SELECT * FROM Complaint_register WHERE status=1 ORDER BY entrydate ";
$result=mysql_query($query) or die("Selection query of
Complaint_register is Error ".mysql_error());
$num = mysql_numrows($result);
$i=0;
$j=1;
?>
<form action="" name="frmcomplaint" id="frmcomplaint" method="post">
<table border="1" style="border-color: #FFFFFF;" >
<tr>
<th style="color: #FF0000">Sl. No</th>
<th style="color: #FF0000">Complaint Id</th>
<th style="color: #FF0000">Date</th>
<th style="color: #FF0000; width:200px;" >Name Of student</th>
<th style="color: #FF0000">District</th>
<th style="color: #FF0000">School Name</th>
<th style="color: #FF0000">Standard with </th>
<th style="color: #FF0000; width:200px;">Complaint</th>
</tr>
<?php
while($row=mysql_fetch_array($result))
{
$date1=explode('-', $row[$i+2]);
$entrydate=$date1[2]."-".$date1[1]."-".$date1[0];
$job_id=$row[$i+1];
?>
<tr>
<td style="color: #000000"><?php echo $j;?></td>
<td style="color: #000000"><?php echo $row[complain_Id]; ?> </td>
<td style="color: #000000"><?php echo $entrydate;?></td>
<td style="color: #000000" ><?php echo $row[studname];?></td>
<td style="color: #000000"><?php echo $row[District];?></td>
<td style="color: #000000"><?php echo $row[School_name] ;?></td>
<td style="color: #000000"><?php
echo $row[Standard]."-".$row[Division];?></td>
<td id="disp" ><?php echo $row[Complaint];?></td>
<td id="button" name="viewbutton" >
</td>
</tr>
<?php
$button++;
$j=$j+1;
}
?>
</table>
</form>
</body>
</html>
Instead of using
<td id="button" name="viewbutton" >
</td>
use,
<td>
<input type="button" onclick="functionname(<?php echo $row[complain_Id]; ?>)">
</td>
and add a javascript function
<script>
function functioname(param)
{
window.location="redirectionpage?id="+param;
}
</script>
This will redirect to the page redirectionpage with the id.
Few Loop holes in your current attempt.
Strictly use mysqli or PDO instead of mysql as it's been deprecated.
It's mysql_num_rows not mysql_numrows.
Now coming to your problem, you can solve this by using jQuery ajax.
$("table").on("click","#button",function(){
var cid = $("#disp").text();
$.ajax({
type: "GET",
url: "anotherpage.php",
data: { complainid: cid},
success: function(data) {
alert(data) //To check if response is success
}
});
});
anotherpage.php:
<?php
$cid = $_GET['complainid'];
?>
You can use a link with complain id like complaints.php?complainid=echo your value here
<td id="button" name="viewbutton" >
view complaint
</td>
and you can style that link like a button if needed.
In complaints.php page you can take the details of that complain with the id you passed.
How can I display data in two columns?
<?php
$query = "SELECT * FROM `release` WHERE artist_id = '$rcode' AND label_id = '$id'";
$result = mysql_query($query);
$tr_no = mysql_num_rows($result);
while ($info = mysql_fetch_array($result)) {
?>
<div>
<table style="width: 100%">
<tr>
<td ><img src="../artwork/<?php echo $info['label_id']; ?>/<?php echo $info['ID']; ?>.jpg" width="100" height="100" /></td>
<td valign="top">
<table style="width: 100%">
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo $info['code']; ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo $info['name']; ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo trh($info['date']); ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px">
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<?php
}
?>
Normally I am using this for just one column.
What is the easiest way of displaying it in two columns with the same fields I have in this code?
The answer also depends on the way you'd like to show the info.
If we assume you have the following six artist_id's in your DB
1,2,3,4,5,6
in which way would you like to show them? This way
1 2
3 4
5 6
or this way?
1 4
2 5
3 6
Update: as you say you'd like to show them in the first way, the solution is pretty simple. Every pair iteration (0, 2, 4...) you should open the row and every odd iteration (1, 3, 5...) you should close it , so you'd have
<tr><td>0</td><td>1</td></tr><tr><td>2</td><td>3</td></tr>...
The code would be
<?php
$query = "SELECT * FROM `release` WHERE artist_id = '$rcode' AND label_id = '$id'";
$result = mysql_query($query);
$tr_no = mysql_num_rows($result);
$ii = 0; // Iterator
while ($info = mysql_fetch_array($result)) {
?>
<div>
<table style="width: 100%">
<?php if ($ii%2 == 0) { // If pair, we open tr?>
<tr>
<?php } ?>
<td ><img src="../artwork/<?php echo $info['label_id']; ?>/<?php echo $info['ID']; ?>.jpg" width="100" height="100" /></td>
<td valign="top">
<table style="width: 100%">
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo $info['code']; ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo $info['name']; ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo trh($info['date']); ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px">
</td>
</tr>
</table>
</td>
<?php if ($ii%2 == 1) { // If odd, we close tr?>
</tr>
<?php } ?>
</table>
</div>
<?php $ii++; // We increment the iterator }
?>
You have several options depending on how fancy you want to get with your HTML/CSS. You can try to keep each to 50% width and float them left and the elements should automatically arrange themselves in two columns.
You can also be more explicit using a table-based layout. In this case, start with a and tag, then add elements inside your loop. After every two elements ( $index % 2 == 0), write a to start a new row.. then, after your loop is finished, close your . If you go this route, you'll want to make sure to add an extra if you've got an odd number of results from your query.
There may be more sophisticated ways to do this, but this is simple and straightforward enough to get the job done.
Unless you have a "LARGE" data set,
1) bring all the rows out into a numerically indexed array
2) divide the number of rows by two: x1 = 0; x2 = (int) count/2;
3) loop from 0 to count/2, creating a table with two columns,
3a) those indexed by x1++ in the first column
Get the total number of pictures, you can do that dynamically, and then put everything in a for loop as follows:
Let's say you want 9 pictures on three columns:
for ($i = 0; $i<=6; $i=($i + 3))
{
$result = mysql_query("select * from users order by id desc limit $i,3 ");
while(mysql_fetch_array($result))
{
//bla bla bla html code
}
}
Good luck.
<table border='1'><tr><?phpfor ($i = 0; $i<=17; $i=($i + 3)){echo "<td>$i</td>";}?></tr><tr><?phpfor ($n = 1; $n<=17; $n=($n + 3)){ echo "<td>$n</td>";}?></tr><tr><?phpfor ($m = 2; $m<=17; $m=($m + 3)){echo "<td>$m</td>";}?></tr></table>
|0|3|6|9|12|15|
|1|4|7|10|13|16|
|2|5|8|11|14|17|
Thank you :)
<table border='1'><?phpfor ($n = 0; $n<=2; $n++) {echo "<tr>";for ($i = $n; $i<=17; $i=($i + 3)){ echo "<td>$i</td>";}echo "</tr>";}?></table>
just use two loop like this
result
0 3 6 9 12 15
1 4 7 10 13 16
2 5 8 11 14 17