IcyPopX Posted August 17, 2010 Author Share Posted August 17, 2010 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! Link to comment https://forums.phpfreaks.com/topic/210823-php-doesnt-link-properly/page/2/#findComment-1100321 Share on other sites More sharing options...
JonnoTheDev Posted August 17, 2010 Share Posted August 17, 2010 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. Link to comment https://forums.phpfreaks.com/topic/210823-php-doesnt-link-properly/page/2/#findComment-1100339 Share on other sites More sharing options...
IcyPopX Posted August 17, 2010 Author Share Posted August 17, 2010 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! Link to comment https://forums.phpfreaks.com/topic/210823-php-doesnt-link-properly/page/2/#findComment-1100435 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.