PHP - Moved: Smarty Templates Newbie - Looping Through Images With Function
This topic has been moved to Other Libraries and Frameworks.
http://www.phpfreaks.com/forums/index.php?topic=321319.0 Similar TutorialsThis topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=357370.0 Hi I am a php learner and I am having some problems while loading images from templates. I will explain everything so hope you can understand my question.. My Folder Structure WEB SITE NAME - index.php [default landing page] + Images [images folder] + css [css folder] + templates [templates folder] |-- header.inc.php [header template] |-- footer.inc.php [footer template] + includes [folder for all classes and variables] + js [folder for all js files] + contact-us [this is a folder] |--index.php [this is the file inside the contact-us folder] + about-us [this is a folder] |-- index.php [this is the file inside the about-us folder] This is the header.inc.php file without some html markups Quote <title>Web Site Name</title> <link href="css/reset.css" rel="stylesheet" type="text/css" /> <link href="css/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script> </head> <body> <img src="images/phpmadeeasy.jpg" width="200" height="70" alt="php made easy logo" /> </body> ------------------------------------------------------------------------------ This is a sample main landing index.php page [i added codes only where i get into problems] Quote <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ As you can guess, default index.php file works fine... load both logo and banner images but... this is the index.php file located under the about-us folder Quote <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="../images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ Here only the banner image load because the template file still show the logo image path as "images/phpmadeeasy.jpg" instead of "../images/phpmadeeasy.jpg" so is there any way me to define the default image folder as a variable so i can use that variable to load images from any directory level Example: Quote <?php echo $images; ?>images/phpmadeeasy.jpg" <script type="text/javascript" src="<?php echo $js; ?>/jquery-1.4.4.min.js" <link href="<?php echo $css; ?>reset.css" rel="stylesheet" type="text/css" Thanks........... Hi I am a php learner and I am having some problems while loading images from templates. I will explain everything so hope you can understand my question.. My Folder Structure WEB SITE NAME - index.php [default landing page] + Images [images folder] + css [css folder] + templates [templates folder] |-- header.inc.php [header template] |-- footer.inc.php [footer template] + includes [folder for all classes and variables] + js [folder for all js files] + contact-us [this is a folder] |--index.php [this is the file inside the contact-us folder] + about-us [this is a folder] |-- index.php [this is the file inside the about-us folder] This is the header.inc.php file [just a example to let you understand my problem] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "URL/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="URL/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Web Site Name</title> <link href="css/reset.css" rel="stylesheet" type="text/css" /> <link href="css/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script> </head> <body> <img src="images/phpmadeeasy.jpg" width="200" height="70" alt="php made easy logo" /> </body> ------------------------------------------------------------------------------ This is a sample main landing index.php page [i added codes only where i get into problems] <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ As you can guess, default index.php file works fine... load both logo and banner images but... this is the index.php file located under the about-us folder <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="../images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ Here only the banner image load because the template file still show the logo image path as "images/phpmadeeasy.jpg" instead of "../images/phpmadeeasy.jpg" so is there any way me to define the default image folder as a variable so i can use that variable to load images from any directory level Example: <?php echo $images; ?>images/phpmadeeasy.jpg" <script type="text/javascript" src="<?php echo $js; ?>/jquery-1.4.4.min.js" <link href="<?php echo $css; ?>reset.css" rel="stylesheet" type="text/css" Thanks........... This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=355225.0 I am new to php templates and I have this simple mail function that worked until I converted to template. I am trying to accomplish a successful sendMail and redirect to the same page with a success statement. The form is set to onsubmit verify input with JavaScript. This contact page is called through a index template and is referred to as ?p=contact Here is my code. Code: [Select] $message = $_GET['usr_find']; $message .= ""; $message .= $_GET['message']; $reason = $_GET['reason']; $email = $_GET['email']; $redirect = $_GET['redirect']; $admin = "admin email address"; $bigtime = "other email"; function sendMail($reason, $email, $message, $admin, $bigtime, $headers ) { if ($reason == "feedback") { mail($admin, $reason, $message, $email); if( return true; } if ($reason == "interested") { mail($bigtime, $reason, $message, $email ); return true; } } ?> <?php function showForm(){ print <<<_HTML_ <form id="contact" enctype="text/plain" method="GET" name="contact" action="$_SERVER[PHP_SELF]" onsubmit="return validateForm()"> <input type="hidden" name="redirect" value="http://www.bigtimebordeaux.com/pgs/scrps/contact.php"> <fieldset><legend style="color: rgb(0, 0, 0)">Please use this form to Contact Us:</legend> <table class="formTable"> <tbody> <tr> <td>Your Email Address: <input size="30" name="email" type="text"></td> </tr> <tr> <td>Reason for contact: <select name="reason"> <option selected="selected" value="not_selected">-Please select one-</option> <option value="feedback">Site Feedback or Problems</option> <option value="interested">interested in Service</option> </td> </tr> <tr> <td>How did you find us: <select name="usr_find"> <option selected="selected" value="not_selected">-Please select one-</option> <option value="friend:">Reccomended by Friend</option> <option value="internetSearch:">Internet Search</option> </select> </td> </tr> <tr> <td>Your Message:<br> <textarea maxsiz="200" name="message" cols="60" rows="10" id="message"></textarea></td> </tr> <tr> <td> <input name="submit" type="submit"> </td> </tr> </tbody> </table> </fieldset> </form> _HTML_; } if (isset($_GET['submit'])) { sendMail($reason, $email, $message, $admin, $bigtime, $headers ); echo 'We have successfully recieved your mail. Thank You'; }else{ showForm(); } ?> This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319414.0 Hi I have two albums with pictures in them, what I want to know is how do I put the first image of my album next to the albums name. For example I have an album called gallery 1 and I have 2 pictures in it and before you click the link to go see those images i want the first picture to be next to gallery 1. I hope that made sense. Thank you for your help. This is the code I got so far public function home(){ $galleries_model = new galleries_model('galleries'); $galleries = $galleries_model -> get_all(); foreach($galleries as $gallery){ $sql = ("SELECT * FROM gallery_images WHERE id = gallery_id LIMIT 1"); $this->_params['list'][] = $gallery; } } } Im trying to assign and update table rows with a random 9 character string but am receiving the error : Fatal error: Cannot redeclare make_seed() (previously declared in ... How can I clear/reset the value before the next loop Code: [Select] else { while ($data=mysql_fetch_array($users)){ $user=$data[user]; $usersarray = array($users); foreach ($usersarray as $key => $u){ //clear pass $token = ""; srand(); //generate new password $password_length = 9; function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } srand(make_seed()); $alfa = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*(){}[]"; for($i = 0; $i < $password_length; $i ++) { $token .= $alfa[rand(0, strlen($alfa))]; } // insert password // setup SQL statement $SQL = " UPDATE data SET pass='$token' WHERE user='$m1' "; // execute SQL statement $makeit = mysql_db_query($userdb,"$SQL",$usercid); // check for error if (!$makeit) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=342707.0 hello, I'm a beginner when it comes to PHP: I'm working on a log in system but i keep on getting the same errors which makes my system unreliable. this is the function I'm trying to use: if(pg_numrows($q) == 1){ echo "<p>Someone took that username</p>"; include "signup.php"; exit; } --> I'm using a postgresql database this is the warning I keep on getting: Code: [Select] Warning: pg_numrows(): supplied argument is not a valid PostgreSQL result resource in /var/ftpdirs/512544/PHP/login/adduser.php on line 13 I have the same problem when I try to look if an username is taken or not... when people try to register this is my adduser.php file: <?php session_start(); include "connectie_db.php"; $User_name = $_POST['user_name'] ; $User_pass = $_POST['user_pass'] ; $User_pass2 = $_POST['user_pass2'] ; $checkUsername= "SELECT user_name from tovanu.users where user_name = '$User_name';"; $q = $db->exec($checkUsername); if(MDB2::isError($q)){ echo "code: ".$q->getUserInfo(); exit(); } if(pg_numrows($q) == 1){ echo "<p>Someone took that username</p>"; include "signup.php"; exit; } If(strlen($User_name > 32)){ echo "<p>The username is too long</p>"; include "signup.php"; exit; } if($User_pass != $User_pass2){ echo "<p>Both passwords must be the same</p>"; include "signup.php"; exit; } $password = md5($User_pass); $add = "INSERT INTO tovanu.users (user_name,user_pass,user_email,user_date,user_level,naam,adres,plaats,postcode) VALUES ('$User_name','$password','email',current_date,1,'jef','jonhstraat','maaseik','3687')"; $execute = $db->exec($add) ; if(MDB2::isError($execute)){ echo "code: ".$q->getUserInfo(); exit(); } $_SESSION['user'] = $username; include "index.php"; ?> any help would be appreciated!!!!!!!!!!! This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=308937.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=343169.0 Hello all; My site is at: http://www.designtoprint.com The problem is that it looks great in everything but Internet Explorer. In I.E., it's utterly broken. I think this has a lot to do with the fact that the former developer who worked on it did everything in Smarty. I'm wondering if there's a way to automate the process of recombining all the Smarty pages back into normal .php files. Or barring that, if any of you smarter-than-me people know off the top of your heads why my site is breaking in I.E., but nothing else. Thanks! Kyle Hello, I am trying to take a calendar script and use it on my site that uses Smarty templates. I have gotten all of it to work minus one spot! I am having trouble trying to get the code below to output what I want in Smarty... I have tried many things but to no avail! Any help would be appreciated! Thanks!! Obviously I want the html output from these PHP calls but I cant figure it out! Thanks for your help! for($i=0; $i< $total_rows; $i++) { for($j=0; $j<7;$j++) { $day++; if($day>0 && $day<=$total_days_of_current_month) { //YYYY-MM-DD date format $date_form = "$current_year/$current_month/$day"; //echo $date_form_good = '<td'; //check if the date is today if($date_form == $today) { $class_today = ' class="today"'; } //check if any event stored for the date if(array_key_exists($day,$events)) { //adding the date_has_event class to the <td> and close it $event_today = ' class="date_has_event"> '.$day; //adding the eventTitle and eventContent wrapped inside <span> & <li> to <ul> $event_title = '<div class="events"><ul>'.$events[$day].'</ul></div>'; } else { //if there is not event on that date then just close the <td> tag $no_event = '> '.$day; } $close_tag= "</td>"; } else { //showing empty cells in the first and last row $mts = '<td class="padding"> </td>'; } } $close_row = "</tr><tr>"; } Hi there, I wonder if anyone can help me. I'm trying to install smarty. The problem I'm having is in choosing the correct path directory for- require('/usr/local/lib/php/Smarty/Smarty.class.php'); Granted I am relatively new to coding. I've tried using- <?php echo $_SERVER['DOCUMENT_ROOT']; ?> which returns- /usr/local/apache/htdocs I think the problem is in understanding what my local directory is. In my ftp program, the first folder looks like this firstfolder/ public_html/ ( < I've installed smarty in this one) DO_NOT_UPLOAD_HERE.txt When I run a test file index.php, I get the following error- Warning: require() [function.require]: open_basedir restriction in effect. File(/usr/local/public_html/lib/php/Smarty/Smarty.class.php) is not within the allowed path(s): (/home/:/usr/lib/php:/tmp) in /home/a4808331/public_html/index.php on line 4 What I've put in my index.php file so far which I'm sure is wrong is- require('/usr/local/public_html/lib/php/Smarty/Smarty.class.php'); If you need more info I'd be happy to supply. Thanks in advance for your help. I have a serialized array stored in a database field in the following format: Unserialized: '1' => '5000', '2' => '2000' Serialized: a:2:{i:1;s:4:"5000";i:2;s:4:"2000";} The key is a database ID and the value is just a number. Next I have a table which stores some information about each ID |ID|NAME|DESCRIPTION|ENABLED?| ----------------------------------------------------- 1 | Test | Description goes here| TRUE 2 | Hello | World | TRUE What I want to do is fetch the serialized values from database, unserialize them and then loop through them using the smarty template engine. The thing is that I want to include some more information, that fetched from the database, based on the KEY of the array. I suck at explaining crazy stuff like this so I'll just provide some images and code to help out Current I have this PHP code ( I had no idea on how to approach the problem so I just wrote stuff I thought would work ): <?php require_once ( 'common-ingame.php' ); $template->assign ( 'page_title', 'Faction Standings' ); $unserialized = unserialize ( $characterInfo['charactersREPUTATION'] ); # IE: a:2:{i:1;s:4:"5000";i:2;s:4:"2000";} $names = array ( ); foreach ($unserialized as $faction_id => $faction_reputation) { $data = mysql_Fetch_assoc ( mysql_query ( "SELECT `worldfactionNAME` FROM `world_factions` WHERE `worldfactionID` = {$faction_id}" ) ); $names[] = $data['worldfactionNAME']; } $final_array = array_combine ( $unserialized, $names ); $template->assign ( 'reputation', $final_array ); $template->display ( 'my-rep.tpl' ); Smarty Template File . TPL Code: [Select] {include file="include/header-ingame.tpl"} <h3>Faction Standings</h3> <table class='ng-table'> <tr><th>Faction</th><th>Reputation</th></tr> {foreach from=$reputation key=faction_name item=faction_reputation} <tr><td>{$faction_reputation}</td><td>{$faction_name} / 10000</td></tr> {/foreach} </table> {include file="include/footer-ingame.tpl"} Screenshot of results is attached What I want to do is add extra information, fetched from the database, to the table. My table structu |FACTIONID|FACTION NAME|FACTION DESCRIPTION| FACTION ENABLED? ( NOT USED YET)| ----------------------------------------------------------------------------------------------------------------------- 1 Horus Brotherhood Description 1 TRUE 2 Darkmist Clan Description 2 TRUE Currently all that's being displayed is the faction name, which is selected based on the array key, and the reputation value which is fetched from the array value. What I want to do is add the description column value to the table. Anyone care to help? hey guys i have this code to grab info from database in my inv.php file
$dbConn = new DBConnection(); $i = new dbHandler($dbConn, 'inventory'); $inv = array(); $sel=mysql_query("select * from inventory"); while($row=mysql_fetch_array($sel)) { $inv[] = $row; } $smarty->assign('inventory', $inv); // Finally, display the actual page $smarty->display('InvViewAdd.tpl');How to i make it show the info on my InvViewAdd .tpl page? also if i put $inv = $i->showInv(); I am using X cart and I have tried add function that hide price until customers log in. so I added following codes to my files with notepad but I am keep getting smarty errors Error: Smarty error: [in customer/main/products_t.tpl line 161]: syntax error: 'if' statement requires arguments (Smarty_Compiler.class.php, line 1270) in /home1/lemielfa/public_html/include/lib/smarty/Smarty.class.php on line 1092 Here's Smarty.class.php line 1092 ------------------------------------------------------------------------------------------------------------------------------------- * @param string $error_msg * @param integer $error_type */ function trigger_error($error_msg, $error_type = E_USER_WARNING) { (line1092----->)trigger_error("Smarty error: $error_msg", $error_type); } /** * executes & displays the template results -------------------------------------------------------------------------------------------------------------------------------- This was my first time adding some code to my web, I hope I didn't screw up that much...... Thank You David ---------------------------------------------------------------------------------------- Following Code ADDED /b] 1. Apply following SQL statements either from your cart admin/patch area or myphpadmin. This will place 2 controls in General Settings / General options in Common options. The first one will allow you to turn this mod on/off Code: INSERT INTO `xcart_config` (`name`, `comment`, `value`, `category`, `orderby`, `type`, `defvalue`, `variants`, `validation`) VALUES ('cflsys_hide_prices', 'Hide prices for non-logged in customers (this will also hide quantity box, "buy now" and "add to cart" buttons)', 'N', 'General', 75, 'checkbox', 'N', '', ''); INSERT INTO `xcart_config` (`name`, `comment`, `value`, `category`, `orderby`, `type`, `defvalue`, `variants`, `validation`) VALUES ('cflsys_hide_prices_message', 'Show this optional message if the option "Hide prices" is enabled', 'You need to login in order to see prices and place orders.', 'General', 76, 'text', '', '', ''); 2. Add to init.php at the end of the file just before PHP Code: # # WARNING ! # Please ensure that you have no whitespaces / empty lines below this message. # Adding a whitespace or an empty line below this line will cause a PHP error. # this PHP Code: # added by CFL Systems for hide prices if customer not logged in $smarty->assign("cflsys_hide_prices",$config['General']['cflsys_hide_prices']); $smarty->assign("cflsys_hide_prices_message",$config['General']['cflsys_hide_prices_message']); # added by CFL Systems for hide prices if customer not logged in 3. In skin1/customer/main/products.tpl find Code: {if $config.Appearance.products_per_row && ($featured eq "Y" || $config.Appearance.featured_only_multicolumn eq "N")} {include file="customer/main/products_t.tpl"} {else} {include file="customer/main/products_list.tpl"} {/if}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} {if $cflsys_hide_prices_message ne ""} <div style="color: red; margin: 5px 0; padding: 5px 5px 5px 10px; border: 1px solid #cccccc;">{$cflsys_hide_prices_message}</div> {/if} {/if} {* added by CFL Systems to hide prices if customer not logged in *} 4. In skin1/customer/main/product.tpl (skin1/customer/main/product_details.tpl for 4.3.x, code may be slightly different) find this Code: <tr> <td class="property-name product-price">{$lng.lbl_price}:</td> <td class="property-value"> and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} $nbsp; {else} {* added by CFL Systems to hide prices if customer not logged in *} then find Code: {if $product.forsale ne "B"} <tr> <td colspan="2"> {include file="customer/main/product_prices.tpl"} </td> </tr> {/if}and after add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} then find Code: <tr> <td class="property-name product-input"> {$lng.lbl_quantity}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} <tr> <td colspan="2"> {if $cflsys_hide_prices_message ne ""} {$cflsys_hide_prices_message} {else} {/if} </td> </tr> {else} {* added by CFL Systems to hide prices if customer not logged in *}then find Code: {/if} </table> and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *}then find Code: {if $product.appearance.buy_now_buttons_enabled}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} $nbsp; {else} {* added by CFL Systems to hide prices if customer not logged in *}then find Code: </form>and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} 5. In skin1/customer/main/products_list.tpl find Code: {if $product.product_type eq "C"} {include file="customer/buttons/details.tpl" href=$url} {else}and after add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if $login eq "" && $cflsys_hide_prices eq "Y"} $nbsp; {else} {* added by CFL Systems to hide prices if customer not logged in *} then find Code: {/if} </div> <div class="clearing"></div>and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} 6. In skin1/customer/main/products_t.tpl find Code: <tr> {foreach from=$row item=product} {if $product} <td class="product-cell product-cell-price"> {if $product.product_type ne "C"} {if $active_modules.Subscriptions ne "" && $product.catalogprice} and before add Code: {if $login eq "" && $cflsys_hide_prices eq "Y"} <tr> <td colspan="2"> </td> </tr> {else} {* added by CFL Systems to hide prices if customer not logged in *}then find at the end of the file Code: {/foreach} </table> {/if}and before add Code: {* added by CFL Systems to hide prices if customer not logged in *} {if} {* added by CFL Systems to hide prices if customer not logged in *} |