X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Data passing between template and PHP file (https://forum.x-cart.com/showthread.php?t=44252)

AMMoyer 12-15-2008 01:00 PM

Data passing between template and PHP file
 
I hope someone can give me some direction with this. I've made a new template with three dropdowns and the bottom two need to be dynamically populated from a table I have added to the database.

tpl file
Code:

{* $Id: mmy.tpl,v 1.0.0.0 2008/12/12 07:58:28 amm Exp $ *}
{capture name=menu}
<form method="post" action="mmy.php" name="year">
<select name="year" style="width: 80%;">
<option value="" selected="selected">Select Year</option>
<option value="2009">2009
<option value="2008">2008
<option value="2007">2007
<option value="2006">2006
<option value="2005">2005
<option value="2004">2004
</select><br>
<form method="post" action="mmy.php" name="mmysearchform">
<select name="posted_data[makeid]" style="width: 80%;">
<option value="" selected="selected">Select Make</option>
</select><br>
<form method="post" action="mmy.php" name="mmysearchform">
<select name="posted_data[modelid]" style="width: 80%;">
<option value="" selected="selected">Select Model</option>
</select>
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
{/capture}
{ include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_mmy_search menu_content=$smarty.capture.menu cellpadding=$fc_cellpadding}

php file
Code:

$year    =    $_POST['year'];

if ($year){
///////////////////////////////////////////////// make query for dropdown
$query    = sprintf("SELECT DISTINCT makeid, makename FROM iemmy WHERE yearid='$year'");
$result    = @mysql_query($query);
$rowMake    = mysql_fetch_array($result);
/////////////////////////////////////////////////
}


Does the year dropdown post the result to the php file as I have it shown? I think I am missing some sort of variable declaration or something even more obvious. How do I get the resulting query back to the tpl file to fill the make dropdown? I believe I'll need to loop through the array to fill that drop down. Is this correct.

Sorry for being vague, I'm still trying to get a handle on the templates and Smarty. Thanks.

Adam

AMMoyer 12-16-2008 08:09 AM

Re: Data passing between template and PHP file
 
OK here's what I've come up with now. Still nothing. Can someone direct me to ways to troubleshoot this? I don't even know that the year is being posted to the PHP file.

from /skin/mmy.tpl
Code:

{capture name=menu}
<form method="post" action="mmy.php" name="mmysearchform">
<select name="year" style="width: 80%;">
<option value="" selected="selected">Select Year</option>
<option value="2009">2009
<option value="2008">2008
<option value="2007">2007
<option value="2006">2006
<option value="2005">2005
<option value="2004">2004
</select><br>
{section name=i loop=$makeid}
{$makeid[i].make_name}&lt;br&gt;
{/section}
<form method="post" action="mmy.php" name="year">
<select name="posted_data[makeid]" style="width: 80%;">
<option value="" selected="selected">Select Make</option>
</select><br>
<form method="post" action="mmy.php" name="mmysearchform">
<select name="posted_data[modelid]" style="width: 80%;">
<option value="" selected="selected">Select Model</option>
</select>
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
{/capture}
{ include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_mmy_search menu_content=$smarty.capture.menu cellpadding=$fc_cellpadding}


from main xcart folder:
Code:

$year    =    $_POST['year'];
///////////////////////////////////////////////// make query for dropdown
$query    = sprintf("SELECT DISTINCT makeid, makename FROM iemmy WHERE yearid='$year'");
$result    = @mysql_query($query);
$rowMake    = mysql_fetch_array($result);
/////////////////////////////////////////////////
if (mysql_num_rows ($result) &gt;= 1)
{
  $makeid = array();
  while ($rows = mysql_fetch_array ($result, MYSQL_ASSOC)) array_push ($makeid, $rows);
  $smart-&gt;assign ("makeid", $makeid);
}


Are the file locations correct? Am I missing some sort of include? Any help is greatly appreciated. Thanks.

Adam

Vetrivel 12-16-2008 09:19 AM

Re: Data passing between template and PHP file
 
use event to submit the form
something like this->
<form method="post" action="mmy.php" name="mmysearchform">
<select name="year" style="width: 80%;" onchange="javascript:document.mmysearchform.submit ();">


Quote:

Originally Posted by AMMoyer
OK here's what I've come up with now. Still nothing. Can someone direct me to ways to troubleshoot this? I don't even know that the year is being posted to the PHP file.

from /skin/mmy.tpl
Code:

{capture name=menu}
<form method="post" action="mmy.php" name="mmysearchform">
<select name="year" style="width: 80%;">
<option value="" selected="selected">Select Year</option>
<option value="2009">2009
<option value="2008">2008
<option value="2007">2007
<option value="2006">2006
<option value="2005">2005
<option value="2004">2004
</select><br>
{section name=i loop=$makeid}
{$makeid[i].make_name}&lt;br&gt;
{/section}
<form method="post" action="mmy.php" name="year">
<select name="posted_data[makeid]" style="width: 80%;">
<option value="" selected="selected">Select Make</option>
</select><br>
<form method="post" action="mmy.php" name="mmysearchform">
<select name="posted_data[modelid]" style="width: 80%;">
<option value="" selected="selected">Select Model</option>
</select>
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
{/capture}
{ include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_mmy_search menu_content=$smarty.capture.menu cellpadding=$fc_cellpadding}


from main xcart folder:
Code:

$year    =    $_POST['year'];
///////////////////////////////////////////////// make query for dropdown
$query    = sprintf("SELECT DISTINCT makeid, makename FROM iemmy WHERE yearid='$year'");
$result    = @mysql_query($query);
$rowMake    = mysql_fetch_array($result);
/////////////////////////////////////////////////
if (mysql_num_rows ($result) &gt;= 1)
{
  $makeid = array();
  while ($rows = mysql_fetch_array ($result, MYSQL_ASSOC)) array_push ($makeid, $rows);
  $smart-&gt;assign ("makeid", $makeid);
}


Are the file locations correct? Am I missing some sort of include? Any help is greatly appreciated. Thanks.

Adam


Vetrivel 12-16-2008 09:22 AM

Re: Data passing between template and PHP file
 
and try to put exit(); in php file to make sure whether the form submitted to corresponding File or not.

AMMoyer 12-17-2008 02:11 PM

Re: Data passing between template and PHP file
 
Thanks, now its sending the year to mmy.php but to no surprise it's causing an error that ends up showing the entire php file in the browser.

Can someone give me some direction on how to troubleshoot this? Any help is greatly appreciated. Thanks.

Adam

Vetrivel 12-17-2008 07:09 PM

Re: Data passing between template and PHP file
 
Hi,
Please check presence of opening and closing php tag?
and just copy and paste the error or provide the error screen shot.
Then only it is easy for us to debug.

Quote:

Originally Posted by AMMoyer
Thanks, now its sending the year to mmy.php but to no surprise it's causing an error that ends up showing the entire php file in the browser.

Can someone give me some direction on how to troubleshoot this? Any help is greatly appreciated. Thanks.

Adam


AMMoyer 12-18-2008 08:44 AM

Re: Data passing between template and PHP file
 
After implementing some of the suggestions and a couple of easy things I found this is what is happening.

php file
Code:

<?php
$year    =    $_POST['year2'];
///////////////////////////////////////////////// make query for dropdown
$query    = sprintf("SELECT DISTINCT makeid, makename FROM iemmy WHERE yearid='$year'");
$result    = @mysql_query($query);
$rowMake    = mysql_fetch_array($result);
/////////////////////////////////////////////////
if (mysql_num_rows ($result) >= 1)
{
  $makeid = array();
  while ($rows = mysql_fetch_array ($result, MYSQL_ASSOC)) array_push ($makeid, $rows);
  $smarty->assign ("makeid", $makeid);
}
?>


Is giving me:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wamp\www\xcart\mmy.php on line 6

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\wamp\www\xcart\mmy.php on line 8

Now I'm guessing query is not returning any results. Does the query automatically use the last connection to the database? Or is there something I need to change in the connection to get this to work? Thanks again.

Adam

Vetrivel 12-18-2008 09:16 AM

Re: Data passing between template and PHP file
 
1.
To establish connection just include this line
require "./auth.php";
after this <?php line.

2.If you need to get the list of makeid for this year
just use
$makelist= func_query("SELECT DISTINCT(makeid),makename FROM iemmy WHERE yearid='$year'");

So,above query will display all the makeid and makename related to your year
then use smarty like this
$smarty->assign ("makelist", $makelist);


3. in your tpl file use foreach function to list this.


Quote:

Originally Posted by AMMoyer
After implementing some of the suggestions and a couple of easy things I found this is what is happening.

php file
Code:

<?php
$year    =    $_POST['year2'];
///////////////////////////////////////////////// make query for dropdown
$query    = sprintf("SELECT DISTINCT makeid, makename FROM iemmy WHERE yearid='$year'");
$result    = @mysql_query($query);
$rowMake    = mysql_fetch_array($result);
/////////////////////////////////////////////////
if (mysql_num_rows ($result) >= 1)
{
  $makeid = array();
  while ($rows = mysql_fetch_array ($result, MYSQL_ASSOC)) array_push ($makeid, $rows);
  $smarty->assign ("makeid", $makeid);
}
?>


Is giving me:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wamp\www\xcart\mmy.php on line 6

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\wamp\www\xcart\mmy.php on line 8

Now I'm guessing query is not returning any results. Does the query automatically use the last connection to the database? Or is there something I need to change in the connection to get this to work? Thanks again.

Adam


AMMoyer 12-18-2008 12:00 PM

Re: Data passing between template and PHP file
 
So far so good. Now it seems as if the php file is working (ie no errors), but the page goes white and the URL is ...xcart/mmy.php It's like its loading a new page rather than just running the php and returning results. Here's what I have going now.

tpl
Code:

{capture name=menu}
<form method="post" action="mmy.php" name="mmysearchform">
<select name="year2" style="width: 80%;"onchange="javascript:document.mmysearchform.submit ();">
<option value="" selected="selected">Select Year</option>
<option value="2009">2009
<option value="2008">2008
<option value="2007">2007
<option value="2006">2006
<option value="2005">2005
<option value="2004">2004
</select><br>
<select name="make" style="width: 80%;"onchange="javascript:document.mmysearchform.submit ();">
<option value="" selected="selected">Select Make</option>
</select><br>
<select name="model" style="width: 80%;"onchange="javascript:document.mmysearchform.submit ();">
<option value="" selected="selected">Select Model</option>
</select>
</form>
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
{/capture}
{ include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_mmy_search menu_content=$smarty.capture.menu cellpadding=$fc_cellpadding}


php
Code:

<?php
require "./auth.php";
$year    =    $_POST['year2'];
///////////////////////////////////////////////// make query for dropdown
$query    = sprintf("SELECT DISTINCT makeid, makename FROM iemmy WHERE yearid='$year'");
$result    = @mysql_query($query);
$rowMake    = mysql_fetch_array($result);
/////////////////////////////////////////////////
if (mysql_num_rows ($result) >= 1)
{
  $makeid = array();
  while ($rows = mysql_fetch_array ($result, MYSQL_ASSOC)) array_push ($makeid, $rows);
  $smarty->assign ("makeid", $makeid);
}
?>


What I am ultimately trying to do is to pass this query back to the form in my tpl file and populate the second dropdown box with the results. I tried adding a foreach loop to the tpl file to see the array, but the browser screen still went white.

I'm extremely grateful for your help. Thanks again.

Adam

Vetrivel 12-18-2008 07:07 PM

Re: Data passing between template and PHP file
 
ok..
you need to tell your system that which tpl need to display.
For that
add this in your php file:
$smarty->assign ("main", "anynewnamehere");
add the below line in skin1/common_templetes.tpl before "else" condition

{elseif $main eq "anynewnamehere"}
{include file="your tpl name goes here"}



Quote:

Originally Posted by AMMoyer
So far so good. Now it seems as if the php file is working (ie no errors), but the page goes white and the URL is ...xcart/mmy.php It's like its loading a new page rather than just running the php and returning results. Here's what I have going now.

tpl
Code:

{capture name=menu}
<form method="post" action="mmy.php" name="mmysearchform">
<select name="year2" style="width: 80%;"onchange="javascript:document.mmysearchform.submit ();">
<option value="" selected="selected">Select Year</option>
<option value="2009">2009
<option value="2008">2008
<option value="2007">2007
<option value="2006">2006
<option value="2005">2005
<option value="2004">2004
</select><br>
<select name="make" style="width: 80%;"onchange="javascript:document.mmysearchform.submit ();">
<option value="" selected="selected">Select Make</option>
</select><br>
<select name="model" style="width: 80%;"onchange="javascript:document.mmysearchform.submit ();">
<option value="" selected="selected">Select Model</option>
</select>
</form>
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
{/capture}
{ include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_mmy_search menu_content=$smarty.capture.menu cellpadding=$fc_cellpadding}


php
Code:

<?php
require "./auth.php";
$year    =    $_POST['year2'];
///////////////////////////////////////////////// make query for dropdown
$query    = sprintf("SELECT DISTINCT makeid, makename FROM iemmy WHERE yearid='$year'");
$result    = @mysql_query($query);
$rowMake    = mysql_fetch_array($result);
/////////////////////////////////////////////////
if (mysql_num_rows ($result) >= 1)
{
  $makeid = array();
  while ($rows = mysql_fetch_array ($result, MYSQL_ASSOC)) array_push ($makeid, $rows);
  $smarty->assign ("makeid", $makeid);
}
?>


What I am ultimately trying to do is to pass this query back to the form in my tpl file and populate the second dropdown box with the results. I tried adding a foreach loop to the tpl file to see the array, but the browser screen still went white.

I'm extremely grateful for your help. Thanks again.

Adam


AMMoyer 12-19-2008 10:15 AM

Re: Data passing between template and PHP file
 
I've tried the suggestions and it still responds the same. These are the two versions of the line I tried in the PHP file:

$smarty->assign ("main", "newname");
and
$smarty->assign ("main", $newname);

but neither seemed to do the trick. I also added the elseif statement to the file mentioned. Could there be another file that I need to use the elseif statement in or is this the only one?

Thanks again.
Adam

Vetrivel 12-19-2008 10:35 AM

Re: Data passing between template and PHP file
 
What you added in the common_templetes.tpl .Can you post it here.So i can able to identify where the problem is.
Quote:

Originally Posted by AMMoyer
I've tried the suggestions and it still responds the same. These are the two versions of the line I tried in the PHP file:

$smarty->assign ("main", "newname");
and
$smarty->assign ("main", $newname);

but neither seemed to do the trick. I also added the elseif statement to the file mentioned. Could there be another file that I need to use the elseif statement in or is this the only one?

Thanks again.
Adam


AMMoyer 12-19-2008 10:46 AM

Re: Data passing between template and PHP file
 
Here's what I added to common_templates.tpl:

Code:

{* $Id: common_templates.tpl,v 1.46.2.7 2007/03/28 12:48:59 twice Exp $ *}
{if $main eq "last_admin"}
{include file="main/error_last_admin.tpl"}

{elseif $main eq "iesearch"}
{include file="mmy.tpl"}

{elseif $main eq "product_disabled"}
{include file="main/error_product_disabled.tpl"}
........


And the line I currently have in my PHP file is

$smarty->assign("main", $iesearch);

My tpl file is in the skin1 folder while the php file is in the root xcart folder. Is this the issue? I really do appreciate the help

Adam

Vetrivel 12-19-2008 10:50 AM

Re: Data passing between template and PHP file
 
Add this instead of yours in the php file.
$smarty->assign("main", "iesearch");
This line is used to say, what tpl need to be used for this particular php file.
check it now.

Quote:

Originally Posted by AMMoyer
Here's what I added to common_templates.tpl:

Code:

{* $Id: common_templates.tpl,v 1.46.2.7 2007/03/28 12:48:59 twice Exp $ *}
{if $main eq "last_admin"}
{include file="main/error_last_admin.tpl"}

{elseif $main eq "iesearch"}
{include file="mmy.tpl"}

{elseif $main eq "product_disabled"}
{include file="main/error_product_disabled.tpl"}
........


And the line I currently have in my PHP file is

$smarty->assign("main", $iesearch);

My tpl file is in the skin1 folder while the php file is in the root xcart folder. Is this the issue? I really do appreciate the help

Adam


AMMoyer 12-19-2008 12:20 PM

Re: Data passing between template and PHP file
 
This is the php file as it is now. The page still goes white and stays at ...xcart/mmy.php Is there some sort of conflict between the two $smarty->assign statements at the end? I am trying to pass the array from $rowMake into smarty and the back to mmy.tpl Thanks again.

Adam

Code:

<?php
require "./auth.php";
$year    =    $_POST['year2'];
///////////////////////////////////////////////// make query for dropdown
$query    = sprintf("SELECT DISTINCT makeid, makename FROM iemmy WHERE yearid='$year'");
$result    = @mysql_query($query);
$rowMake    = mysql_fetch_array($result);
/////////////////////////////////////////////////
//do {
//echo $rowMake['makeid'];
//echo $rowMake['makename']."<br>";
//}while ($rowMake = mysql_fetch_array($result));

if (mysql_num_rows ($result) >= 1)
{
  $makeid = array();
  while ($rows = mysql_fetch_array ($result, MYSQL_ASSOC)) array_push ($makeid, $rows);
  $smarty->assign("makeid", $makeid);
}
$smarty->assign("main", "iesearch");
?>


Vetrivel 12-19-2008 07:54 PM

Re: Data passing between template and PHP file
 
Hi ,
I forgot to tell you one thing .
Add this two lines at the end of the mmy.php page (before the closing php tags.)
$smarty->assign("location", $location);
func_display("customer/home.tpl",$smarty);

Quote:

Originally Posted by AMMoyer
This is the php file as it is now. The page still goes white and stays at ...xcart/mmy.php Is there some sort of conflict between the two $smarty->assign statements at the end? I am trying to pass the array from $rowMake into smarty and the back to mmy.tpl Thanks again.

Adam

Code:

<?php
require "./auth.php";
$year    =    $_POST['year2'];
///////////////////////////////////////////////// make query for dropdown
$query    = sprintf("SELECT DISTINCT makeid, makename FROM iemmy WHERE yearid='$year'");
$result    = @mysql_query($query);
$rowMake    = mysql_fetch_array($result);
/////////////////////////////////////////////////
//do {
//echo $rowMake['makeid'];
//echo $rowMake['makename']."<br>";
//}while ($rowMake = mysql_fetch_array($result));

if (mysql_num_rows ($result) >= 1)
{
  $makeid = array();
  while ($rows = mysql_fetch_array ($result, MYSQL_ASSOC)) array_push ($makeid, $rows);
  $smarty->assign("makeid", $makeid);
}
$smarty->assign("main", "iesearch");
?>



AMMoyer 12-22-2008 01:52 PM

Re: Data passing between template and PHP file
 
Ok, now I get back to the initial page, sort of. I end up at mmy.php when I'd like to be back at home.php but I'm not too concerned with this at this time. I'm not getting the data from query back to my second dropdown box. Not sure what I've done. The query does work, I can echo it back out in the php file, just can't get the transfer complete.

tpl:
Code:

{* $Id: mmy.tpl,v 1.0.0.0 2008/12/12 07:58:28 amm Exp $ *}
{capture name=menu}
<form method="post" action="mmy.php" name="mmysearchform">
<select name="year2" style="width: 80%;"onchange="javascript:document.mmysearchform.submit ();">
<option value="" selected="selected">Select Year</option>
<option value="2009">2009
<option value="2008">2008
<option value="2007">2007
<option value="2006">2006
<option value="2005">2005
<option value="2004">2004
</select><br>
<select name="make" style="width: 80%;"onchange="javascript:document.mmysearchform.submit ();">
<option value"" selected="selected">Select Make</option>
{foreach item=row from=$row}
<option value="{$row.makeid}">{$row.makename}</option>
{/foreach}
</select><br>
<select name="model" style="width: 80%;"onchange="javascript:document.mmysearchform.submit ();">
<option value="" selected="selected">Select Model</option>
</select>
</form>
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
<font class="CategoriesList"><a href="home.php?cat=" class="VertMenuItems"></a></font><br />
{/capture}
{ include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_mmy_search menu_content=$smarty.capture.menu cellpadding=$fc_cellpadding}


php:
Code:

<?php
require "./auth.php";
$year    =    $_POST['year2'];
///////////////////////////////////////////////// make query for dropdown
$query    = sprintf("SELECT DISTINCT makeid, makename FROM iemmy WHERE yearid='$year'");
$result    = @mysql_query($query);
$rowMake    = mysql_fetch_array($result);
/////////////////////////////////////////////////
//do {
//echo $rowMake['makeid'];
//echo $rowMake['makename']."<br>";
//}while ($rowMake = mysql_fetch_array($result));

if (mysql_num_rows ($result) >= 1)
{
  $makeid = array();
  while ($rows = mysql_fetch_array ($result, MYSQL_ASSOC)) array_push ($makeid, $rows);
  $smarty->assign("makeid", $makeid);
}
$smarty->assign("main", "iesearch");
$smarty->assign("location", $location);
func_display("customer/home.tpl",$smarty);
?>


Thanks again for the help.

Adam


All times are GMT -8. The time now is 09:59 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.