The following code is displaying product name in one row and quantity,price and subtotal in new row, how to get all these on same row. Output screenshot as been attached below.
code output
<table class="table table-striped table-condensed">
<tbody>
<?php
$r = 1;
$tax_summary = array();
foreach ($rows as $row) {
if (isset($tax_summary[$row->tax_code])) {
$tax_summary[$row->tax_code]['items'] += $row->quantity;
$tax_summary[$row->tax_code]['tax'] += $row->item_tax;
$tax_summary[$row->tax_code]['amt'] += ($row->quantity * $row->net_unit_price) - $row->item_discount;
} else {
$tax_summary[$row->tax_code]['items'] = $row->quantity;
$tax_summary[$row->tax_code]['tax'] = $row->item_tax;
$tax_summary[$row->tax_code]['amt'] = ($row->quantity * $row->net_unit_price) - $row->item_discount;
$tax_summary[$row->tax_code]['name'] = $row->tax_name;
$tax_summary[$row->tax_code]['code'] = $row->tax_code;
$tax_summary[$row->tax_code]['rate'] = $row->tax_rate;
}
echo '<tr><td colspan="2">#' . $r . ': ' . product_name($row->product_name) . ($row->variant ? ' (' . $row->variant . ')' : '') . '<span class="pull-right">' . $row->tax_code . '</span></td></tr>';
echo '<tr><td>' . $this->sma->formatNumber($row->quantity) . ' x ';
if ($row->item_discount != 0) {
echo '<del>' . $this->sma->formatMoney($row->net_unit_price + ($row->item_discount / $row->quantity) + ($row->item_tax / $row->quantity)) . '</del> ';
}
echo $this->sma->formatMoney($row->net_unit_price + ($row->item_tax / $row->quantity)) . '</td><td class="text-right">' . $this->sma->formatMoney($row->subtotal) . '</td></tr>';
$r++;
}
?>
</tbody>
<tfoot>
<tr>
Try below, but probabbly the formatting will be broken:
<table class="table table-striped table-condensed">
<tbody>
<?php
$r = 1;
$tax_summary = array();
foreach ($rows as $row) {
if (isset($tax_summary[$row->tax_code])) {
$tax_summary[$row->tax_code]['items'] += $row->quantity;
$tax_summary[$row->tax_code]['tax'] += $row->item_tax;
$tax_summary[$row->tax_code]['amt'] += ($row->quantity * $row->net_unit_price) - $row->item_discount;
} else {
$tax_summary[$row->tax_code]['items'] = $row->quantity;
$tax_summary[$row->tax_code]['tax'] = $row->item_tax;
$tax_summary[$row->tax_code]['amt'] = ($row->quantity * $row->net_unit_price) - $row->item_discount;
$tax_summary[$row->tax_code]['name'] = $row->tax_name;
$tax_summary[$row->tax_code]['code'] = $row->tax_code;
$tax_summary[$row->tax_code]['rate'] = $row->tax_rate;
}
echo '<tr><td colspan="2">#' . $r . ': ' . product_name($row->product_name) . ($row->variant ? ' (' . $row->variant . ')' : '') . '<span class="pull-right">' . $row->tax_code . '</span>';
echo '' . $this->sma->formatNumber($row->quantity) . ' x ';
if ($row->item_discount != 0) {
echo '<del>' . $this->sma->formatMoney($row->net_unit_price + ($row->item_discount / $row->quantity) + ($row->item_tax / $row->quantity)) . '</del> ';
}
echo $this->sma->formatMoney($row->net_unit_price + ($row->item_tax / $row->quantity)) . '' . $this->sma->formatMoney($row->subtotal) . '</td></tr>';
$r++;
}
?>
</tbody>
Related
I have an API that's showing almost 100 trades that I want to limit to just 10. I've tried
if($bitcointrades == 10) break
but that didn't work. Do I run a for loop after I pull the data? Should I break up the functions into two parts as opposed to using elseif to present $trades? Here's what I'm working with:
<?php
require_once('bitcoin.class.php');
$data = new Bitcoin();
$type = $_GET['type'];
$currency = $_GET['currency'];
if($type == 'ticker') {
$bitcoinlive = $data->getPrice($currency);
echo '<h2>1 Bitcoin is currently worth <span class="bitvalue">' .
number_format((float)$bitcoinlive['last'], 2) . ' <span class="upper">'
. $currency . '</span></span></h2>';
echo ' <p><span><i class="icon-arrow-up-circle"></i> High: ' .
number_format((float)$bitcoinlive['high'], 2) . '</span> <span><i
class="icon-arrow-down-circle"></i> Low: ' .
number_format((float)$bitcoinlive['low'], 2) . '</span>';
} elseif($type == 'trades') {
$bitcointrades = $data->getTrades($currency);
foreach($bitcointrades as $trade) {
if($trade['type'] == 'buy') {
$ttype = '<span class="green"><i class="icon-plus-circle"></i> Buy
Order</span>';
} else {
$ttype = '<span class="blue"><i class="icon-circle-minus"></i> Sell
Order</span>';
}
echo' <tr> <th scope="row">' . $ttype . '</th> <td>' . $trade['price']
. ' <span class="upper">' . $currency . '</span></td> <td>' .
$trade['amount'] . '</td> <td>' . $data->timeAgo($trade['date']) .
'</td> </tr>';
}
}
It's normal if($bitcointrades == 10) break isn't going to work.
$bitcointrades should be an array with trades which you define as $trade.
You need to use an iterator i like in the example below:
<?php
$i = 0;
foreach($bitcointrades as $trade) {
if($i==10)
break;
// your logic here
$i++;
}
You can finish a foreach execution using break so you can use a cnt and break
$my_cnt = 0;
foreach($bitcointrades as $trade) {
if ($my_cnt >= 10) {
break;
}
if($trade['type'] == 'buy') {
$ttype = '<span class="green"><i class="icon-plus-circle"></i> Buy
Order</span>';
} else {
$ttype = '<span class="blue"><i class="icon-circle-minus"></i> Sell
Order</span>';
}
$my_cnt++;
}
Do Like this way
$i = 0;
foreach ($bitcointrades as $trade) {
if ($trade['type'] == 'buy') {
$ttype = '<span class="green"><i class="icon-plus-circle"></i> Buy Order</span>';
} else {
$ttype = '<span class="blue"><i class="icon-circle-minus"></i> Sell Order</span>';
}
echo ' <tr> <th scope="row">' . $ttype . '</th> <td>' . $trade['price']
. ' <span class="upper">' . $currency . '</span></td> <td>' .
$trade['amount'] . '</td> <td>' . $data->timeAgo($trade['date']) .
'</td> </tr>';
$i++;
if ($i == 10) {
break;
}
}
I have a php leaderboard and it works great, and works well with ties. Currently it will number users from 1st to last place (whichever # that is), and if there are ties, it lists them all out with the same number.
For example:
userC 2. userG 3. userA 3. userT 3. userJ 4. userW 5. userP
What I would like is for when there are ties, for the leaderboard to display a "(t)" next to the number, like so: (t) 3. userT
Here is my code, any help is appreciated:
<table cellpadding="4" cellspacing="0" class="table1" width="100%"><caption>
<h2>Leaderboard</h2>
</caption>
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
$playerTotals = sort2d($playerTotals, 'score', 'desc');
$i = 1;
$tmpScore = 0;
//show place #
foreach($playerTotals as $playerID => $stats) {
if ($tmpScore < $stats[score]) $tmpScore = $stats[score];
//if next lowest score is reached, increase counter
if ($stats[score] < $tmpScore ) $i++;
$pickRatio = $stats[score] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($stats[score] / $possibleScoreTotal) * 100), 2) . '%';
//display users/stats
$rowclass = ((($i - 1) % 2 == 0) ? ' class="altrow"' : '');
echo ' <tr' . $rowclass . '><td style="height: 25px;"><b>' . $i . '</b>. ' . $stats[userName] . '</td><td align="center">' . $stats[wins] . '</td><td align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
$tmpScore = $stats[score];
}
}
echo ' </div>' . "\n";
?>
</table>
Try this code... hope it will resolve your issue
<table cellpadding="4" cellspacing="0" class="table1" width="100%">
<caption><h2>Leaderboard</h2></caption>
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
$playerTotals = sort2d($playerTotals, 'score', 'desc');
$j = 1;
$tmpScore = 0;
//show place #
$tieflag=false;
for($i=0; $i<=count($playerTotals)-1; $i++) {
if(($i<count($playerTotals) && $playerTotals[$i][score]==$playerTotals[$i+1][score]) || ($i>0 && $playerTotals[$i][score]==$playerTotals[$i-1][score])) $tieflag=true;
$pickRatio = $$playerTotals[$i][score] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($playerTotals[$i][score] / $possibleScoreTotal) * 100), 2) . '%';
$rowclass = ((($j - 1) % 2 == 0) ? ' class="altrow"' : '');
echo ' <tr' . $rowclass . '><td style="height: 25px;"><b>' . ($tieflag?'(t)'.$j:$j) . '</b>. ' . $playerTotals[$i][userName] . '</td><td align="center">' . $playerTotals[$i][wins] . '</td><td align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
$j++;
}
}
echo '</div>'. "\n";
?>
</table>
I'd create a new variable $placeholder. So:
if ( $i != 0 ) {
if ($tmpScore < $stats[score]) {
$tmpScore = $stats[score];
}
if ( $tmpScore == $stats[score] ) {
$placeholder = $i.'(t)';
} else if ($stats[score] < $tmpScore )
$placeholder = $++i;
}
} else {
$placeholder = $++i;
$firstScore = $stats[score];
$tmpScore = $stats[score];
}
Then instead of printing $i print $placeholder
so for the first time through you could do this in the echo:
//It makes more sense if you read it from bottom to top but I put it this way
//so you will not have to keep running through every condition when you will
//only evaluate the first condition most often
if ( $i != 0 && $i != 1 ) {
echo ;//Your normal print
} else if ( $i = 1 && $tmpScore != $firstScore ) {
echo '<b>'; //and the rest of the first line plus second line NOT a tie
} else if ( $i = 1 ) {
echo ' (t)'; //Plus the rest of your first line plus second line TIE
} else {
//This is your first time through the loop and you don't know if it's a tie yet so just
//Print placeholder and then wait to figure out the rest
echo ' <tr' . $rowclass . '><td style="height: 25px;"><b>' . $placeholder;
}
I have a script which retrieves all rows of data within a sales list (npc_sales_list) but what I am trying to do is set up a drop down menu which filters the results oand I don't know where to start as I haven't done any php in while.
The main filters I am trying to do are to see the previous month's sales only (npc_entry_date) and the sales type (npc_usertype). If someone could point me in the right direction or show me some resource links that would be great.
Im not fussed whether the filter is automatic or if you need to hit a submit button. Any suggestions welcome...
<?php
require_once ('./includes/config.inc.php');
$page_title = 'Page title';
include ('./includes/header.html');
if (!isset($_SESSION['admin_sp_id'])) {
$url = 'http://' . $_SERVER['HTTP_HOST']
. dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1);
}
$url .= '/login.php';
ob_end_clean();
header("Location: $url");
exit();
}
require_once ('database.php');
$display = 500;
if (isset($_GET['np'])) {
$num_pages = $_GET['np'];
} else {
$query = "SELECT COUNT(*) FROM npc_sales_list ORDER BY npc_entry_date DESC";
$result = #mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row[0];
if ($num_records > $display) {
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
}
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
$link1 = "{$_SERVER['PHP_SELF']}?sort=fna";
$link2 = "{$_SERVER['PHP_SELF']}?sort=lna";
if (isset($_GET['sort'])) {
switch ($_GET['sort']) {
case 'fna':
$order_by = 'sp_firstname ASC';
$link1 = "{$_SERVER['PHP_SELF']}?sort=fnd";
break;
case 'fnd':
$order_by = 'sp_firstname DESC';
$link1 = "{$_SERVER['PHP_SELF']}?sort=fna";
break;
case 'lna':
$order_by = 'sp_surname ASC';
$link2 = "{$_SERVER['PHP_SELF']}?sort=lnd";
break;
case 'lnd':
$order_by = 'sp_surname DESC';
$link2 = "{$_SERVER['PHP_SELF']}?sort=lna";
break;
default:
$order_by = 'npc_entry_date DESC';
break;
}
// $sort will be appended to the pagination links.
$sort = $_GET['sort'];
} else { // Use the default sorting order.
$order_by = 'npc_entry_date DESC';
$sort = 'drd';
}
$query = "SELECT us.sp_firstname , us.sp_surname , us.sp_amb_club_no , us.sp_position_title , us.sp_dealer_name ,
us.sp_dealer_code , us.sp_region , us.sp_department, sp_business_phone, us.sp_mobile_phone , us.sp_dealer_category, us.sp_email,
sa.npc_item_id , sa.npc_part_no, sa.npc_quantity, sa.npc_customer_name, sa.npc_registration_no , sa.npc_suo_no , sa.npc_amb_club_no , sa.npc_repair_order , sa.npc_invoice_no ,
sa.npc_entry_userdate, sa.npc_image_upload, sa.npc_usertype, sa.npc_points, sa.npc_bonus_points, sa.npc_active, sa.npc_entry_date,
DATE_FORMAT(sa.npc_entry_date, '%d-%m-%Y') AS dr , sa.sp_user_id
FROM sp_user AS us, npc_sales_list AS sa
WHERE us.sp_user_id = sa.sp_user_id
ORDER BY
$order_by LIMIT $start, $display";
$result = #mysql_query ($query);
//
// Table header.
echo '<table width="100%" cellspacing="1" cellpadding="4" style="font-size:10px;">
<tr>
<td align="center"><b>Invoice No.</b></td>
<td align="center"><b>Member ID</b></td>
<td align="center"><b>Surname</b></td>
<td align="center"><b>Part #</b></td>
<td align="center"><b>Sale Type</b></td>
<td align="center"><b>Qty</b></td>
<td align="center"><b>Invoice Date</b></td>
<td align="center"><b>Customer Rego</b></td>
<td align="center"><b>Submission Date</b></td>
<td align="center"><b>Status</b></td>
</tr>';
// Fetch and print all the records. echo '<td align="left"><strong>' . $row['sp_invoice_no'] . '</strong></td> ';
$bg = '#ffffff'; // Set the background color.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$bg = ($bg=='#eaeced' ? '#ffffff' : '#eaeced');
echo '<tr bgcolor="' . $bg . '">';
echo '<td align="center"><strong>Details</strong></td> ';
echo '<td align="center"><strong>' . $row['sp_amb_club_no'] . '</strong></td> ';
echo '<td align="center"><strong>' . $row['sp_surname'] . '</strong></td> ';
echo '<td align="center"> <strong>' . $row['npc_part_no'] . '<strong></td>';
echo '<td align="center"> ' . $row['npc_usertype'] . ' </td>';
echo '<td align="center"> ' . $row['npc_quantity'] . ' </td>';
echo '<td align="center"> ' . $row['npc_entry_userdate'] . ' </td>';
echo '<td align="center"> ' . $row['npc_registration_no'] . ' </td>';
echo '<td align="center"> ' . $row['dr'] . ' </td>';
echo '<td align="center" style="color:#5a8e22; font-weight:bold;"> ' . $row['npc_active'] . ' </td>';
echo '</tr>
';
}
echo '</table>';
mysql_free_result ($result);
mysql_close();
if ($num_pages > 1) {
echo '<br /><p>';
$current_page = ($start/$display) + 1;
if ($current_page != 1) {
echo '<a href="view-all-sales.php?s=' . ($start - $display) . '&np=' .
$num_pages . '&sort=' . $sort .'">Previous</a> ';
}
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="view-all-sales.php?s=' . (($display * ($i - 1))) .
'&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
} else {
echo $i . ' ';
}
}
if ($current_page != $num_pages) {
echo '<a href="view-all-sales.php?s=' . ($start + $display) . '&np=' .
$num_pages . '&sort=' . $sort .'">Next</a> ';
}
echo '</p>';
}
include ('./includes/footer_admin_user.html');
?>
Think I've done this completely wrong but I am trying to display the values of the items when added to the shopping cart into a table. My code looks like this:
<?php
function minicart() {
foreach($_SESSION as $name => $value) {
if ($value > 0) {
if (substr($name, 0, 5)=='cart_') {
$id = substr($name, 5, (strlen($name) -5));
$get = mysql_query('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));
while ($get_row = mysql_fetch_assoc($get)) {
$sub = $get_row['price']*$value;
'<table border = "1">'
'<tr>'
'<td>'<echo $get_row['name'].' x '.$value.' # £'.number_format($get_row['price'], 2).' = £'.number_format($sub, 2).' [-] [+] [Delete]<br />''</tr>';
'</tr>'
'</table>'
}
}
$total += $sub;
}
}
if ($total==0) {
echo "Your cart is empty";
}
else {
echo '<br />Total: £'.number_format($total, 2);
?>
Try this:
function minicart()
{
$items = 0;
$tbl = array();
foreach($_SESSION as $name => $value)
{
if ($value > 0) {
if (substr($name, 0, 5)=='cart_')
{
$id = substr($name, 5, (strlen($name) -5));
$get = mysql_query('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));
$tbl[] = '<table border="1"><thead><tr>'
. '<th>Item</th>'
. '<th>Quantity</th>'
. '<th>Unit Price</th>'
. '<th>SubTotal</th>'
. '<th>Action</th>'
. '</tr></thead><tbody>'
;
while ($get_row = mysql_fetch_assoc($get)) {
$items++;
$sub = $get_row['price'] * $value;
$tbl[] = '<tr>'
. '<td>' . $get_row['name'] . '</td>'
. '<td>' . $value . '</td>'
. '<td>£' . number_format( $get_row['price'], 2 ) . '</td>'
. '<td>$pound;' . number_format( $sub, 2) . '</td>'
. '<td>'
. ' [-] '
. ' [+] '
. ' [Delete]'
. '</td>'
. '</tr>'
;
}
$tbl[] = '</tbody>';
}
$total += $sub;
}
}
if ($items==0)
{
echo "Your cart is empty";
}
else
{
$tbl[] = '<tfoot><tr>'
. '<td colspan="3" style="text-align:right; font-weight:bold">Total:</td>'
. '<td>£' . number_format($total, 2) . '</td></tr></tfoot></table>';
echo implode( "\n", $tbl );
}
}
I changed the logic so that if the item count is zero, it displays the "empty cart" message, allowing for zero-cost items.
I tried to re write your table to correct format:
echo '<table border = "1">';
while ($get_row = mysql_fetch_assoc($get)) {
$sub = $get_row['price']*$value;
echo '
<tr>
<td>'.
$get_row['name'].' x '.$value.' # £'.number_format($get_row['price'], 2).' = £'.number_format($sub, 2).'
[-]
[+]
[Delete]<br />
</td>
</tr>
';
}
echo '</table>';
Please see PHP Strings
I think you want to replace the if-statement with the following.
This will give you 1 table with a row per item, probably what you're looking for.
if (substr($name, 0, 5)=='cart_') {
$id = substr($name, 5, (strlen($name) -5));
$get = mysql_query('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));
echo '<table border = "1">';
echo '<tr>';
while ($get_row = mysql_fetch_assoc($get)) {
$sub = $get_row['price']*$value;
echo '<td>';
echo $get_row['name'].' x '.$value.' # £';
echo number_format($get_row['price'], 2).' = £';
echo number_format($sub, 2);
echo '[-] ';
echo '[+] ';
echo '[Delete]<br />';
}
echo'</tr>';
echo'</table>';
}
I have migrated some codes, all went fine till I encountered this code in the tutorial. Because I have a custome template, the html and php code is a little different from the original template, now I'm totally lost.
This is the original code, which should be replaced with the one beneath this code:
<table cellspacing="0" cellpadding="0" border="0" class="product">
<tr>
<td width="103" height="104"><script language="javascript"><!--
document.write('<?php echo '
<a href="javascript:popupWindow(\\\'' .
tep_href_link(FILENAME_POPUP_IMAGE, 'pID=' .
$product_info['products_id']) . '\\\')">'
. tep_image(DIR_WS_IMAGES .
$product_info['products_image'], addslashes(
$product_info['products_name']),
SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="0" vspace="0"') . '</a>'; ?>');
//--></script>
<noscript>
<?php echo '<a href="' . tep_href_link(DIR_WS_IMAGES .
$product_info['products_image']) . '" target="_blank">' .
tep_image(DIR_WS_IMAGES .
$product_info['products_image'],
$product_info['products_name'],
SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="0" vspace="0"') . '</a>'; ?>
</noscript></td>
<td width="344" height="104"><br>
<br style="line-height:5px"><?php echo stripslashes(
$product_info['products_description']); ?>
<br style="line-height:1px;"><br style="line-height:5px;">
</td>
</tr>
<tr>
<td width="447" height="1" colspan="2">
<img src="images/3_line.gif" alt="" border="0"><br></td>
</tr>
<tr>
<td height="38">
<br style="line-height:12px"><script language="javascript"><!--
document.write('<?php echo '
<div style=" text-align:center; width:90%;">
<a href="javascript:popupWindow(\\\''
. tep_href_link(FILENAME_POPUP_IMAGE, 'pID=' .
$product_info['products_id']) . '\\\')">'
. TEXT_CLICK_TO_ENLARGE . '</a></div><br style="line-height:2px;">'; ?>');
//--></script>
<noscript>
<?php echo '<div style=" text-align:center; width:90%;">
<a href="' . tep_href_link(DIR_WS_IMAGES .
$product_info['products_image']) . '" target="_blank">
<br style="line-height:7px">' . TEXT_CLICK_TO_ENLARGE . '</a>
</div>
<br style="line-height:2px;">'; ?>
</noscript>
</td>
<td style=" vertical-align:middle; padding-left:20px;"><strong>
<?=$products_price?></strong><br></td>
</tr>
</table>
This is the code I had to replace with the original one (the one above this code):
<!-- Simple multi image addon -->
<div id="fancy">
<table border="0" cellspacing="0" cellpadding="2" align="right">
<tr>
<td align="center" class="smallText">
<?php
if (strlen($product_info['products_name']) >
$max_title_length)
{
$title = wordwrap(htmlspecialchars($product_info['products_name']),
$max_title_length, '<br>');
}
else
{
$title = htmlspecialchars($product_info['products_name']);
}
$m_source = '';
$thumb = (class_exists('oscthumb') && CFG_MASTER_SWITCH == 'On');
if ($thumb)
{
preg_match('/"([^"]+)"/', htmlentities(tep_image(
DIR_WS_IMAGES .
$product_info['products_image'], '', '', '', '', '', 5),
ENT_NOQUOTES), $image);
$m_source = str_replace('&', '&', $image[1]);
}
echo '<a rel="image_group" title="' . $title . '" href="' . (
$m_source ? $m_source : DIR_WS_IMAGES .
$product_info['products_image']) . '"
alt="' . $product_info['products_name'] . '" target="_blank">' .
tep_image(DIR_WS_IMAGES . $product_info['products_image'],
$product_info['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT,
'hspace="5" vspace="5"', false, 5) . '
<br /></a>';
if (!$vertical_format)
{
echo '';
$row = 1;
reset($products_image_array);
foreach ($products_image_array as $value)
{
if ($thumb)
{
$source = '';
preg_match('/"([^"]+)"/', htmlentities(
tep_image(DIR_WS_IMAGES . $value, '', '', '', '', '', 5), ENT_NOQUOTES),
$image);
$source = str_replace('&', '&', $image[1]);
}
echo '<a rel="image_group" title="' . $title . '" href="' . (
$source ? $source : DIR_WS_IMAGES . $value) . '" target="_blank">' .
tep_image(DIR_WS_IMAGES . $value, $product_info['products_name'],
TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT, 'hspace="5" vspace="5"') .
'</a>';
++$row;
if ($row > $image_group)
{
echo '<br />';
$row = 1;
}
}
}
echo '</td>';
if ($vertical_format)
{
echo '<td>';
$row = 1;
reset($products_image_array);
foreach ($products_image_array as $value)
{
if ($thumb)
{
$source = '';
preg_match('/"([^"]+)"/', htmlentities(
tep_image(DIR_WS_IMAGES . $value, '', '', '', '', '', 5),
ENT_NOQUOTES), $image);
$source = str_replace('&', '&', $image[1]);
}
echo '<a rel="image_group" title="' .
$title . '" href="' . ($source ? $source : DIR_WS_IMAGES . $value) . '"
target="_blank">' .
tep_image(DIR_WS_IMAGES . $value, $product_info['products_name'],
TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT, 'hspace="5" vspace="5"') .
'<br />' . '</a>';
++$row;
if ($row > $image_group)
{
echo '</td><td>';
$row = 1;
}
}
echo '</td>';
}
?>
</tr>
<?php
echo
'<tr><td class="smallText">' . TEXT_CLICK_TO_ENLARGE . '</td></tr>';
?>
</table>
</div>
<!-- EOF Simple multi image addon -->
This is the error it produces on my website:
Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in..
includes/functions/database.php on line 99
This is line 99
function tep_db_fetch_array($db_query) {
return mysql_fetch_array($db_query, MYSQL_ASSOC);
}
Any help would be great, excuse me for the formatting of the code, i tried to make it as good as possible, but some echo lines are to long.
Edit:
Posting here, complete database.php
<?php
/*
$Id: database.php,v 1.21 2003/06/09 21:21:59 hpdl Exp $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2003 osCommerce
Released under the GNU General Public License
*/
function tep_db_connect(
$server = DB_SERVER,
$username = DB_SERVER_USERNAME,
$password = DB_SERVER_PASSWORD,
$database = DB_DATABASE,
$link = 'db_link') {
global $$link;
if (USE_PCONNECT == 'true') {
$$link = mysql_pconnect($server, $username, $password);
} else {
$$link = mysql_connect($server, $username, $password);
}
if ($$link) mysql_select_db($database);
return $$link;
}
function tep_db_close($link = 'db_link') {
global $$link;
return mysql_close($$link);
}
function tep_db_error(
$query, $errno, $error) {
die('<font color="#000000">
<b>' . $errno . ' - ' . $error . '<br><br>' .
$query . '<br><br><small><font color="#ff0000">
[TEP STOP]</font></small><br><br></b></font>');
}
function tep_db_query($query, $link = 'db_link') {
global $$link;
if (defined('STORE_DB_TRANSACTIONS') && (
STORE_DB_TRANSACTIONS == 'true')) {
error_log('QUERY ' .
$query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
$result = mysql_query($query, $$link) or
tep_db_error($query, mysql_errno(), mysql_error());
if (defined('STORE_DB_TRANSACTIONS') && (
STORE_DB_TRANSACTIONS == 'true')) {
$result_error = mysql_error();
error_log('RESULT ' . $result . ' ' .
$result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
return $result;
}
function tep_db_perform($table, $data, $action = 'insert',
$parameters = '', $link = 'db_link') {
reset($data);
if ($action == 'insert') {
$query = 'insert into ' . $table . ' (';
while (list($columns, ) = each($data)) {
$query .= $columns . ', ';
}
$query = substr($query, 0, -2) . ') values (';
reset($data);
while (list(, $value) = each($data)) {
switch ((string)$value) {
case 'now()':
$query .= 'now(), ';
break;
case 'null':
$query .= 'null, ';
break;
default:
$query .= '\'' . tep_db_input($value) . '\', ';
break;
}
}
$query = substr($query, 0, -2) . ')';
} elseif ($action == 'update') {
$query = 'update ' . $table . ' set ';
while (list($columns, $value) = each($data)) {
switch ((string)$value) {
case 'now()':
$query .= $columns . ' = now(), ';
break;
case 'null':
$query .= $columns .= ' = null, ';
break;
default:
$query .= $columns . ' = \'' . tep_db_input($value) . '\', ';
break;
}
}
$query = substr($query, 0, -2) . ' where ' . $parameters;
}
return tep_db_query($query, $link);
}
function tep_db_fetch_array($db_query) {
line 99
return mysql_fetch_array($db_query, MYSQL_ASSOC);
}
function tep_db_num_rows($db_query) {
return mysql_num_rows($db_query);
}
function tep_db_data_seek($db_query, $row_number) {
return mysql_data_seek($db_query, $row_number);
}
function tep_db_insert_id() {
return mysql_insert_id();
}
function tep_db_free_result($db_query) {
return mysql_free_result($db_query);
}
function tep_db_fetch_fields($db_query) {
return mysql_fetch_field($db_query);
}
function tep_db_output($string) {
return htmlspecialchars($string);
}
function tep_db_input($string, $link = 'db_link') {
global $$link;
if (function_exists('mysql_real_escape_string')) {
return mysql_real_escape_string($string, $$link);
} elseif (function_exists('mysql_escape_string')) {
return mysql_escape_string($string);
}
return addslashes($string);
}
function tep_db_prepare_input($string) {
if (is_string($string)) {
return trim(tep_sanitize_string(stripslashes($string)));
} elseif (is_array($string)) {
reset($string);
while (list($key, $value) = each($string)) {
$string[$key] = tep_db_prepare_input($value);
}
return $string;
} else {
return $string;
}
}
?>
The first tep_fetch_array
// Simple multi image addon
$image_group = TINY_IMAGE_GROUP_SIZE; //Number of images to show per row/column
$vertical_format = (ADDITIONAL_IMAGE_FORMAT == 'vertical');
$max_title_length = 40; //Set the maximm length of popup titles before they are broken into multiple lines.
$product_info_query = tep_db_query("select p.products_id, pd.products_name,
pd.products_description, p.products_model, p.products_quantity, p.products_image,
p.products_image_array, pd.products_url, p.products_price,
p.products_tax_class_id, p.products_date_added,
p.products_date_available, p.manufacturers_id from "
. TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where
p.products_status = '1' and p.products_id = '" . (int)
$HTTP_GET_VARS['products_id'] . "' and
pd.products_id = p.products_id and
pd.language_id = '" . (int)$languages_id . "'");
$product_info = tep_db_fetch_array(
$product_info_query);
$products_image_array = unserialize($product_inf0
['products_image_array']);
if (!is_array($products_image_array)) $products_image_array = array();
// EOF Simple multi image addon
Given that error message, the $db_query you're passing in to the tep_db_fetch_array() is obviously not set properly. Somewhere it's getting nulled out, overwritten, referred to out of scope, or you've got a typo in a parameter somewhere.