Jump to content

Recommended Posts

problem solved with this script.

<?php
include "includes/common.php";


$result = mysql_query("SELECT * FROM tab_product WHERE prod_id='".mysql_real_escape_string($_GET['id'])."'") or die(mysql_error());


while ($row = mysql_fetch_assoc($result)) {
        $products[] = $row;
}


$objSmarty->assign("det", $products);
$objSmarty->assign("IncludeTemplate","view_car.tpl");
$objSmarty->display("pagetemplateautomobile.tpl")
?>

 

Thanks for everyone's help!

This is totally incorrect.

Since you are only selecting one car, there should not be any loops at all, both in your php file view_car.php & template file view_car.tpl. Loops are used when there are many rows returned, i.e If you selected all cars from the database.

 

See the following & read the comments!

 

view_car.php

<?php
include("includes/common.php");
/*
select the single car that the user has clicked on
*/
$result      = mysql_query("SELECT * FROM tab_product WHERE prod_id='".mysql_real_escape_string($_GET['id'])."'");
$thisProduct = mysql_fetch_assoc($result);
/*
assign the car data to the smarty variable $product
*/
$objSmarty->assign("product",$thisProduct);
$objSmarty->assign("IncludeTemplate","view_car.tpl");
$objSmarty->display("pagetemplateautomobile.tpl")
?>

 

view_car.tpl (this is an example. I do not know your database field names)

<div>
<h1>{$product.name}</h1>
</div>

 

There should be no {section} / {foreach} elements within the template. You only have 1 piece of data!

 

Note: When you are querying the database always test your SQL either directly using the mysql command line or through a database admin tool such as phpMyAdmin. You can see the number of results that are supposed to be returned and how to handle the data.

This is totally incorrect.

Since you are only selecting one car, there should not be any loops at all, both in your php file view_car.php & template file view_car.tpl. Loops are used when there are many rows returned, i.e If you selected all cars from the database.

 

See the following & read the comments!

 

view_car.php

<?php
include("includes/common.php");
/*
select the single car that the user has clicked on
*/
$result      = mysql_query("SELECT * FROM tab_product WHERE prod_id='".mysql_real_escape_string($_GET['id'])."'");
$thisProduct = mysql_fetch_assoc($result);
/*
assign the car data to the smarty variable $product
*/
$objSmarty->assign("product",$thisProduct);
$objSmarty->assign("IncludeTemplate","view_car.tpl");
$objSmarty->display("pagetemplateautomobile.tpl")
?>

 

view_car.tpl (this is an example. I do not know your database field names)

<div>
<h1>{$product.name}</h1>
</div>

 

There should be no {section} / {foreach} elements within the template. You only have 1 piece of data!

 

Note: When you are querying the database always test your SQL either directly using the mysql command line or through a database admin tool such as phpMyAdmin. You can see the number of results that are supposed to be returned and how to handle the data.

 

Okay, thanks for all the advise and explanation!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.