Need help pulling data from MySql database

First let me say that I am very new to CS-Cart. I am a new employee for a small company that took me on to work on their website.



We have been adding alot of subcategories and it has become difficult for the enduser to find exactly what they want on our site. I am trying to create a JS form in the HTML block which uses multiple drop down selection boxes to help navigate our products.



I want to pull the data from CPanel's MySql server to populate each drop down box. This way the code will not need to be updated every time a category is added in CS-Cart. I have been adding the following code to a unique html block on one of my category pages.



mysql_connect("localhost", "CPanel_username", "Cpanel_password") or die(mysql_error());
mysql_select_db("database_name") or die(mysql_error());
$data = mysql_query("SELECT * FROM cscart_categories")
or die(mysql_error());

Print "";

while($info = mysql_fetch_array( $data ))
{
Print "";
Print " ";
Print "";
}
Print "

Parent: ".$info['parent_id'] . " Id: ".$info['id_path'] . "
";
?>



After checking through multiple search engines, I cannot figure out what is wrong with the code. Perhaps I need additional syntax to run the code in the HTML block?

Don't think you can put PHP inside an html block, it gets stripped out by CS-Cart.



Others on the forum can chime in, but last I recall you cannot do this w/o hacking some core files in CS-Cart.

Couldn't you just create a new static block and put this code in there? Then you can select the static block just like you do the copyright or whatever.



Just be sure to change your config.local.php file to allow php in templates. You just have to change it from false to true.



Hope that helps,



Brandon

I'm fairly certain even if you DO do this, it wouldn't work because:[list]

[]it would be encountered at the step it is in the smarty template, so you'd need {php} blocks.

[
]it would need evaluated as it is printed from a variable, this variable would then need evaluated via php if you used the code above or with smarty's parser if you used {php} blocks

[/list]

The true proper way to do this would be create an addon.

A hackish way to do it would be to create a block type, make a block of that type, and in that block type's template file put the code in {php} brackets like so

{php}

echo “Hello world”;

{/php}



Info on {php} in smarty can be found in smarties documentation.



Additionally you will have to edit config.local.php in the cscart directoy to allow {php} tags in the templates.

Also note that the mysql api is deprecated in php and you should move on to an api for mysql that will be supported past php 5 like one of the following:

PHP: MySQLi - Manual

PHP: PDO - Manual

Truly figuring out addons is a time consuming process but you can learn a lot from copying an addon in the addons/ folder.



age_verification is a simpler one that you could copy and modify to suit your needs.



Here's the documentation on addons:

http://docs.cs-cart.com/add-on-tutorial

why woulldn't product filters do what you want. They can be sequential so that selection an item from the first populates the 2nd, etc.

[quote name='tbirnseth' timestamp='1352353212' post='148610']

why woulldn't product filters do what you want. They can be sequential so that selection an item from the first populates the 2nd, etc.

[/quote]

Yes, there are ways built into the cart he could achieve a solution but it might not be what he needs exactly or is handed by a designer. Hmmm. I think he wants a solution where just the subcategories show up as you select instead of filtering products as you go though.