Modulentwicklung: Shopping Card

matt.loker
Beiträge: 203
Registriert: Mo 7. Mai 2007, 09:05
Kontaktdaten:

Modulentwicklung: Shopping Card

Beitrag von matt.loker »

Hallo zusammen,
ich versuche gerade die Shopping Card aus diesem Tutorial (http://www.qualitycodes.com/tutorial.php?articleid=25) in ein Modul zu packen.
Ich bin erst bei der Products-Seite und kommt nicht weiter - hoffe Ihr könnt mir helfen.

Die Testdaten die ich versuche auszulesen liegen in der sc_products

Code: Alles auswählen

INSERT INTO `sc_products` (`serial`, `name`, `description`, `price`, `picture`) VALUES
(1, 'View Sonic LCD', '19" View Sonic Black LCD, with 10 months warranty', 250, 'upload/shop/lcd.jpg'),
(2, 'IBM CDROM Drive', 'IBM CDROM Drive', 80, 'images/cdrom-drive.jpg'),
(3, 'Laptop Charger', 'Dell Laptop Charger with 6 months warranty', 50, 'upload/shop/charger.jpg'),
(4, 'Seagate Hard Drive', '80 GB Seagate Hard Drive in 10 months warranty', 40, 'upload/shop/hard-drive.jpg'),
(5, 'Atech Mouse', 'Black colored laser mouse. No warranty', 5, 'upload/shop/mouse.jpg'),
(6, 'Nokia 5800', 'Nokia 5800 XpressMusic is a mobile device with 3.2" widescreen display brings photos, video clips and web content to life', 299, 'upload/shop/mobile.jpg');
Ich habe versucht das ganze mit Templates aufzubauen also habe ich folgende Templates erstellt:
SC-Products_container.html

Code: Alles auswählen

<table border="0" cellpadding="0" width="100%">
    {items}
</table>
SC-Products_items.html

Code: Alles auswählen

        <tr>
            <td>{IMG}</td>
            <td>    <b>{NAME}</b><br />
                    {DESCRIPTION}<br />
                    {PRICE}:<big style="color:green">
                        {CURRENCY}{PRICE-DEC}</big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart({SERIAL})" />
            </td>
        </tr>
        <tr><td colspan="2"><hr size="1" /></td></tr>
Das Modul das die Daten aus der Datenbank lesen und in die Tempaltes packen soll sieht bis jetzt so aus und geht nicht :( - ich habe mir das aus verschiedenen Modul zusammengebaut auf Grund mangelnden Wissens.

Code: Alles auswählen

<?php
#Includes
cInclude('classes', 'SC.functions.php');

//check if there is a template instance
if (!is_object($tpl)) {
    $tpl = new Template;
}

// reset template object
$tpl->reset();
$limit = 20;
// build shopping card
$sql = "SELECT * FROM sc_products";
$db->query($sql);
if ($db->next_record()) {
    $picture = $db->f('picture');
    $name = $db->f('name');
    $description = $db->f('description');
    $price = $db->f('price');
    $serial = $db->f('serial');
}
var_dump($count);
if($db->num_rows() > 0) {
    $count = $db->num_rows();
	var_dump($count);
    if ($count > 0) {
         if (is_numeric($limit) AND strlen($limit) > 0) {
                if ($limit < $list->count) {
                    $limit_art = $limit;
                } else {
                    $limit_art = $list->count;
                }
            } else {
                $limit_art = $list->count;
            }
        for ($i = 0; $i < $limit_art; $i ++) {
            $tpl->set('d', 'IMG', $picture);
            $tpl->set('d', 'NAME', $name);
            $tpl->set('d', 'DESCRIPTION', $description);
            $tpl->set('d', 'PRICE', mi18n("Preis"));
            $tpl->set('d', 'CURRENCY', mi18n("€"));
            $tpl->set('d', 'PRICE-DEC', $price);
            $tpl->set('d', 'SERIAL', $serial);
            $tpl->next();
            }
        $sItems = $tpl->generate('templates/SC-Products_items.html', true, false);
        $tpl->reset();
        $tpl->set('s', 'items', $sItems);
        $tpl->generate('templates/SC-Products_container.html');
        }
    }
?>
das Ergebnis sieht das leider wie folgt aus: Die Templates werden angesteuert aber die Platzhalter nicht ausgetauscht und eigentlich sollte die Darstellung so aussehen wie im Tutorialbeispiel (http://www.qualitycodes.com/tutorials/d ... oducts.php)

Code: Alles auswählen

<table border="0" cellpadding="0" width="100%">
            <tr>
            <td>{IMG}</td>
            <td>    <b>{NAME}</b><br />
                    {DESCRIPTION}<br />

                    {PRICE}:<big style="color:green">
                        {CURRENCY}{PRICE-DEC}</big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart({SERIAL})" />
            </td>
        </tr>
        <tr><td colspan="2"><hr size="1" /></td></tr>
</table>
Könnt Ihr mir weiterhelfen das Modul irgendwie laufen zu lassen - wär euch super Dankbar!

die SC.functions.php die dort included wird sieht wie folgt aus

Code: Alles auswählen

<?
	function get_product_name($pid){
		$result=mysql_query("select name from sc_products where serial=$pid");
		$row=mysql_fetch_array($result);
		return $row['name'];
	}
	function get_price($pid){
		$result=mysql_query("select price from sc_products where serial=$pid");
		$row=mysql_fetch_array($result);
		return $row['price'];
	}
	function remove_product($pid){
		$pid=intval($pid);
		$max=count($_SESSION['cart']);
		for($i=0;$i<$max;$i++){
			if($pid==$_SESSION['cart'][$i]['productid']){
				unset($_SESSION['cart'][$i]);
				break;
			}
		}
		$_SESSION['cart']=array_values($_SESSION['cart']);
	}
	function get_order_total(){
		$max=count($_SESSION['cart']);
		$sum=0;
		for($i=0;$i<$max;$i++){
			$pid=$_SESSION['cart'][$i]['productid'];
			$q=$_SESSION['cart'][$i]['qty'];
			$price=get_price($pid);
			$sum+=$price*$q;
		}
		return $sum;
	}
	function addtocart($pid,$q){
		if($pid<1 or $q<1) return;
		
		if(is_array($_SESSION['cart'])){
			if(product_exists($pid)) return;
			$max=count($_SESSION['cart']);
			$_SESSION['cart'][$max]['productid']=$pid;
			$_SESSION['cart'][$max]['qty']=$q;
		}
		else{
			$_SESSION['cart']=array();
			$_SESSION['cart'][0]['productid']=$pid;
			$_SESSION['cart'][0]['qty']=$q;
		}
	}
	function product_exists($pid){
		$pid=intval($pid);
		$max=count($_SESSION['cart']);
		$flag=0;
		for($i=0;$i<$max;$i++){
			if($pid==$_SESSION['cart'][$i]['productid']){
				$flag=1;
				break;
			}
		}
		return $flag;
	}

?>
BagHira
Beiträge: 486
Registriert: Do 23. Feb 2006, 19:42
Wohnort: Tirschenreuth / Oberpfalz / Bayern
Kontaktdaten:

Re: Modulentwicklung: Shopping Card

Beitrag von BagHira »

Servus matt.loker,

ich hab das jetzt erst mal nicht nachgebaut.
Aufgefallen ist mir aber, das du die $_SESSION verwendest. Ich hatte bei einem anderen Modul tierische Probleme etwas in der $_SESSION zu speichern. Vielleicht hilft dir ja das hier ein wenig weiter - auf jeden Fall würde ich nicht die $_SESSION verwenden um Daten / Arrays zu speichern.

http://forum.contenido.org/viewtopic.ph ... 5&p=132869
Gruß Holger

Träumer haben vielleicht keinen Plan, aber Realisten haben keine Vision.

Handgewickelte Glasperlen Facebook Google+
_wiewo_
Beiträge: 358
Registriert: Mo 8. Sep 2008, 11:12

Re: Modulentwicklung: Shopping Card

Beitrag von _wiewo_ »

matt.loker hat geschrieben: SC-Products_items.html

Code: Alles auswählen

        <tr>
            <td>{IMG}</td>
            <td>    <b>{NAME}</b><br />
                    {DESCRIPTION}<br />
                    {PRICE}:<big style="color:green">
                        {CURRENCY}{PRICE-DEC}</big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart({SERIAL})" />
            </td>
        </tr>
        <tr><td colspan="2"><hr size="1" /></td></tr>
da fehlt doch das <!--BEGIN:BLOCK--> und <!--END:BLOCK--> :)
_wiewo_
Beiträge: 358
Registriert: Mo 8. Sep 2008, 11:12

Re: Modulentwicklung: Shopping Card

Beitrag von _wiewo_ »

Code: Alles auswählen

if($db->num_rows() > 0) {
    $count = $db->num_rows();
   var_dump($count);
    if ($count > 0) {
ähm, erst guckst du obs über 0 ist, wenn ja guckst du nochmal ob es über null ist :)

Code: Alles auswählen

$iCount = $db->num_rows();
if ($iCount > 0) {
dürfte reichen ;)
matt.loker
Beiträge: 203
Registriert: Mo 7. Mai 2007, 09:05
Kontaktdaten:

Re: Modulentwicklung: Shopping Card

Beitrag von matt.loker »

Code: Alles auswählen

<?php
#Includes
cInclude('classes', 'SC.functions.php');

//check if there is a template instance
if (!is_object($tpl)) {
    $tpl = new Template;
}

// reset template object
$tpl->reset();
$limit = 20;
// build shopping card
$sql = "SELECT * FROM sc_products";
$db->query($sql);
if ($db->next_record()) {
    $picture = $db->f('picture');
    $name = $db->f('name');
    $description = $db->f('description');
    $price = $db->f('price');
    $serial = $db->f('serial');
}
$iCount = $db->num_rows();
if ($iCount > 0) {
         if (is_numeric($limit) AND strlen($limit) > 0) {
                if ($limit < $list->count) {
                    $limit_art = $limit;
                } else {
                    $limit_art = $list->count;
                }
            } else {
                $limit_art = $list->count;
            }
        for ($i = 0; $i < $limit_art; $i ++) {
            $tpl->set('d', 'IMG', $picture);
            $tpl->set('d', 'NAME', $name);
            $tpl->set('d', 'DESCRIPTION', $description);
            $tpl->set('d', 'PRICE', mi18n("Preis"));
            $tpl->set('d', 'CURRENCY', mi18n("€"));
            $tpl->set('d', 'PRICE-DEC', $price);
            $tpl->set('d', 'SERIAL', $serial);
            $tpl->next();
            }
        $sItems = $tpl->generate('templates/SC-Products_items.html', true, false);
        $tpl->reset();
        $tpl->set('s', 'items', $sItems);
        $tpl->generate('templates/SC-Products_container.html');
        }

?>
Hab die Blockanreisungen ins Template eingesetzt und den Code des Moduls mit deinem Tip korrigiert - jetzt bekomme ich keine Anzeige der Platzhalter mehr was ja gut ist weil da etwas passiert - nur nicht das was ich will. :D

Wobei - Wenn er zu mindestens die For-Schleife korrekt durchlaufen würde (auch wenn er keine Daten hätte die er den Platzhaltern geben würde) müsste er doch das Template SC-Products_items.html durchlaufen und die HTML-Inhalte anzeigen. Dann hätte ich zwar keine Daten aber ich würde wissen dass die Schleife korrekt funktioniert - und das tut sie anscheinend nicht:(
Zuletzt geändert von matt.loker am Sa 17. Okt 2009, 15:45, insgesamt 1-mal geändert.
_wiewo_
Beiträge: 358
Registriert: Mo 8. Sep 2008, 11:12

Re: Modulentwicklung: Shopping Card

Beitrag von _wiewo_ »

Code: Alles auswählen

<?php
#Includes
cInclude('classes', 'SC.functions.php');

//check if there is a template instance
if (!is_object($tpl)) {
    $tpl = new Template;
}

// reset template object
$tpl->reset();
$limit = 20;
// build shopping card
$sql = "SELECT * FROM sc_products";
$db->query($sql);

while($db->next_record()) {
    $picture = $db->f('picture');
    $name = $db->f('name');
    $description = $db->f('description');
    $price = $db->f('price');
    $serial = $db->f('serial');

         if (is_numeric($limit) AND strlen($limit) > 0) {
                if ($limit < $list->count) {
                    $limit_art = $limit;
                } else {
                    $limit_art = $list->count;
                }
            } else {
                $limit_art = $list->count;
            }
        for ($i = 0; $i < $limit_art; $i ++) {
            $tpl->set('d', 'IMG', $picture);
            $tpl->set('d', 'NAME', $name);
            $tpl->set('d', 'DESCRIPTION', $description);
            $tpl->set('d', 'PRICE', mi18n("Preis"));
            $tpl->set('d', 'CURRENCY', mi18n("€"));
            $tpl->set('d', 'PRICE-DEC', $price);
            $tpl->set('d', 'SERIAL', $serial);
            $tpl->next();
            }
        $sItems = $tpl->generate('templates/SC-Products_items.html', true, false);
        }
$tpl->reset();
$tpl->set('s', 'items', $sItems);
$tpl->generate('templates/SC-Products_container.html');
?>
sollte klappen

EDIT
ne halt, hä? was gehtn da in dem script ab... ähm, wasn durcheinander, geb mir mal eben 5min ;)
Zuletzt geändert von _wiewo_ am Sa 17. Okt 2009, 15:43, insgesamt 1-mal geändert.
idea-tec
Beiträge: 1242
Registriert: Do 19. Sep 2002, 14:41
Wohnort: Dichtelbach
Kontaktdaten:

Re: Modulentwicklung: Shopping Card

Beitrag von idea-tec »

Code: Alles auswählen

<?php
#Includes
cInclude('classes', 'SC.functions.php');

//check if there is a template instance
if (!is_object($tpl)) {
    $tpl = new Template;
}

// reset template object
$tpl->reset();
$limit = 20;
// build shopping card
$sql = "SELECT * FROM sc_products limit 0,20";
$db->query($sql);
if ($db->next_record()) {
    $picture = $db->f('picture');
    $name = $db->f('name');
    $description = $db->f('description');
    $price = $db->f('price');
    $serial = $db->f('serial');
            $tpl->set('d', 'IMG', $picture);
            $tpl->set('d', 'NAME', $name);
            $tpl->set('d', 'DESCRIPTION', $description);
            $tpl->set('d', 'PRICE', mi18n("Preis"));
            $tpl->set('d', 'CURRENCY', mi18n("€"));
            $tpl->set('d', 'PRICE-DEC', $price);
            $tpl->set('d', 'SERIAL', $serial);
            $tpl->next();
 }
        $sItems = $tpl->generate('templates/SC-Products_items.html', true, false);
        $tpl->set('s', 'items', $sItems);
        $tpl->generate('templates/SC-Products_container.html');

?>
Zuletzt geändert von idea-tec am Sa 17. Okt 2009, 15:51, insgesamt 4-mal geändert.
MfG, Karsten
Nicht Können bedeutet nicht, dass man etwas nicht beherrscht, sondern lediglich, dass man sich nicht traut es zu tun ;-)
| Internet | Ihr Logo deutschlandweit auf T-Shirts |
Diplomatie: Jemanden so in die Hölle zu schicken, dass er sich auf die Reise freut!!! ;-)
_wiewo_
Beiträge: 358
Registriert: Mo 8. Sep 2008, 11:12

Re: Modulentwicklung: Shopping Card

Beitrag von _wiewo_ »

Code: Alles auswählen

<?php
#Includes
cInclude('classes', 'SC.functions.php');

//check if there is a template instance
(!isset($tpl) ? $tpl = new Template() : $tpl->reset());

// set Limit
$limit = 20;
$i       = 1;

// build shopping card
$db->query("SELECT * FROM sc_products");

while($db->next_record() && $i <= $limit) {
    $picture = $db->f('picture');
    $name = $db->f('name');
    $description = $db->f('description');
    $price = $db->f('price');
    $serial = $db->f('serial');

    $tpl->set('d', 'IMG', $picture);
    $tpl->set('d', 'NAME', $name);
    $tpl->set('d', 'DESCRIPTION', $description);
    $tpl->set('d', 'PRICE', mi18n("Preis"));
    $tpl->set('d', 'CURRENCY', mi18n("€"));
    $tpl->set('d', 'PRICE-DEC', $price);
    $tpl->set('d', 'SERIAL', $serial);
    $tpl->next();
    $i++;
}

$sItems = $tpl->generate('templates/SC-Products_items.html', true, false);
$tpl->reset();
$tpl->set('s', 'items', $sItems);
$tpl->generate('templates/SC-Products_container.html');
?>
idea-tec
Beiträge: 1242
Registriert: Do 19. Sep 2002, 14:41
Wohnort: Dichtelbach
Kontaktdaten:

Re: Modulentwicklung: Shopping Card

Beitrag von idea-tec »

jo ... so sind es 2 passende lösungen, wobei die hier super-schlank ist:

Code: Alles auswählen

<?php
#Includes
cInclude('classes', 'SC.functions.php');

//check if there is a template instance
if (!is_object($tpl)) {
    $tpl = new Template;
}

// reset template object
$tpl->reset();
// build shopping card
$db->query("SELECT * FROM sc_products limit 0,20");
while ($db->next_record()) {
            $tpl->set('d', 'IMG', $db->f('picture'));
            $tpl->set('d', 'NAME', $db->f('name'));
            $tpl->set('d', 'DESCRIPTION', $db->f('description'));
            $tpl->set('d', 'PRICE', mi18n("Preis"));
            $tpl->set('d', 'CURRENCY', mi18n("€"));
            $tpl->set('d', 'PRICE-DEC', $db->f('price'));
            $tpl->set('d', 'SERIAL', $db->f('serial'));
            $tpl->next();
 }
$sItems = $tpl->generate('templates/SC-Products_items.html', true, false);
$tpl->set('s', 'items', $sItems);
$tpl->generate('templates/SC-Products_container.html');
?>
Zuletzt geändert von idea-tec am Sa 17. Okt 2009, 15:55, insgesamt 1-mal geändert.
MfG, Karsten
Nicht Können bedeutet nicht, dass man etwas nicht beherrscht, sondern lediglich, dass man sich nicht traut es zu tun ;-)
| Internet | Ihr Logo deutschlandweit auf T-Shirts |
Diplomatie: Jemanden so in die Hölle zu schicken, dass er sich auf die Reise freut!!! ;-)
_wiewo_
Beiträge: 358
Registriert: Mo 8. Sep 2008, 11:12

Re: Modulentwicklung: Shopping Card

Beitrag von _wiewo_ »

idea-tec hat geschrieben:jo ... so sind es 2 passende lösungen, wobei die hier super-schlank ist:

Code: Alles auswählen

<?php
#Includes
cInclude('classes', 'SC.functions.php');

//check if there is a template instance
if (!is_object($tpl)) {
    $tpl = new Template;
}

// reset template object
$tpl->reset();
$limit = 20;
// build shopping card
$sql = "SELECT * FROM sc_products limit 0,20";
$db->query($sql);
while ($db->next_record()) {
            $tpl->set('d', 'IMG', $db->f('picture'));
            $tpl->set('d', 'NAME', $db->f('name'));
            $tpl->set('d', 'DESCRIPTION', $db->f('description'));
            $tpl->set('d', 'PRICE', mi18n("Preis"));
            $tpl->set('d', 'CURRENCY', mi18n("€"));
            $tpl->set('d', 'PRICE-DEC', $db->f('price'));
            $tpl->set('d', 'SERIAL', $db->f('serial'));
            $tpl->next();
 }
$sItems = $tpl->generate('templates/SC-Products_items.html', true, false);
$tpl->set('s', 'items', $sItems);
$tpl->generate('templates/SC-Products_container.html');
?>

Code: Alles auswählen

$sql = "SELECT * FROM sc_products limit 0, $limit";
wenn schon denn schon, gefällt mir sogar besser, ist resourcenfreundlicher und schneller, hab den query garnö angeguckt weil die schleifen im original mich so irritiert haben oO
matt.loker
Beiträge: 203
Registriert: Mo 7. Mai 2007, 09:05
Kontaktdaten:

Re: Modulentwicklung: Shopping Card

Beitrag von matt.loker »

Hey - super nett von euch, dass ihr mir unter die Arme greift - würde sonst nicht weiter kommen. Ich versuche gleich mal eure Tipps aus

Das ist übrigends das UR-Script aus dem ich dieses 1. von 3 Modulen aufbaue

Code: Alles auswählen

<?
	include("includes/db.php");
	include("includes/functions.php");
	
	if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){
		$pid=$_REQUEST['productid'];
		addtocart($pid,1);
		header("location:shoppingcart.php");
		exit();
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Products</title>
<script language="javascript">
	function addtocart(pid){
		document.form1.productid.value=pid;
		document.form1.command.value='add';
		document.form1.submit();
	}
</script>
</head>


<body>
<form name="form1">
	<input type="hidden" name="productid" />
    <input type="hidden" name="command" />
</form>
<div align="center">
	<h1 align="center">Products</h1>
	<table border="0" cellpadding="2px" width="600px">
		<?
			$result=mysql_query("select * from products");
			while($row=mysql_fetch_array($result)){
		?>
    	<tr>
        	<td><img src="<?=$row['picture']?>" /></td>
            <td>   	<b><?=$row['name']?></b><br />
            		<?=$row['description']?><br />
                    Price:<big style="color:green">
                    	$<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['serial']?>)" />
			</td>
		</tr>
        <tr><td colspan="2"><hr size="1" /></td>
        <? } ?>
    </table>
</div>
</body>
</html>
idea-tec
Beiträge: 1242
Registriert: Do 19. Sep 2002, 14:41
Wohnort: Dichtelbach
Kontaktdaten:

Re: Modulentwicklung: Shopping Card

Beitrag von idea-tec »

wenn wir schon klugscheißen wollen, Christian, dann machen wir es gleich so:

Code: Alles auswählen

getEffectiveSetting('shoppingcart', 'limit',20
was dann so gehen sollte (ungetestet):

Code: Alles auswählen

<?php
#Includes
cInclude('classes', 'SC.functions.php');

//check if there is a template instance
if (!is_object($tpl)) {
    $tpl = new Template;
}

// reset template object
$tpl->reset();
// build shopping card
$db->query("SELECT * FROM sc_products limit 0,".getEffectiveSetting('shoppingcart', 'limit',20));
while ($db->next_record()) {
            $tpl->set('d', 'IMG', $db->f('picture'));
            $tpl->set('d', 'NAME', $db->f('name'));
            $tpl->set('d', 'DESCRIPTION', $db->f('description'));
            $tpl->set('d', 'PRICE', mi18n("Preis"));
            $tpl->set('d', 'CURRENCY', mi18n("€"));
            $tpl->set('d', 'PRICE-DEC', $db->f('price'));
            $tpl->set('d', 'SERIAL', $db->f('serial'));
            $tpl->next();
}
$sItems = $tpl->generate('templates/SC-Products_items.html', true, false);
$tpl->set('s', 'items', $sItems);
$tpl->generate('templates/SC-Products_container.html');
?>
dann ist es wenigstens über Contenido-Einstellungen veränderbar, und ich muss nicht ins Modul
MfG, Karsten
Nicht Können bedeutet nicht, dass man etwas nicht beherrscht, sondern lediglich, dass man sich nicht traut es zu tun ;-)
| Internet | Ihr Logo deutschlandweit auf T-Shirts |
Diplomatie: Jemanden so in die Hölle zu schicken, dass er sich auf die Reise freut!!! ;-)
matt.loker
Beiträge: 203
Registriert: Mo 7. Mai 2007, 09:05
Kontaktdaten:

Re: Modulentwicklung: Shopping Card

Beitrag von matt.loker »

_wiewo_ hat geschrieben:
idea-tec hat geschrieben:jo ... so sind es 2 passende lösungen, wobei die hier super-schlank ist:

Code: Alles auswählen

<?php
#Includes
cInclude('classes', 'SC.functions.php');

//check if there is a template instance
if (!is_object($tpl)) {
    $tpl = new Template;
}

// reset template object
$tpl->reset();
$limit = 20;
// build shopping card
$sql = "SELECT * FROM sc_products limit 0,20";
$db->query($sql);
while ($db->next_record()) {
            $tpl->set('d', 'IMG', $db->f('picture'));
            $tpl->set('d', 'NAME', $db->f('name'));
            $tpl->set('d', 'DESCRIPTION', $db->f('description'));
            $tpl->set('d', 'PRICE', mi18n("Preis"));
            $tpl->set('d', 'CURRENCY', mi18n("€"));
            $tpl->set('d', 'PRICE-DEC', $db->f('price'));
            $tpl->set('d', 'SERIAL', $db->f('serial'));
            $tpl->next();
 }
$sItems = $tpl->generate('templates/SC-Products_items.html', true, false);
$tpl->set('s', 'items', $sItems);
$tpl->generate('templates/SC-Products_container.html');
?>

Code: Alles auswählen

$sql = "SELECT * FROM sc_products limit 0, $limit";
wenn schon denn schon, gefällt mir sogar besser, ist resourcenfreundlicher und schneller, hab den query garnö angeguckt weil die schleifen im original mich so irritiert haben oO
SUUUPER - hat wunberbar geklappt - hat das Limit auch rausgenommen - das habe ich nur reingemacht um meine For-Schleife zu begrenzen und das brauch ich bei deiner Lösung nicht :)
Vielen Dank!!!!!!!!!!!!!!!!!!!
idea-tec
Beiträge: 1242
Registriert: Do 19. Sep 2002, 14:41
Wohnort: Dichtelbach
Kontaktdaten:

Re: Modulentwicklung: Shopping Card

Beitrag von idea-tec »

Christian,
kannst du mir erkären, wieso es ressourcenfreundlicher sein soll, wenn ich 1 Zeile mehr im Modul habe, mir damit mehr Code in der DB steht und ich nur 2 Zeilen auseinander den gleichen wert habe?
so, ist es am schnellsten und vom Code her am kompaktesten:

Code: Alles auswählen

<?php
#Includes
cInclude('classes', 'SC.functions.php');

//check if there is a template instance
if (!is_object($tpl)) {
    $tpl = new Template;
}

// reset template object
$tpl->reset();
// build shopping card
$db->query("SELECT * FROM sc_products limit 0,".getEffectiveSetting('shoppingcart', 'limit',20));
while ($db->next_record()) {
            $tpl->set('d', 'IMG', $db->f('picture'));
            $tpl->set('d', 'NAME', $db->f('name'));
            $tpl->set('d', 'DESCRIPTION', $db->f('description'));
            $tpl->set('d', 'PRICE', mi18n("Preis"));
            $tpl->set('d', 'CURRENCY', mi18n("€"));
            $tpl->set('d', 'PRICE-DEC', $db->f('price'));
            $tpl->set('d', 'SERIAL', $db->f('serial'));
            $tpl->next();
}
$sItems = $tpl->generate('templates/SC-Products_items.html', true, false);
$tpl->set('s', 'items', $sItems);
$tpl->generate('templates/SC-Products_container.html');
?>
wobei hier natürlich varianten drin sind:

Code: Alles auswählen

$db->query("SELECT * FROM sc_products");

Code: Alles auswählen

$db->query("SELECT * FROM sc_products limit 0,20");
Wahrscheinlich sehe ich es einfach nicht, an welcher stelle die obere Variante von Christian ressourcenfreundlicher ist, bin für jeden tipp dankbar :-)
MfG, Karsten
Nicht Können bedeutet nicht, dass man etwas nicht beherrscht, sondern lediglich, dass man sich nicht traut es zu tun ;-)
| Internet | Ihr Logo deutschlandweit auf T-Shirts |
Diplomatie: Jemanden so in die Hölle zu schicken, dass er sich auf die Reise freut!!! ;-)
_wiewo_
Beiträge: 358
Registriert: Mo 8. Sep 2008, 11:12

Re: Modulentwicklung: Shopping Card

Beitrag von _wiewo_ »

ich meinte doch das es per sql query am resourcenfreundlichsten ist :)
Gesperrt