Jump to content

scar5308

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

scar5308's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am trying to adapt part of a script. At present, it show the names of subcategories of items for sale but I would like it to show next to the subcategory, the number of items for sale without the visitor having to click on the link only to find there are no items in this subcategory. I have it working after a fashion but it also shows 1 item in the subcategories where there are either 0 items or 1. With the subcategories with 2 or more items there is no problem. I would like the subcategories to only show the number of items available in that subcategory if there are any, otherwise it could show either 0 or nothing. I think I should be using an array and not an if else statement as I am trying to evaluate numbers but I am not too sure. My code reads: if (num_ads == 0) /*mod to show number of items*/ echo '<a href="'.$link.'">'.$row->name. ' ('.$row-> num_ads. ' items)';'</a>'; I tried changing the if (num_ads == 0) to 1 and all the rows disappeared. I added an else statement after but just got a parse error. I would be grateful for some direction here! Thanks in advance
  2. Try looking here. [code]http://www.seochat.com/seo-tools/url-rewriting/[/code] I used it today and it works fine. Only problem; no instructions really so look here as well; [code]http://www.devarticles.com/c/a/Web-Services/Make-Dynamic-URLs-Search-Engine-Friendly/1/[/code] Hope it helps Simon
  3. In a bid to get my new site search engine friendly as the site was not being indexed properly, I have used mod_rewrite to rewrite the urls. So far, so good. However, I am having a problem with rewriting the arrays. I have written my menu items like so: [code]href="homepage-language-<?=$lang?>.html">[/code] with the original url as: [code]href="homepage.php?language=<?=$lang?>">[/code] This produces the url: [code]http://www.site.co.uk/homepage-language-en.html[/code] this works fine with a rewrite rule: [code]Options +FollowSymLinks RewriteEngine on RewriteRule homepage-language-(.*)\.html$ homepage.php?language=$1[/code] My problem is that I have a language switch using the code: [code]<select name="select" onchange="self.location='http://www.site/homepage.php?language='+this.options[this.selectedIndex].value">[/code] This allows the user to select a different language from a list. This is the part that is giving me trouble as when a different language is sellected, it produces the URL: [code]http://www.site/homepage.php?language=de[/code] How can I make it produce the URL as above?: [code]http://www.site.co.uk/homepage-language-en.html[/code] Obviously quite a simple problem with a different rewrite rule but how? Also, is there a rewrite rule that would  allow the part where 'homepage' is to allow any other page title such as contactus or bookings. or would this be a security problem? Thanks in advance
  4. OK, so trying to run before I can walk again but I learn better this way! I have a script that requires the path to a folder to be inserted on this line: [code] $config->dir    = "/home/site/public_html/folder/lang_sets/";[/code] where lang_sets is the folder name. I want to create an install script (install.php) that asks the user to input the path or can auto detect it. I also need to make the script create an array of languages the user wants to use from a dropdown list - language names and id; en, fr, de etc.These values are then written to config.php. config.php: [code]#this sets the root path to the language files   class object {};   $config = new object;   $config->dir    = "/home/site/public_html/folder/lang_sets/";   session_start();     # Create language array   $language = array("en" => "English", "de" => "German", "lv" => "Latvian", "ru" => "Russian");[/code] config.php is then included in all the page files. There is slightly more to it than this but getting an idea of how to do this will certainly help me with the rest. I haven't had much luck in trying to work this out for myself so I hope someone can help. Cheers Simon
  5. I am not a php whiz but on my site I just tried changing the line: [code]<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">[/code] to [code]<form method="post" action="different_page.php"target="_blank">[/code] Amazingly, it worked! You will need to take all the 'Thank you' code and put it on this page along with perhaps a javascript 'Close Window' behavoir I'm only looking here because I am stuck with a different problem  ;D Good luck Simon
  6. I am trying to create a multi language site which open the index page in the users' browser language but allows the user to change it if needed. My file tree is: [URL=http://www.webwhiz.co.uk/lang12/tree.gif]tree[/URL] I have the following main files: index.php and select.php Working versions at: [URL=http://webwhiz.co.uk/lang12/index.php]index.php[/URL] [URL=http://webwhiz.co.uk/lang12/select.php]select.php[/URL] They both work fine as they are. Index.php displays the correct language page, calling up the appropriate content from the language folders. select.php, displays the content according to the language selected. What I want to do, is merge the code somehow so that the user initially arrives at the page apropriate to their browser as in index.php but has the option of changing their language preference as in select.php. I like the 'on select' method used here as it keeps the interface clean. How can I get the script to redirect to for instance; http://www.webwhiz.co.uk/lang12/index.php?language=en if the user selects English from the list? The code I have so far is: index.php [CODE]<? class object {}; $config = new object; $config->dir    = "/home_path/lang12/lang_sets/"; session_start(); if (! isset($lang)) { $lang = "en"; $lang = "pt"; $lang = "sp"; $lang = "lv"; } else if ($lang == "pt-br" ) { $_SESSION["lang"] = "pt"; } else if ($lang == "en" ) { $_SESSION["lang"] = "en"; } else if ($lang == "sp" ) { $_SESSION["lang"] = "sp"; } else if ($lang == "lv" ) { $_SESSION["lang"] = "lv"; } else { $_SESSION["lang"] = "en"; } $config->global = $config->dir.$lang."/language.php"; include ($config->global); session_destroy(); ?> <?=$content1?> <?=$content3?> <?=$content2?> <?=$content4?>[/CODE] select.php: [CODE]<?php $lang = $_GET["language"]; if ($lang=="") {     $lang = 1; } ?> <select onChange="window.location='select.php?language='+this.value"> <?php $language = array(     "",     "English",     "Portuguese",     "Spanish",     "Latvian"); for ($i = 1; $i <= 4; $i++) { ?> <option value="<?=$i?>" <? if ($lang == $i) { print "SELECTED";}?>> <?=$language[$i]?></option> <? } ?> </select> <!-- content here -  Just to show it works! --> <br> <img src = " <?=$lang?>.gif"><!--posibly a flag here?--> <? include("./$lang.htm"); ?><br /> <? if ($lang==1) { ?> English <? } elseif ($lang==2) { ?> Portuguese <? } elseif ($lang==3) { ?> Spanish <? } elseif ($lang==4) { ?> Latvian <? } else ($lang==1) ?>[/CODE] I think this way would make updating and adding new files very easy as I could use a similar method for all the other pages including language specific menus and content from the other pages (I think) The typical content for the language.php file could be: lang_sets/lv/language.php [CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>webwhiz lang12 lv</title> </head> <body> <? $content3 = "text"; $content2 = " in Latvian"; $content4 = include_once("../include/footer.php"); ?> </body> </html>[/CODE] I hope you can see what I am aiming at here. It will keep file organisation simple and allow additional languages to be added easily as some of the code could be inserted as 'include' files. I a sure that once I get the answer for this step, I will hit more walls but  I am learning all the time :-) Simon
  7. Thanks for that but I am already using something similar for the initial page. What I wanted to do was; once the visitor has been directed to the page according to the $_GET[lang] I wanted to give them the option of selecting a different language. All the pages are just templates and the script calls up the various includes etc. according to the language detected from language specific include folders. I then wanted a drop down menu on the main page that would change the language include directory. I would therefore only have one set of pages with just the includes and perhaps some images changing according to the language either selected or detected. Hope that's clear :-)
  8. I am trying to set up a multi lingual web site. Currently, the following works well as a static menu but I would like to change it to a dropdown menu using if possible, the 'select onchange=' method so the user doesn't have to click on a OK or Select button. I would also like a message to appear in the drop down in its default state such as 'Select Language' I have a version at: [url=http://www.webwhiz.co.uk/lang5/langselect.php]http://www.webwhiz.co.uk/lang5/langselect.php[/url] which doesn't work either. I asked on the forum for help but nothing so far! (see Help with arrays please: [url=http://www.phpfreaks.com/forums/index.php/topic,112413.0.html]http://www.phpfreaks.com/forums/index.php/topic,112413.0.html[/url] ) I have tried to sort this out but am not really a coder. The code I have so far is: [code]<? include_once ("./setstring.inc") ?> <?= "<a href='" . $PHP_SELF . "?lang=pt-br'>Portuguese</a>" ?> | <?= "<a href='" . $PHP_SELF . "?lang=fr'>Fran&ccedil;ais</a>" ?> | <?= "<a href='" . $PHP_SELF . "?lang=en'>English</a>" ?> | <?= "<a href='" . $PHP_SELF . "?logoff=1'>Logoff</a>" ?> <? include ( setstring ( 'pt-br', './portuguese.php', 'fr', './french.php', 'en', './english.php') )?>[/code] I wouldn't mind getting either to work properly, both would be a bonus! A virtual beer is on offer for anyone who can help!
  9. I have been struggling with this problem for over a week and am not much nearer a solution. I am trying to create a multi language site that only requires the content to be added as simple text or html files although php files can be included. I have a page that detects the language used on the users browser; index.php: [code]<? class object {}; $config = new object; $config->dir    = "/home/path/public_html/language2/lang_sets/"; if (! isset($lang)) { $lang = "pt"; $lang = "en"; $lang = "lv"; } else if ($lang == "pt-br" ) { $SESSION["lang"] = "pt"; } else if ($lang == "en" ) { $SESSION["lang"] = "en"; } else if ($lang == "lv" ) { $SESSION["lang"] = "lv"; } else { $SESSION["lang"] = "en"; } $config->global = $config->dir.$lang."/language.php"; include ($config->global); ?> <html> <head> <title>webwhiz language2</title></head> <body> <?=$content4?> <?=$content1?> <?=$content2?> </body> </html>[/code] The page; language_sets/en/language.php, then includes the appropriate language specific content for my language files.[code]<? $content1 = include_once("../include/langselect.php"); $content2 = include_once("../include/contactform.php"); $content4 = include_once("../include/footer.php"); ?>[/code] I then want the option to allow the visitor to select a different language to the one detected. For this I am trying to use this snippet I found. The included file above langselect.php contains the following code: [code]<?php $language = $_GET["language"]; ?> <select onchange="window.location='select.php?language='+this.value"> <?php $language = array(     "",     "English",     "Portuguese",     "Latvian",     "Spanish"); for ($i = 1; $i <= 4; $i++) { print "<option value=$i>$language[$i]</option>"; print "<h3>Language is : $language[$i]</h3>"; } ?> </select>[/code] This provides a dropdown box to select a language. I am new to php and can't quite see how to make the above script redirect the user to a language specific page; in this case www.site.co.uk/language/index_en.php if English is selected from the dropdown. Any help would be gratefully received! Simon
×
×
  • 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.