Jump to content

PHP doesn't link properly.


IcyPopX

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.