Foreign Key In Php to get data from another table - php

function show_username($connect)
{
$output = '';
$query = "SELECT * from users";
$res = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($res))
{
$output .= '<option value="'.$row["id"].'">'.$row["name"].'</option>';
{
}
return $output;
}
function show_offer($connect)
{
$output = '';
$query = "SELECT * FROM add_offer ORDER BY id DESC";
$res = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($res))
{
$output .= '<div class="col-md-3 col-sm-4 col-lg-6">';
$output .= '<div class="panel panel-default">';
$output .= '<div class="panel-body">';
$output .= '<div style="padding:1px;float:left;font-weight:bold;">'.$row["part_no"].'</div>';
$output .= '<div style="padding:1px;float:left;">'.$row["make"].'</div>';
$output .= '<div style="padding:1px;float:left;">'.$row["date_code"].'</div>';
$output .= '<div style="padding:1px;float:left;">'.$row["qty"].'</div>';
$output .= '<br>';
$output .= '<div style="float:left;font-size:9px;">'.$row["time"].'</div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
}
echo $output;
}
<div class="container">
<div class="row">
<div class="col-lg-offset-3 col-lg-6">
<div class="panel">
<div class="panel panel-default" style="border: 1px solid #66512c;">
<div class="panel-heading" style="background-color: #66512c;color: white;">
Market Offers
</div>
<div class="panel-body" style="padding: 0px;padding-left: 5px;border-bottom: 1px solid #66512c;">
<div class="nav nav-pills nav-stacked">
<select name="category" id="user" class="form-control">
<option selected="" value="" class="form-control">All User Offers</option>
<?php echo show_username($connect); ?>
</select>
<div class="panel panel-body" id="show_offer">
<?php echo show_offer($connect);?>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3"></div>
</div>
<script>
$(document).ready(function(){
$('#user').change(function(){
var user_id = $(this).val();
$.ajax({
url:"load_data.php",
method:"POST",
data:{user_id:user_id},
success:function(data){
$('#show_offer').html(data);
}
});
});
});</script>
<?php
//load_data.php
$connect = mysqli_connect("localhost", "root", "", "customer");
$output = '';
if(isset($_POST["user_id"]))
{
if($_POST["user_id"] != '')
{
$query = "SELECT * FROM add_offer WHERE user_id = '".$_POST["user_id"]."' ORDER BY id DESC";
}
else
{
$query = "SELECT * FROM add_offer ORDER BY id DESC";
}
$res = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($res))
{
$output .= '<div class="col-md-3 col-sm-4 col-lg-6">';
$output .= '<div class="panel panel-default">';
$output .= '<div class="panel-body">';
$output .= '<div style="padding:1px;float:left;font-weight:bold;">'.$row["part_no"].'</div>';
$output .= '<div style="padding:1px;float:left;">'.$row["make"].'</div>';
$output .= '<div style="padding:1px;float:left;">'.$row["date_code"].'</div>';
$output .= '<div style="padding:1px;float:left;">'.$row["qty"].'</div>';
$output .= '<br>';
$output .= '<div style="float:left;font-size:9px;">'.$row["time"].'</div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
}
echo $output;
}?>
In this above code I have used functions to take data from 2 seperate table and I want to display the table in the following format as
name from users table
part_no,make,date_code,qty from add_offers table
the image shows my output market_offers page
I want the data not to be selected by dropdown but has to display whole data as first with name from users table and followed by users part_no from add_offers table.
Also the timestamp display as 2018-03-22 12.40.55 which i want as 22-03-2018 12.40.55

You've to change your code as bellow:
function show_username($connect)
{
$output = '';
$query = "SELECT * from users order by id asc";
$res = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($res))
{
$output .= '<option value="'.$row["id"].'">'.$row["name"].'</option>';
{
}
return $output;
}
function show_offer($connect)
{
$output = '';
$user_query = "SELECT * from users order by id asc";
$user_res = mysqli_query($connect, $user_query );
$user_row = mysqli_fetch_array($user_res);
$query = "SELECT * FROM add_offer where user_id = ".$user_row['id']." ORDER BY id DESC";
$res = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($res))
{
$output .= '<div class="col-md-3 col-sm-4 col-lg-6">';
$output .= '<div class="panel panel-default">';
$output .= '<div class="panel-body">';
$output .= '<div style="padding:1px;float:left;font-weight:bold;">'.$row["part_no"].'</div>';
$output .= '<div style="padding:1px;float:left;">'.$row["make"].'</div>';
$output .= '<div style="padding:1px;float:left;">'.date('d-m-Y H:i:s',strtotime($row["date_code"])).'</div>';
$output .= '<div style="padding:1px;float:left;">'.$row["qty"].'</div>';
$output .= '<br>';
$output .= '<div style="float:left;font-size:9px;">'.$row["time"].'</div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
}
echo $output;
}
Html Code:
<div class="container">
<div class="row">
<div class="col-lg-offset-3 col-lg-6">
<div class="panel">
<div class="panel panel-default" style="border: 1px solid #66512c;">
<div class="panel-heading" style="background-color: #66512c;color: white;">
Market Offers
</div>
<div class="panel-body" style="padding: 0px;padding-left: 5px;border-bottom: 1px solid #66512c;">
<div class="nav nav-pills nav-stacked">
<select name="category" id="user" class="form-control">
<option selected="" value="" class="form-control">All User Offers</option>
<?php echo show_username($connect); ?>
</select>
<div class="panel panel-body" id="show_offer">
<?php echo show_offer($connect);?>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3"></div>
</div>
Java Script Code:
<script>
$(document).ready(function(){
$('#user').change(function(){
var user_id = $(this).val();
$.ajax({
url:"load_data.php",
method:"POST",
data:{user_id:user_id},
success:function(data){
$('#show_offer').html(data);
}
});
});
});</script>
PHP Code:
<?php
//load_data.php
$connect = mysqli_connect("localhost", "root", "", "customer");
$output = '';
if(isset($_POST["user_id"]))
{
if($_POST["user_id"] != '')
{
$query = "SELECT * FROM add_offer WHERE user_id = '".$_POST["user_id"]."' ORDER BY id DESC";
}
else
{
$query = "SELECT * FROM add_offer ORDER BY id DESC";
}
$res = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($res))
{
$output .= '<div class="col-md-3 col-sm-4 col-lg-6">';
$output .= '<div class="panel panel-default">';
$output .= '<div class="panel-body">';
$output .= '<div style="padding:1px;float:left;font-weight:bold;">'.$row["part_no"].'</div>';
$output .= '<div style="padding:1px;float:left;">'.$row["make"].'</div>';
$output .= '<div style="padding:1px;float:left;">'.$row["date_code"].'</div>';
$output .= '<div style="padding:1px;float:left;">'.$row["qty"].'</div>';
$output .= '<br>';
$output .= '<div style="float:left;font-size:9px;">'.$row["time"].'</div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
}
echo $output;
}?>

Related

How to make Bootstrap Tab dynamic PHP?

I have a problem for making TAB dynamically. When I click Tab 2 (when class="tab-pane fade"), a tab content was duplicated from Tab 1 and so do to another tab.This is a screenshot
And this is my php code :
$sql1 = "SELECT * FROM pur_supp WHERE pn = '$id_p' and pn_interchange = '$id_a'";
$hasil1= mysqli_query($connect2,$sql1);
//$rowp = mysqli_fetch_assoc($hasil1);
$tab_menu = '';
$tab_content = '';
$i = 0;
while($row1 = mysqli_fetch_array($hasil1))
{
if($i == 0)
{
$tab_menu .= '
<li class="active">Priority '.$row1["priority"].'</li>
';
$tab_content .= '
<div id="priority'.$row1["priority"].'" class="tab-pane fade in active">
';
}
else
{
$tab_menu .= '
<li>Priority '.$row1["priority"].'</li>
';
$tab_content .= '
<div id="priority'.$row1["priority"].'" class="tab-pane fade">
';
}
$sql2 = "SELECT * FROM pur_supp WHERE pn = '$id_p' and pn_interchange = '$id_a' and priority = '".$row1["priority"]."' GROUP BY pn,pn_interchange";
$hasil2= mysqli_query($connect2,$sql2);
while($rowp = mysqli_fetch_array($hasil2))
{
$tab_content .= '<div class="panel-heading" align="center">';
$tab_content .= '<h2 >Selected Vendor Information</h2>';
$tab_content .= '<div class="panel-heading" align="center">';
$tab_content .= '<h5 >PURCHASE SUPPLIER</h5>';
$tab_content .= '<p style="font-weight: bold">Part Number';
$tab_content .= '<input style="text-align:center;margin-left: 90px" class="form-control" type="text" name="pn1" value="'. $rowp['pn'].'" readonly> </p>';
$tab_content .= ' <p style="font-weight: bold; text-align: left">Selected Vendor Information : Priority '.$rowp['priority'].'</p>';
}
$i++;
}

if checkbox checked enable his textarea

in this php code i have foreach loop create textarea with checkbox for each statement
i wanna to enable textarea if his checkbox is checked
but they have same id
<?php
foreach($Arows as $row){
echo '<tr class="row">
<th class="col-sm-12"><h4>'.$row['Type_A'].'</h4></th>
</tr>';
$stmt3 = $con->prepare("SELECT * FROM sous_analyse WHERE Id_A =".$row['Id_A']);
$stmt3->execute();
$SArows = $stmt3->fetchAll();//Analyse rows
foreach($SArows as $Srow){
echo '<tr class="row">
<td class="col-sm-4">'.$Srow['Parameter'].'</td>
<td class=" col-sm-5"><input type="text" class="form-control col-xl-12 border-secondary" name="Fonctionnalite" placeholder="RESULTATS" required=""></td>
<td class="col-sm-3 text-center">'.$Srow['Normal'].'</td>
</tr>';
}
echo '<tr class="row">
<th class="col-sm-12">
<div class="input-group">
<span class="input-group-addon form-check">
<span class="checkbox-custom checkbox-default">
<input type="checkbox" class="icheckbox-grey" id="inputUnchecked" name="inputUnchecked">
<label for="inputUnchecked"></label>
</span>
</span>
<textarea class="form-control" id="textareaDefault" rows="3" style="margin-top: 0px; margin-bottom: 0px; height: 60px;" disabled></textarea>
</div>
</th>
</tr>';
}
?>
i use this script but is working in first textarea
<script >
$(document).ready(function() {
$("#inputUnchecked").on('click', function() {
if($(this).is(':checked')){
$("#textareaDefault").prop('disabled',false);
} else {
$("#textareaDefault").prop('disabled',true);
}
alert("fdg");
})
});
</script>
Expanding on my comment, you will want to adjust your PHP. This is easily done with a counter ($c).
<?php
foreach($Arows as $row){
$html = "";
$html .= '<tr class="row">'."\r\n";
$html .= '<th class="col-sm-12"><h4>'.$row['Type_A'].'</h4></th>'."\r\n";
$html .= '</tr>'."\r\n";
$stmt3 = $con->prepare("SELECT * FROM sous_analyse WHERE Id_A =".$row['Id_A']);
$stmt3->execute();
$SArows = $stmt3->fetchAll();
$c = 1;
foreach($SArows as $Srow){
$html .= '<tr class="row">'."\r\n";
$html .= '<td class="col-sm-4">'.$Srow['Parameter'].'</td>';
$html .= '<td class=" col-sm-5"><input type="text" class="form-control col-xl-12 border-secondary" name="Fonctionnalite" placeholder="RESULTATS" required=""></td>';
$html .= '<td class="col-sm-3 text-center">'.$Srow['Normal'].'</td>';
$html .= '</tr>';
}
$html .= '<tr class="row">';
$html .= '<th class="col-sm-12">';
$html .= '<div class="input-group">';
$html .= '<span class="input-group-addon form-check">';
$html .= '<span class="checkbox-custom checkbox-default">';
$html .= '<input type="checkbox" class="icheckbox-grey" id="inputUnchecked-$c" name="inputUnchecked">';
$html .= '<label for="inputUnchecked-$c"></label>';
$html .= '</span></span>';
$html .= '<textarea class="form-control" id="textareaDefault-$c" rows="3" style="margin-top: 0px; margin-bottom: 0px; height: 60px;" disabled></textarea>';
$html .= '</div></th></tr>';
echo $html;
$c++;
}
?>
Your JavaScript can then use the ID since it is unique or can simply be relative to nearby elements.
$(function() {
$("[id^='inputUnchecked-']").on('click', function() {
if($(this).is(':checked')){
$(this).parent().parent().find("[id^='textareaDefault-']").prop('disabled',false);
} else {
$(this).parent().parent().find("[id^='textareaDefault-']").prop('disabled',true);
}
alert("fdg");
})
});

Not Able to access MySQL data through php function

I've added clients in clients.php sown on the following screenshot:
UPDATE: If I add new client from manange_sale page, The List Shows up soon after!
When I try to access them in another page through this function:
function get_client_info($client_id, $term) {
global $db;
$query = "SELECT * from clients WHERE client_id='".$client_id."'";
$result = $db->query($query) or die($db->error);
$row = $result->fetch_array();
return $row[$term];
}
It just does not show any clients list on that page:
Please help me resolve this issue.
Note: Same script is working perfectly on Online host but causing issues in localhost.
Rest of the client class:
<?php
//Notes Class
class Client {
public $full_name;
public $business_title;
public $mobile;
public $phone;
public $address;
public $city;
public $state;
public $zipcode;
public $country;
public $email;
public $price_level;
public $notes;
function get_client_info($client_id, $term) {
global $db;
$query = "SELECT * from clients WHERE client_id='".$client_id."'";
$result = $db->query($query) or die($db->error);
$row = $result->fetch_array();
return $row[$term];
}//get user email ends here.
function add_client($full_name, $business_title, $mobile, $phone, $address, $city, $state, $zipcode, $country, $email, $price_level, $notes) {
global $db;
$query = "SELECT * from clients WHERE full_name='".$full_name."' AND store_id='".$_SESSION['store_id']."'";
$result = $db->query($query) or die($db->error);
$num_rows = $result->num_rows;
if($num_rows > 0) {
return 'A client with same name already exists.';
} else {
$query = "INSERT into clients(client_id, full_name, business_title, mobile, phone, address, city, state, zipcode, country, email, price_level, notes, store_id)
VALUES(NULL, '".$full_name."', '".$business_title."', '".$mobile."', '".$phone."', '".$address."', '".$city."', '".$state."', '".$zipcode."', '".$country."', '".$email."', '".$price_level."', '".$notes."', '".$_SESSION['store_id']."')
";
$result = $db->query($query) or die($db->error);
$_SESSION['cn_id'] = $db->insert_id;
return 'Client added successfuly.';
}
}//add warehouse ends here.
function set_client($client_id) {
global $db;
$query = 'SELECT * from clients WHERE client_id="'.$client_id.'" AND store_id="'.$_SESSION['store_id'].'"';
$result = $db->query($query) or die($db->error);
$row = $result->fetch_array();
extract($row);
$this->full_name = $full_name;
$this->business_title = $business_title;
$this->mobile = $mobile;
$this->phone = $phone;
$this->address = $address;
$this->city = $city;
$this->state = $state;
$this->zipcode = $zipcode;
$this->country = $country;
$this->email = $email;
$this->price_level = $price_level;
$this->notes = $notes;
}//Set Warehouse ends here..
function update_client($client_id, $full_name, $business_title, $mobile, $phone, $address, $city, $state, $zipcode, $country, $email, $price_level, $notes) {
global $db;
$query = 'UPDATE clients SET
full_name = "'.$full_name.'",
business_title = "'.$business_title.'",
mobile = "'.$mobile.'",
phone = "'.$phone.'",
address = "'.$address.'",
city = "'.$city.'",
state = "'.$state.'",
zipcode = "'.$zipcode.'",
country = "'.$country.'",
email = "'.$email.'",
price_level = "'.$price_level.'",
notes = "'.$notes.'"
WHERE client_id="'.$client_id.'" AND store_id="'.$_SESSION['store_id'].'"';
$result = $db->query($query) or die($db->error);
return 'Client updated Successfuly!';
}//update user level ends here.
function list_clients() {
global $db;
$query = 'SELECT * from clients WHERE store_id="'.$_SESSION['store_id'].'" ORDER by full_name ASC';
$result = $db->query($query) or die($db->error);
$content = '';
$count = 0;
while($row = $result->fetch_array()) {
extract($row);
$count++;
if($count%2 == 0) {
$class = 'even';
} else {
$class = 'odd';
}
$content .= '<tr class="'.$class.'">';
$content .= '<td>';
$content .= $client_id;
$content .= '</td><td>';
$content .= $full_name;
$content .= '</td><td>';
$content .= $business_title;
$content .= '</td><td>';
$content .= $mobile;
$content .= '</td><td>';
$content .= $phone;
$content .= '</td><td>';
$content .= $address.' '.$city.' '.$state.' '.$zipcode.' '.$country;
$content .= '</td><td>';
$content .= $email;
$content .= '</td><td>';
$content .= $price_level;
$content .= '</td><td>';
$content .= currency_format($this->get_client_balance($client_id));
$content .= '</td>';
if(partial_access('admin')) {
$content .= '<td><form method="post" name="edit" action="manage_client.php">';
$content .= '<input type="hidden" name="edit_client" value="'.$client_id.'">';
$content .= '<input type="submit" class="btn btn-default btn-sm" value="Edit">';
$content .= '</form>';
$content .= '</td><td>';
$content .= '<form method="post" name="delete" onsubmit="return confirm_delete();" action="">';
$content .= '<input type="hidden" name="delete_client" value="'.$client_id.'">';
$content .= '<input type="submit" class="btn btn-default btn-sm" value="Delete">';
$content .= '</form>';
$content .= '</td>';
}
$content .= '</tr>';
unset($class);
}//loop ends here.
echo $content;
}//list_notes ends here.
function delete_client($client_id) {
global $db;
$query = "SELECT * FROM customer_log WHERE client_id='".$client_id."'";
$result = $db->query($query) or die($db->error);
$num_rows = $result->num_rows;
if($num_rows > 0) {
return 'Please delete sale invoices, receivings, return invoices, return payments for related client first.';
} else {
$query = "DELETE FROM clients WHERE client_id='".$client_id."'";
$result = $db->query($query) or die($db->error);
return 'Client deleted successfuly!';
}
}//delete client ends here.
function client_options($client_id) {
global $db;
$query = 'SELECT * from clients WHERE store_id="'.$_SESSION['store_id'].'" ORDER by full_name ASC';
$result = $db->query($query) or die($db->error);
$options = '';
if($client_id != '') {
while($row = $result->fetch_array()) {
if($client_id == $row['client_id']) {
$options .= '<option selected="selected" value="'.$row['client_id'].'">'.$row['full_name'].' ('.$row['mobile'].')</option>';
} else {
$options .= '<option value="'.$row['client_id'].'">'.$row['full_name'].' ('.$row['mobile'].')</option>';
}
}
} else {
while($row = $result->fetch_array()) {
$options .= '<option value="'.$row['client_id'].'">'.$row['full_name'].' ('.$row['mobile'].')</option>';
}
}
return $options;
}//vendor options ends here.
function add_log($datetime, $client_id, $transaction_type, $type_table_id) {
global $db;
$query = "INSERT into customer_log(customer_log_id, datetime, client_id, transaction_type, type_table_id, store_id) VALUES(NULL, '".$datetime."', '".$client_id."', '".$transaction_type."', '".$type_table_id."', '".$_SESSION['store_id']."')";
$result = $db->query($query) or die($db->error);
return $db->insert_id;
}//add log ends here.
function add_receiving($date, $method, $ref_no, $memo, $amount, $client_id) {
global $db;
$query = "INSERT into receivings(receiving_id, datetime, method, ref_no, memo, amount, client_id, agent_id, store_id) VALUES(NULL, '".$date."', '".$method."', '".$ref_no."', '".$memo."', '".$amount."', '".$client_id."', '".$_SESSION['user_id']."', '".$_SESSION['store_id']."')";
$result = $db->query($query) or die($db->error);
return $db->insert_id;
}//add_payment ends here.
function add_return_payment($date, $method, $ref_no, $memo, $amount, $client_id) {
global $db;
$query = "INSERT into sale_return_payment(return_payment_id, datetime, method, ref_no, memo, amount, client_id, agent_id, store_id) VALUES(NULL, '".$date."', '".$method."', '".$ref_no."', '".$memo."', '".$amount."', '".$client_id."', '".$_SESSION['user_id']."', '".$_SESSION['store_id']."')";
$result = $db->query($query) or die($db->error);
return $db->insert_id;
}//add_payment ends here.
function get_client_balance($client_id) {
global $db;
$creditQuery = "SELECt * from creditors WHERE client_id='".$client_id."' AND store_id='".$_SESSION['store_id']."'";
$creditResult = $db->query($creditQuery) or die($db->error);
$receiveable = 0;
while($creditRow = $creditResult->fetch_array()) {
$receiveable += $creditRow['receiveable'];
if($creditRow['receiveable'] == 0) {
$receiveable -= $creditRow['received'];
}
}
$receivingQuery = "SELECt * from receivings WHERE client_id='".$client_id."' AND store_id='".$_SESSION['store_id']."'";
$receivingResult = $db->query($receivingQuery) or die($db->error);
while($recevingRow = $receivingResult->fetch_array()) {
$receiveable -= $recevingRow['amount'];
}
$sale_return_payment = "SELECt * from sale_return_payment WHERE client_id='".$client_id."' AND store_id='".$_SESSION['store_id']."'";
$sale_payment_result = $db->query($sale_return_payment) or die($db->error);
while($sale_return_row = $sale_payment_result->fetch_array()) {
$receiveable -= $sale_return_row['amount'];
}
return $receiveable;
}//get vendor balance ends here.
function list_receivings() {
global $db;
$query = 'SELECT * from receivings WHERE store_id="'.$_SESSION['store_id'].'" ORDER by receiving_id DESC';
$result = $db->query($query) or die($db->error);
$content = '';
while($row = $result->fetch_array()) {
extract($row);
$datetime = strtotime($datetime);
$date = date('d-M-Y', $datetime);
$client = $this->get_client_info($client_id, 'full_name');
$user = new Users;
$agent = $user->get_user_info($agent_id, 'first_name').' '.$user->get_user_info($agent_id, 'last_name');
$content .= '<tr><td>';
$content .= $receiving_id;
$content .= '</td><td>';
$content .= $date;
$content .= '</td><td>';
$content .= $method;
$content .= '</td><td>';
$content .= $ref_no;
$content .= '</td><td>';
$content .= $agent;
$content .= '</td><td>';
$content .= $client;
$content .= '</td><td>';
$content .= $memo;
$content .= '</td><td>';
$content .= $amount;
$content .= '</td>';
if(partial_access('admin')) {
$content .= '<td><form method="post" name="delete" onsubmit="return confirm_delete();" action="">';
$content .= '<input type="hidden" name="delete_receiving" value="'.$receiving_id.'">';
$content .= '<input type="submit" class="btn btn-default btn-sm" value="Delete">';
$content .= '</form>';
$content .= '</td>'; }
$content .= '</tr>';
unset($class);
}//loop ends here.
echo $content;
}//list_notes ends here.
function delete_receiving($receiving_id) {
global $db;
$query = "DELETE from receivings WHERE receiving_id='".$receiving_id."'";
$result = $db->query($query) or die($db->error);
$query = "DELETE from customer_log WHERE transaction_type='Sale Receiving' AND type_table_id='".$receiving_id."'";
$result = $db->query($query) or die($db->error);
$query = "DELETE from customer_log WHERE transaction_type='Receiving' AND type_table_id='".$receiving_id."'";
$result = $db->query($query) or die($db->error);
return 'Receiving deleted Successfuly.';
}//delete_purchase return receiving.
function list_return_payments() {
global $db;
$query = 'SELECT * from sale_return_payment WHERE store_id="'.$_SESSION['store_id'].'" ORDER by return_payment_id DESC';
$result = $db->query($query) or die($db->error);
$content = '';
while($row = $result->fetch_array()) {
extract($row);
$datetime = strtotime($datetime);
$date = date('d-M-Y', $datetime);
$client = $this->get_client_info($client_id, 'full_name');
$user = new Users;
$agent = $user->get_user_info($agent_id, 'first_name').' '.$user->get_user_info($agent_id, 'last_name');
$content .= '<tr><td>';
$content .= $return_payment_id;
$content .= '</td><td>';
$content .= $date;
$content .= '</td><td>';
$content .= $method;
$content .= '</td><td>';
$content .= $ref_no;
$content .= '</td><td>';
$content .= $agent;
$content .= '</td><td>';
$content .= $client;
$content .= '</td><td>';
$content .= $memo;
$content .= '</td><td>';
$content .= $amount;
$content .= '</td>';
if(partial_access('admin')) {
$content .= '<td><form method="post" name="delete" onsubmit="return confirm_delete();" action="">';
$content .= '<input type="hidden" name="delete_sale_return_payment" value="'.$return_payment_id.'">';
$content .= '<input type="submit" class="btn btn-default btn-sm" value="Delete">';
$content .= '</form>';
$content .= '</td>'; }
$content .= '</tr>';
}//loop ends here.
echo $content;
}//list_notes ends here.
function delete_sale_return_payment($return_payment_id) {
global $db;
$query = "DELETE from sale_return_payment WHERE return_payment_id='".$return_payment_id."'";
$result = $db->query($query) or die($db->error);
$query = "DELETE from customer_log WHERE transaction_type='Sale Return Refund' AND type_table_id='".$return_payment_id."'";
$result = $db->query($query) or die($db->error);
return 'Return Payment deleted Successfuly.';
}//delete_purchase return receiving.
function clear_creditors($amount, $client_id){
global $db;
$query = "SELECT * FROM creditors WHERE client_id='".$client_id."' ORDER by credit_id ASC";
$result = $db->query($query) or die($db->error);
while($row = $result->fetch_array()) {
extract($row);
if($receiveable == 0 || $receiveable == $received || $amount == 0) {
//do nothing.
} else {
if($received == 0) {
if($amount < $receiveable) {
$receive = $amount;
} else {
$receive = $receiveable;
}
$query_up = "UPDATE creditors SET
received = '".$receive."'
WHERE credit_id='".$credit_id."'
";
$amount -= $receive;
} else if($received != 0) {
$difference = $receiveable-$received;
if($amount < $difference) {
$receive = $amount+$received;
} else {
$receive = $difference+$received;
}
$query_up = "UPDATE creditors SET
received = '".$receive."'
WHERE credit_id='".$credit_id."'
";
$amount -= $difference;
}
$result_up = $db->query($query_up) or die($db->error);
}//main if ends here.
}//main loop ends.
}//debts clear ends here.--
function customers_balance_summary() {
global $db;
$query = "SELECT * FROM clients WHERE store_id='".$_SESSION['store_id']."' ORDER by full_name ASC";
$result = $db->query($query) or die($db->error);
$content = '';
$grand_total = 0;
while($row = $result->fetch_array()) {
extract($row);
//getting balance.
$balance = $this->get_client_balance($client_id);
$grand_total += $balance;
$content .= '<tr><td>';
$content .= $full_name;
$content .= '</td><td>';
$content .= $business_title;
$content .= '</td><td align="right">';
$content .= currency_format($grand_total);
$content .= '</td></tr>';
}
$new_store = new Store;
$currency = $new_store->get_store_info($_SESSION['store_id'], 'currency');
$content .= '<tr><th colspan="2" align="right">Grand Total</th><th align="right">'.$currency.' '.currency_format($grand_total).'</tH></tr>';
echo $content;
}//customers balance summary ends here.
function customer_ledger_summary($client) {
global $db;
$query = "SELECT * from customer_log WHERE client_id='".$client."' ORDER by customer_log_id ASC";
$result = $db->query($query) or die($db->error);
$balance = 0;
$content = '';
$balance = 0;
while($row = $result->fetch_array()) {
extract($row);
$datetime = strtotime($datetime);
$date = date('d-M-Y', $datetime);
$content .= '<tr><td>';
$content .= $transaction_type;
$content .= '</td><td>';
$content .= $date;
$content .= '</td><td>';
$content .= $type_table_id;
$content .= '</td><td>';
if($transaction_type == 'Sale Invoice' || $transaction_type == 'Cash Sale') {
//Invoice Details.
$sale_query = "SELECT * from sales WHERE sale_id='".$type_table_id."'";
$sale_result = $db->query($sale_query) or die($db->error);
while($sale_row = $sale_result->fetch_array()) {
$content .= $sale_row['memo'];
$content .= '</td><td>';
}
$sale_detail_query = "SELECT * from sale_detail WHERE sale_id='".$type_table_id."'";
$sale_detail_result = $db->query($sale_detail_query) or die($db->error);
$invoice_total = 0;
while($sale_detail_row = $sale_detail_result->fetch_array()) {
$credit_query = "SELECT * from creditors WHERE credit_id='".$sale_detail_row['credit_id']."'";
$credit_result = $db->query($credit_query) or die($db->error);
while($credit_row = $credit_result->fetch_array()) {
$invoice_total += $credit_row['receiveable'];
}
}
$balance = $invoice_total+$balance;
$content .= currency_format($invoice_total);
$content .= '</td><td>';
$content .= currency_format($balance);
$content .= '</td></tr>';
} else if($transaction_type == 'Sale Receiving' || $transaction_type == 'Receiving') {
//Cash receivign.
$receiving_query = "SELECT * from receivings WHERE receiving_id='".$type_table_id."'";
$receiving_result = $db->query($receiving_query) or die($db->error);
while($receiving_row = $receiving_result->fetch_array()) {
$content .= $receiving_row['memo'];
$content .= '</td><td>';
$balance = $balance-$receiving_row['amount'];
$content .= '('.currency_format($receiving_row['amount']).')';
$content .= '</td><td>';
$content .= currency_format($balance);
$content .= '</td></tr>';
}
} else if($transaction_type == 'Invoice Return' || $transaction_type == 'Sale Return') {
//sale return invoice.
$sale_query = "SELECT * from sale_returns WHERE sale_rt_id='".$type_table_id."'";
$sale_result = $db->query($sale_query) or die($db->error);
while($sale_row = $sale_result->fetch_array()) {
$content .= $sale_row['memo'];
$content .= '</td><td>';
}
$sale_detail_query = "SELECT * from sale_return_detail WHERE sale_rt_id='".$type_table_id."'";
$sale_detail_result = $db->query($sale_detail_query) or die($db->error);
$invoice_total = 0;
while($sale_detail_row = $sale_detail_result->fetch_array()) {
$credit_query = "SELECT * from creditors WHERE credit_id='".$sale_detail_row['credit_id']."'";
$credit_result = $db->query($credit_query) or die($db->error);
while($credit_row = $credit_result->fetch_array()) {
$invoice_total += $credit_row['received'];
}
}
$balance = $balance-$invoice_total;
$content .= '('.currency_format($invoice_total).')';
$content .= '</td><td>';
$content .= currency_format($balance);
$content .= '</td></tr>';
} else if($transaction_type == 'Sale Return Refund') {
//sale Return Payment.
$receiving_query = "SELECT * from sale_return_payment WHERE return_payment_id='".$type_table_id."'";
$receiving_result = $db->query($receiving_query) or die($db->error);
while($receiving_row = $receiving_result->fetch_array()) {
$content .= $receiving_row['memo'];
$content .= '</td><td>';
$balance = $balance+$receiving_row['amount'];
$content .= currency_format($receiving_row['amount']);
$content .= '</td><td>';
$content .= currency_format($balance);
$content .= '</td></tr>';
}
}
}//main loop ends here.
echo $content;
}//customer ledger summary ends here.
}//class ends here.
The shown screen code where this class functions are being used:
`
<?php
include('system_load.php');
//This loads system.
//user Authentication.
authenticate_user('subscriber');
//creating company object.
if(partial_access('admin') || $store_access->have_module_access('sales')) {} else {
HEADER('LOCATION: store.php?message=products');
}
if(!isset($_SESSION['store_id']) || $_SESSION['store_id'] == '') {
HEADER('LOCATION: stores.php?message=1');
} //select company redirect ends here.
if(isset($_POST['edit_purchase'])){ $page_title = 'Edit Sale'; } else { $page_title = 'Add Sale';}; //You can edit this to change your page title.
require_once("includes/header.php"); //including header file.
?>
<?php if(isset($_GET['sale_id'])) { ?>
<script type="text/javascript">
window.open('reports/view_sale_invoice.php?sale_id=<?php echo $_GET['sale_id']; ?>', '_blank');
</script>
<?php } ?>
<?php
//display message if exist.
if(isset($_GET['message']) && $_GET['message'] != '') {
echo '<div class="alert alert-success">';
echo $_GET['message'];
echo '</div>';
}
if(isset($message) && $message != '') {
echo '<div class="alert alert-success">';
echo $message;
echo '</div>';
}
?>
<style type="text/css">
textarea:hover, textarea:focus, #items td.total-value textarea:hover, #items td.total-value textarea:focus, .delme:hover { background-color:#EEFF88; }
#items input[type=text] {width:60px;border:0px;}
.delete-wpr { position: relative; }
.delme { display: block; color: #000; text-decoration: none; position: absolute; background: #EEEEEE; font-weight: bold; padding: 0px 3px; border: 1px solid; top: -6px; left: -22px; font-family: Verdana; font-size: 12px; }
</style>
<script type="text/javascript">
jQuery(function($) {
$('form[data-async]').on('submit', function(event) {
var $form = $(this);
var $target = $($form.attr('data-target'));
$.ajax({
type: $form.attr('method'),
url: 'includes/otherprocesses.php',
data: $form.serialize(),
dataType: 'json',
success: function(response) {
var message = response.message;
var client_options = response.client_options;
var client_id = response.client_id;
$('#client_id').html(client_options);
$("#client_id").select2().select2('val', client_id);
$('#success_message').html('<div class="alert alert-success">'+message+'</div>');
}
});
event.preventDefault();
});
});
</script>
<!-- Add new vendor modal starts here. -->
<div class="modal fade" id="addnewclient" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add new client</h4>
</div>
<div class="modal-body">
<form data-async data-target="#addnewclient" method="POST" enctype="multipart/form-data" role="form">
<div id="success_message"></div>
<table style="width:100%;">
<tr>
<td>
<div class="form-group">
<label class="control-label">Full Name*</label>
<input type="text" class="form-control" name="full_name" placeholder="Client full name" value="" required="required" />
</div>
</td>
<td>
<div class="form-group">
<label class="control-label">Business Title</label>
<input type="hidden" name="add_client" value="1" />
<input type="submit" id="submit" class="btn btn-primary" value="Add client">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!--add new vendor modal ends here.-->
<form action="includes/process_sale.php" method="post">
<div class="row">
<div class="col-sm-5">
<table border="0" cellpadding="5">
<tr>
<td width="110">Date</td>
<td width="300"><input type="text" name="date" class="form-control datepick" readonly="readonly" value="<?php echo date('Y-m-d'); ?>" /></td>
</tr>
<tr>
<td>Custom Inv#</td>
<td><input type="text" placeholder="Custom Invoice number" name="custom_inv_no" class="form-control" /></td>
</tr>
<tr>
<td>Memo</td>
<td><textarea placeholder="Memo" name="memo" class="form-control"></textarea></td>
</tr>
<tr>
<th>Select Client</th>
<td>
<select name="client_id" id="client_id" class="autofill" style="width:100%">
<option value="">Select Client by full name or mobile</option>
<?
=$client->client_options($client->client_id);
?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><a class="btn btn-default btn-xs" data-toggle="modal" href="#addnewclient">Add new Client</a></td>
</tr>
</table>
</div><!--left-side-form ends here.-->
<script type="text/javascript">
function update_total() {
var grand_total = 0;
i = 1;
$('.total').each(function(i) {
var total = $(this).html();
total = parseFloat(total);
grand_total = total+grand_total;
});
$('#grand_total').html(grand_total.toFixed(2));
}//Update total function ends here.
<?php
require_once("includes/footer.php");
?>
What plattform do you use for the localhost? Online linux server and local a Windows machine? As it is run on the localhost, do you get warnings, notices or the sort? Or even a fatal?
<?
=$client->client_options($client->client_id);
?>
That looks odd. Why the '='?
Okay I finally figured how to make it work by the hint provided above. Actually this Syntax doesn't work in this case:
<?=$client->client_options($client->client_id);?>
The Solution is:
<?php echo $client->client_options($client->client_id); ?>
Thanks all anyway for brainstorming.

PHP while loop number of rows

im struggling with php while loop. The goal is to get the quote from the database and display it with 3 columns on each row. As it look now the while loop is displaying one column each row. How should i correct this problem?
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$row = $ip['id'];
$row = $ip['quote'];
$row = $ip['topic'];
$row = $ip['author'];
$nr = 0;
$sql = "SELECT * FROM quotes ORDER BY date DESC limit 10";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc() ) {
$nr++;
echo
"<div class='container row'>
<div class='col s12 m6 l4 z-depth-1'>
<div class='card-panel grey darken-4 white-text center'><h5>Citat: ". $row["id"] ."</h5></div> <pre class='flow-text black-text' wrap='soft'>" ."<p class=''>Författare: ". $row["author"] ."</p>"
. "<p class=''>Citat: ". $row["quote"] ."</p>" . $row["topic"] ."</pre>
<div class='content_wrapper'>
<h4>Vote </h4>
<div class='voting_wrapper' id='". $row["id"] ."'>
<div class='voting_btn'>
<div class='up_button'> </div><span class='up_votes'>0</span>
</div>
<div class='voting_btn'>
<div class='down_button'> </div><span class='down_votes'>0</span>
</div>
<br>
</div>
</div>
</div>
</div>";
}
}else {
echo "0 results";
}
$conn->close();
?>
You could do something like this:
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//DO YOU NEED THESE VARIABLES? I DON'T SEE THEIR USE HERE... BESIDES, $row DOES NOT EXIST YET...
$row = $ip['id'];
$row = $ip['quote'];
$row = $ip['topic'];
$row = $ip['author'];
$nr = 0;
$sql = "SELECT * FROM quotes ORDER BY date DESC limit 10";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$output = "";
while($row = $result->fetch_assoc() ) {
$topic = trim($row["topic"]);
$quote = trim($row["quote"]);
$author = trim($row["author"]);
$id = trim($row["id"]);
$output .= injectNColumnWrapper(3, $nr, "container row", $nr);
$output .="<div class='col s12 m6 l4 z-depth-1'>";
$output .="<div class='card-panel grey darken-4 white-text center'>";
$output .=" <h5>Citat: {$id}</h5>";
$output .="</div>";
$output .="pre class='flow-text black-text' wrap='soft'>";
$output .="<p class='flow-text-p author'>Författare: {$author}</p>";
$output .="<p class='flow-text-p citat'>Citat: {$quote}</p>";
$output .="<p class='flow-text-p topic'>{$topic}</p>";
$output .="</pre>";
$output .="<div class='content_wrapper'>";
$output .="<h4>Vote </h4>";
$output .="<div class='voting_wrapper' id='vote-{$id}'>";
$output .="<div class='voting_btn'>";
$output .="<div class='up_button'> </div>";
$output .="<span class='up_votes'>0</span>";
$output .="</div>";
$output .="<div class='voting_btn'>";
$output .="<div class='down_button'> </div>";
$output .="<span class='down_votes'>0</span>";
$output .="</div>";
$output .="<br>";
$output .="</div>";
$output .="</div>";
$output .="</div>";
$nr++;
}
$output .= "</div>";
echo $output;
}else {
echo "0 results";
}
$conn->close();
function injectNColumnWrapper($cols_per_row, $closePoint, $cssClass="container row", $nthElem=""){
$blockDisplay = "";
if( ($closePoint == 0) ){
$blockDisplay = "<div class='" . $cssClass . " container_nr_" . $nthElem . "'>" . PHP_EOL;
}else if( ($closePoint % $cols_per_row) == 0 && ($closePoint != 0) ){
$blockDisplay = "</div><div class='" . $cssClass . " container_nr_" . $nthElem . "'>" . PHP_EOL;
}
return $blockDisplay;
}
?>
You should have 3 Columns per Row like so:
<div class="container">
<div class="col s12 m6 l4 z-depth-1">Column 1</div>
<div class="col s12 m6 l4 z-depth-1">Column 2</div>
<div class="col s12 m6 l4 z-depth-1">Column 3</div>
</div>
I hope this helps a little bit...
Try it:-
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$row = $ip['id'];
$row = $ip['quote'];
$row = $ip['topic'];
$row = $ip['author'];
$nr = 0;
$sql = "SELECT * FROM quotes ORDER BY date DESC limit 10";
$result = $conn->query($sql);
$chngrow=0;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc() ) {
$nr++;
$chngrow = $chngrow + 1;
echo
"<div class='container row'>
<div class='col s12 m6 l4 z-depth-1'>
<div class='card-panel grey darken-4 white-text center'><h5>Citat: ". $row["id"] ."</h5></div> <pre class='flow-text black-text' wrap='soft'>" ."<p class=''>Författare: ". $row["author"] ."</p>"
. "<p class=''>Citat: ". $row["quote"] ."</p>" . $row["topic"] ."</pre>
<div class='content_wrapper'>
<h4>Vote </h4>
<div class='voting_wrapper' id='". $row["id"] ."'>
<div class='voting_btn'>
<div class='up_button'> </div><span class='up_votes'>0</span>
</div>
<div class='voting_btn'>
<div class='down_button'> </div><span class='down_votes'>0</span>
</div>
<br>
</div>
</div>
</div>
</div>";
$mod = ($chngrow % 3);
echo ($mod==0) ? "<br>" : "";
}
}else {
echo "0 results";
}
$conn->close();
?>
Elaborating #RuchishParikh comment, which already contains the core of the solution:
$nr = 0;
while ($row = $result->fetch_assoc()) {
$nr++;
if ($nr % 3 == 0) {
echo "<div class='container row'>\n"; # start of row
}
echo "<div class='col s4 m6 l4 z-depth-1'>\n"; # start of column
echo " ...\n";
echo "</div>\n"; # end of column
if ($nr % 3 == 0) {
echo "</div>\n"; # end of row
}
}
Try like this,
$nr =0;
while($row = $result->fetch_assoc() ) {
$nr++;
if(($count-1)%3==0) echo '<div class="row">';
//Add your content units here.
if(($count)%3==0) echo '</div>';
}
increment a counter variable for every loop. open table tag and tr tag outside of the loop. the while loop should have td tag alone. if count%3==0 then close the tr tag and open a new tr tag.
$i=0
?><table><tr><?
while(condition)
{
$i++;
if($i%3==0)
{
?></tr><tr><?
}
?><td>your data</td><?
}
?></tr></table><?
You messed up with the variables.
Don't need to declare $row below:
$row = $ip['id'];
$row = $ip['quote'];
$row = $ip['topic'];
$row = $ip['author'];
As stated here Why shouldn't I use mysql_* functions in PHP? don't use mysql_* functions.
You need to fetch 3 rows and place them inside one container.
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
$db = new PDO("mysql:host=$servername;dbname=$dbname;charset=UTF-8",
$username
$password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$sql = "SELECT * FROM quotes ORDER BY date DESC limit 10";
$nr = 0;
$stmt = $db->query('SELECT * FROM table');
while($row1 = $stmt->fetch(PDO::FETCH_ASSOC)) {
$row2 = $stmt->fetch(PDO::FETCH_ASSOC);
$row3 = $stmt->fetch(PDO::FETCH_ASSOC);
$rows[] = $row1;
if ($row2) $rows[] = $row2;
if ($row3) $rows[] = $row3;
echo "<div class='container row'>\n"
foreach($rows as $row) {
$nr++;
$id_ = $row["id"];
$author_ = $row["author"];
$quote_ = $row["quote"];
$topic_ = $row["topic"];
echo
"<div class='col s12 m6 l4 z-depth-1'>
<div class='card-panel grey darken-4 white-text center'><h5>Citat:$id_ </h5></div>
<pre class='flow-text black-text' wrap='soft'>
<p class=''>Författare: $author_</p>
<p class=''>Citat: $quote_</p>
$topic_
</pre>
<div class='content_wrapper'>
<h4>Vote </h4>
<div class='voting_wrapper' id='$id_'>
<div class='voting_btn'>
<div class='up_button'> </div><span class='up_votes'>0</span>
</div>
<div class='voting_btn'>
<div class='down_button'> </div><span class='down_votes'>0</span>
</div>
<br />
</div>
</div>
</div>";
}
echo "</div>\n";
$rows = null;
}
if ($nr == 0){
echo "0 results";
}
?>
Try this
$i=0
?><table><tr><?
while(condition)
{
$i++;
if($i%3==0)
{
?></tr><tr><?
}
?><td>your data</td><?
}
?></tr></table><?

Images in loop with different div class in PHP

Suppose I have code like bellow
<?php
$sql = "SELECT * FROM images";
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)) {
echo '<div class="single">';
echo '<img src="'.$row['image'].'" alt="'.$row['title'].' " />';
echo '</div>';
}
?>
And I want to append first and last in div class <div class="single"> in every set of 5 images i.e
<div class="single first">
<img src="image1.jpg" alt="title1" />
</div>
<div class="single">
<img src="image2.jpg" alt="title2" />
</div>
<div class="single">
<img src="image3.jpg" alt="title3" />
</div>
<div class="single">
<img src="image4.jpg" alt="title4" />
</div>
<div class="single last">
<img src="image5.jpg" alt="title5" />
</div>
How to do it through loop, please help,
Thanks :)
Using modulo:
<?php
$sql = "SELECT * FROM images";
$query = mysql_query($sql);
$i = 0;
$class = "";
while($row = mysql_fetch_assoc($query)) {
if($i % 5 == 0){
$class = 'first';
}else if($i % 5 == 4){
$class = 'last';
}else{
$class = "";
}
echo '<div class="single ' . $class . '">';
echo '<img src="'.$row['image'].'" alt="'.$row['title'].' " />';
echo '</div>';
$i++;
}
?>
<?php
$sql = "SELECT * FROM images";
$query = mysql_query($sql);
$x=0;
while($row = mysql_fetch_assoc($query)) {
$x++;
if ( $x == 1 ) { $c = ' first'; }
elseif ( $x == 5 ) { $c = ' last'; }
else { $c = ''; }
echo '<div class="single' . $c . '">';
echo '<img src="'.$row['image'].'" alt="'.$row['title'].' " />';
echo '</div>';
}
?>
You need to count your iterations, and use the modulo function to get parts of 5:
$sql = "SELECT * FROM images";
$query = mysql_query($sql);
$i = 0;
while($row = mysql_fetch_assoc($query)) {
if($i % 5 == 0)
echo '<div class="single first">';
else if($i % 5 == 4)
echo '<div class="single last">';
else
echo '<div class="single">';
echo '<img src="'.$row['image'].'" alt="'.$row['title'].' " />';
echo '</div>';
$i++;
}
How about this:
$index = 0;
while($row = mysql_fetch_assoc($query)) {
$classes = 'single';
switch ($index % 5) {
case 0:
$classes .= ' first';
break;
case 4:
$classes .= ' last';
break;
}
echo <<<HTML
<div class="$classes">
<img src="{$row['image']}" alt="{$row['title']}" />
</div>;
HTML;
$index++;
}
As a sidenote, have you considered using CSS nth-child property instead?

Categories