-
Posts
779 -
Joined
-
Last visited
Never
Everything posted by xyn
-
I fixed it.. the regex i now use is... "/^(.*?)\{(while)\}(.*?)\{(1\|if:row=1)\}(.*?)\{(1\|endif)\}(.*?)\{(endwhile)\}(.*?)$/us";
-
First off, I would like to apologise for posting this, in the "incorrect" area, as i couldn't find the specific regex board. Secondly, I've been working on my own basic template engine, every thing has been working fine, up until i used multiple IF STATEMENTS within my html template page: The Template file: [code=php:0]<table width="600" cellspacing="0" cellpadding="0"> <tbody> {0|if:rows=0} <!-- No items in basket --> <tr class="formbg"> <td colspan="2" width="600" height="25" class="head2" style="padding-left:5px;"> There are not any products in your shopping basket! </td> </tr> {0|else} {while} {1|if:row=1} <!-- The headings for the basket table --> <tr class="formbg"> <td width="300" height="25" class="head3" style="padding-left:5px;"> Heading </td> <td width="300" height="25" class="head3"> Title </td> </tr> {1|endif} <!-- The basket items --> <tr class="formbg"> <td width="300" height="25" class="head3" style="padding-left:5px;"> - </td> <td width="300" height="25" class="head3"> - </td> </tr> {endwhile} {0|endif} </tbody> </table> [/code] Basically I can collect the table row between {0|if:rows=0} and {0|else}. I can also collect everything from {while} to {endwhile} between {0|else} and {0|endif}. However, when i try to extract the following as separate items, the regular expressions will not work... [code=php:0]{1|if:row=1} <!-- The headings for the basket table --> <tr class="formbg"> <td width="300" height="25" class="head3" style="padding-left:5px;"> Heading </td> <td width="300" height="25" class="head3"> Title </td> </tr> {1|endif} [/code] My php code: [code=php:0]function basket_checkout(){ # define smart tags $smart_tags=array( array() ); # select products in basket $cart=mysql_query("select * from `sc_cart_basket` where `sc_basket_user`='{$_SESSION[$this->c_session]}' order by `sc_basket_added` asc"); $cart_html=file_get_contents("$this->c_root/basket_checkout.inc.php"); # regular expressions $pattern_elseif_1="/^(.*?)\{(0\|if:rows=0)\}(.*?)\{(0\|else)\}(.*?)\{(0\|endif)\}(.*?)$/us"; $pattern_while="/^(.*?)\{(while)\}\{(1\|if:row=1)\}(.*?)\{(1\|endif)\}(.*?)\{(endwhile)\}(.*?)$/us"; $html_table_start=preg_replace($pattern_elseif_1, "\\1", $cart_html); # start table $html_no_rows=preg_replace($pattern_elseif_1, "\\3", $cart_html); # if no mysql rows, insert 1 table row $html_basket_while=preg_replace($pattern_elseif_1, "\\5", $cart_html); # the while loop $html_basket_itmes=preg_replace($pattern_while, "\\4", $html_basket_while); # DEBUG 1 $html_table_end=preg_replace($pattern_elseif_1, "\\7", $cart_html); # end the table (debug only) echo $html_table_start, $html_basket_itmes, $html_table_end; // --> } [/code]
-
[SOLVED] Randomly splitting form data into 2 groups
xyn replied to tomd79's topic in PHP Coding Help
Sorry, I got lost. so you want to be able to check say 10 players? and then 5 are randomly places in team A, and the other 5 are randomly placed in team B? -
[SOLVED] If Conditional's ""speach mark braces conflict?
xyn replied to yandoo's topic in PHP Coding Help
you're missing a } somewhere -
[SOLVED] Randomly splitting form data into 2 groups
xyn replied to tomd79's topic in PHP Coding Help
Ok, do you store your players in a database? and would you onyl have team A and team B? -
Well As far as i know theres only AJAX.
-
replace that with this; your code fine, but i dont understand the function business <? $host ="localhost"; $user ="ddsqladmin"; $pass ="bobo"; $data ="flory"; $connect =mysql_connect($host, $user, $pass); $database =mysql_select_db($data, $connect); if(!$connect||!$database)die("Database cannot connect..."); function makeClickableLinks($text) { $text = html_entity_decode($text); $text = " ".$text; $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '<a href="\1" target=_blank>\1[/url]', $text); $text = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '<a href="\1" target=_blank>\1[/url]', $text); $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)', '\1\2', $text); $text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})', '\1', $text); return $text; } ?>
-
my url wasnt invalid, its not hard to make an associative array :l, and thats the params sorted. but i dont care agreed.
-
I think you mean this: $result3 = mysql_query("SELECT HeaderDate FROM Headertbl"); print '<h2><select name="$HeaderDate">'; while($row2 = mysql_fetch_array($result3)) { echo "<ption value=\"{$row2['HeaderDate']}\">{$row2['HeaderDate']}</option>'; } print '</select>';
-
[SOLVED] If Conditional's ""speach mark braces conflict?
xyn replied to yandoo's topic in PHP Coding Help
<?php if (@$row_user_conditional['Access'] == "2") { echo "<img src=\"Images/Buttons/admin.png\" onclick=\"window.location.href='http://localhost/RFW/admin.php'\" width=\"100\" height=\"35\" />"; } ?> or <?php if (@$row_user_conditional['Access'] == "2") { ?> <img src="Images/Buttons/admin.png"onclick="window.location.href='http://localhost/RFW/admin.php'" width="100" height="35" /> <? } ?> -
[SOLVED] linking a file (pdf) to an article
xyn replied to anthony-needs-you's topic in PHP Coding Help
If you know the exact path of your PDF, try this? download.php header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: application/pdf"); header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); user by download.php?filename=PDF.pdf -
[SOLVED] linking a file (pdf) to an article
xyn replied to anthony-needs-you's topic in PHP Coding Help
try adding this: header('content-type','application/pdf'); -
[SOLVED] Randomly splitting form data into 2 groups
xyn replied to tomd79's topic in PHP Coding Help
Can I just ask what you're trying to archive? and what your problem is? I'll try and code you something to learn from. -
Your code does exactly what my example does, except yours uses more lines
-
ok, post the content of www/dbconnect.php here.
-
Looking at your code, and theres a seriouse SQL Injection vulnrability. your code: $sql="SELECT * FROM users WHERE usr_name='$user' and usr_pass='$pass'"; if i put a username of Admin (if your user was admin, with every power) and added ' -- i will get the following result: Anything in red, will NOT appear in your query, SELECT * FROM users WHERE usr_name='Admin' [color=red]--' and usr_pass='$pass'[/color] which will execute as... SELECT * FROM users WHERE usr_name='Admin' -- meaning a password can be avoided, giving access to anyone. As for the session problem: http://php.net/session_start
-
I would do this.. my array: <? $vars =array( 'test','ash','din' ); $url ='mypage.php?'; foreach($vars as $param => $value){ $url.="&$param=$value"; } print $url; ?>code]
-
i believe its sleep(); http://php.net/sleep
-
[SOLVED] Randomly splitting form data into 2 groups
xyn replied to tomd79's topic in PHP Coding Help
use print_r(); -
Your code needs a big change; your loop is not going to work, use this: <?php require('www/dbconnect.php'); dbconnect(); $id = $_GET['id']; $sql = mysql_query("select * from `books` where `books_id` ='$id'"); # or die ('Error : ' . mysql_error()); ?> <table border="1" cellpadding="0" cellspacing="0" class="tabel_editare"> <tr> <td class="textare_butonase">Book Title</td> <td class="textare_butonase">Book Year</td> <td class="textare_butonase">Book Author</td> </tr> <?php while($row=mysql_fetch_assoc($sql)) { ?> <tr> <td><?php echo $row['book Author']; ?></td> <td><?php echo $row['booky']; ?></td> <td><?php echo $row['title']; ?></td> </tr> <?php } ?> </table> <?php include('www/dbclose.php'); ?>
-
OK, I'll give you my database version. use MySQL. database.php <? $host ="localhost"; $user ="UserName"; $pass ="PasswordHere"; $data ="databaseHere"; $connect =mysql_connect($host, $user, $pass); $database =mysql_select_db($data, $connect); if(!$connect||!$database)die("Database cannot connect..."); ?> ajax.js function xml_request(){ var nr; if(window.XMLHttpRequest){ nr =new XMLHttpRequest(); }else if(window.ActiveXObject){ try{ nr =new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){ try{ nr =new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ nr =null; } } } return nr; } var xml =xml_request(); function changeLang(langId){ var d =new Date(); xml.open('get','ajax.php?'+d.getTime()+'&i='+langId); xml.onreadystatechange =function(){ if(xml.readyState ==4 && xml.status ==200){ window.location.reload(); } }; xml.send(null); }; ajax.php <? session_start(); $_SESSION['CountryId'] =$_GET['i']; ?> index.php <? ob_start(); session_start(); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <script type="text/javascript" src="ajax.js"></script> <? include_once 'database.php'; $lang_id =((!$_SESSION['CountryId'])?'gb':$_SESSION['CountryId']); $sql =mysql_query("select * from `website_text` where `lang_id` ='$lang_id'")or die(mysql_error()); $lang =mysql_fetch_assoc($sql); ?> <table width="100%" height="100%" cellspacing="0" cellpadding="0"> <tbody> <tr> <td align="center"> <form name="logonCode" method="post" action="index.php"> <input type="hidden" name="ref" value="<?=$_SERVER['PHP_SELF']?>" /> <table width="400" cellspacing="0" cellpadding="1"> <tbody> <tr> <td width="400" height="20" colspan="2"> <select onChange="changeLang(this.value)"> <option selected>-- Choose</option> <option value="gb">English</option> <option value="de">German</option> </select> </td> </tr> <tr> <td width="400" height="20" colspan="2"></td> </tr> <tr> <td width="400" height="20" colspan="2" align="center">Logon</td> </tr> <tr> <td width="100" height="20"><strong><?=$lang['t_username']?></strong></td> <td width="300" height="20"><input type="text" name="logon_user" value="<?=$_POST['logon_user']?>" class="textinput" /></td> </tr> <tr> <td width="100" height="20"><strong><?=$lang['t_password']?></strong></td> <td width="300" height="20"><input type="password" name="logon_pass" class="textinput" /></td> </tr> <tr> <td width="100" height="20"></td> <td width="300" height="20"><input type="submit" name="logon_go" value="Go" class="button" style="width:50px;" /></td> </tr> <tr> <td width="400" height="20" colspan="2"><a href="#"><?=$lang['t_link_1']?></a></td> </tr> </tbody> </table> </form> </td> </tr> </tbody> </table> </body> </html> <? ob_end_flush(); ?> MySQL Query (install database) CREATE TABLE IF NOT EXISTS `website_text` ( `text_id` int(11) NOT NULL auto_increment, `lang_id` varchar(5) NOT NULL, `t_username` varchar(50) NOT NULL, `t_password` varchar(50) NOT NULL, `t_link_1` varchar(150) NOT NULL, PRIMARY KEY (`text_id`), UNIQUE KEY `lang_id` (`lang_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; INSERT INTO `website_text` (`text_id`, `lang_id`, `t_username`, `t_password`, `t_link_1`) VALUES (1, 'gb', 'Username:', 'Password:', 'Forgotten Password?'), (2, 'de', 'Username:', 'Passwortt:', 'Passwortt Vergessen?');
-
the array must be defined before you try and implement it on the page...
-
I think the amount of text translation depends on how you take this task... If you want to add to your translations, or change all text in the website, a database would be recommended. However an array is better if its just odd words. 1. you could use a session, or a cookie (i recommend sessions). 2. using the country ID you could then do something like... (this is only any example.) <?php $lang =array( 'gb' => array( #english 'english','german' ), 'de' => array( #german 'englisch','deutsch' ) ); # $_SESSION['country'] is gb ?> choose a country: - <?=$lang[$_SESSION['country']][0]?> <!-- english --> - <?=$lang[$_SESSION['country']][1]?> <!-- german -->
-
this is your problem... $row=mysql_fetch_assoc($result); { $book = $row['book Author']; $book_year = $row['booky']; $title = $row['title']; } should be: while($row=mysql_fetch_assoc($result)) { $book = $row['book Author']; $book_year = $row['booky']; $title = $row['title']; }