laffin
Members-
Posts
1,200 -
Joined
-
Last visited
Everything posted by laffin
-
Regex not working, noone in regex forums... need help badly
laffin replied to spikeon's topic in PHP Coding Help
use the preg_match to grab everything than use explode to seperate the listing based on the comma, is simpler if(preg_match('<td class="TextResultsRowValue">(.*)</td>',$str,$matches)) $list=explode(',',$matches[1]) -
its all in the checking.... first check is Games. if u dun have a Game, than display the games list if(!isset($game)) { foreach($games as $key => $game) echo "<A HREF=?game=$key>$key</A>&NBSP;"; } else if(isset($game_array['Consoles']) && !isset($console) { // display Console list foreach($game_array['Consoles'] as $console) echo "<A HREF=?game=$game&console=$console>$console</A>&NBSP;"; } else if(!isset($diff)) { // Display Difficulty levels if(isset($console)) $cd="&console=$console"; // Do we have console set? if so set up parameter else $cd=''; // otherwise leave parameter empty foreach($game_array['Diff'] as $diff) echo "<A HREF=?game=$game$cd&diff=$diff>$diff</A>&NBSP;"; } else { We have our necessary parameters display the info // Whatever info echo out } note: on the 2nd else if, since this parameter is optional we do 2 checks, one if it's in the game_array, and the other if the parameter has been set. also u want to set $game from the previous post if(array_key_exists($_GET['game'],$games)) // we are in 1st level checking { $game=$_GET['game']; $game_array=$games[$_GET['game']];
-
Thats the question u shud have been focusing on, instead of asking generic questions. Get as specific as possible U wud want to use an array/mysql for the input validations. a very simple structure wud be $games = array ( 'Game1' => array ( 'Consoles' => array ('Ps2','XBOX','PSP'), 'Diff' => array ('Easy','Medium','Hard') ), 'Game2' => array ( 'Diff' => array ('Easy','Medium','Hard') ) ) u do your verifications either by walking the array, against the $_GET values if(isset($_GET['game'])) { if(array_key_exists($_GET['game'],$games)) // we are in 1st level checking { $game_array=$games[$_GET['game']]; // 2nd lvl checking - 1st check for consoles if(isset($game_array['Consoles'] && isset($_GET['console'])) { if(in_array($_GET['console'],$game_array['Consoles'])) { // we got a valid console $console=$_GET['console']; } } if(isset($game_array['Diff'] && isset($_GET['diff'])) { if(in_array($_GET['diff'],$game_array['Diff'])) { // we got a valid difficulty $diff=$_GET['diff']; } } } } so now u can build a url like http://my.site.com?game=xxx&console=xbox&diff=hard this is a simple example, u will need more checking for console setting if it exists prior to setting the diff setting
-
Uhm, i'm still lost. LOL. Since very little is on the scoring system itself.
-
it's prolly in yer mysql use urlencode on the href link and htmlentities on the text portion of the link
-
To me that page looks like it relies more on a DB for information than it does on php calculations. so plan and organize yer data layout first.
-
first u shud think how parameters shud be passed, and verified. do they all need to exist, or are u building them from previous sessions. than test those parameters and validate them.
-
i just use $order[] leaving the key index field blank, assigns it as next available index.
-
[SOLVED] faking referer - without using meta refresh
laffin replied to hidd3n's topic in PHP Coding Help
wud be nice if u had a page verification system. but i wud set it within yer script as an array of valid pages instead of fetching the page from the site. -
[SOLVED] faking referer - without using meta refresh
laffin replied to hidd3n's topic in PHP Coding Help
nope, use a get parameter. but if u have pathinfo enabled, than ya can do all sorts of neat things -
Working with an option/select box is same as working with checkboxes just define the name with the array square brackets. here is a sample I use to demonstrate (modified with select/option) <?php if($_SERVER['REQUEST_METHOD']=='POST') { if(isset($_POST['cb'])) { $cb=implode(',',$_POST['cb']); } echo "cb = '$cb'<BR>"; if(isset($_POST['sb'])) { $sb=implode(',',$_POST['sb']); } echo "sb = '$sb'<BR>"; } ?> <form method="POST"> <select name="sb[]" multiple="true"> <option value="0">Zero</option> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> </select> 0<INPUT TYPE='checkbox' name='cb[]' value='0'> 1<INPUT TYPE='checkbox' name='cb[]' value='1'> 2<INPUT TYPE='checkbox' name='cb[]' value='2'> 3<INPUT TYPE='checkbox' name='cb[]' value='3'> 4<INPUT TYPE='checkbox' name='cb[]' value='4'> <INPUT type="submit"> </FORM>
-
[SOLVED] faking referer - without using meta refresh
laffin replied to hidd3n's topic in PHP Coding Help
and u may check $_SERVER['HTTP_REFERRER'] to see from which site a user is coming from, or use a $_GET parameter on the redirection -
and how do u differentiate a name from a city? and how do u concatenate a 2+ word name/city?
-
Its more a question of DB Design and PHP integration, this can be done without Javascript/Ajax (But using Ajax will prevent page refreshes) As for the pages from the website, it's all the same script but some pages have 2 paramaters and others have 3. Is very vague. PHP is all about being dynamic content. I think u shud start with the tutorials on PHP and start learning. U will soon get to the MySQL and GET/POST features. it all depends on yer current level of programming with php.
-
I think the logic shud be if (!(file_exists($html_file) && ((filemtime($html_file) + ($cache_reload_seconds - 90)) < time()) )) { if(file_exists($html_file)) unlink($html_file); $test = write_to_html($html_file); } file exists and time less than expiry (which in case we dun want to do anything) which wud be a valid, hey we got our cache and it hasnt expired but the ! in front of the conditionals make it everything else
-
$photographer=mysql_result($result,$i,"photographer"); u never define $i. I think it shud be 0 (return row 0).
-
Came up with this one. using preg_match. also added a simple scoring system, which than sorts the matches by score. <?php $list=array('pink blackberry','blackberry case','pink blackberry case','blackberry phone','blackberry 8800 pink','headset case'); $search=array('pink','case'); function rsearch($list,$keys) { $scores=array(); foreach($keys as $term) { $term=preg_quote($term,'/'); foreach($list as $key=>$slist) { $score=(preg_match("/^$term\$/i",$slist)*1000) + // complete match highest score (preg_match("/\b$term\b/i",$slist)*100) + // Within search list, Med Score preg_match("/$term/i",$slist); // compounded search term, low score if($score) $scores[$key]+=$score; } } $keys=array_keys($scores); $items=count($keys); for($i=0;$i<($items-1);$i++) { for($j=1;$j<$items;$j++) { if($scores[$keys[$i]]<$scores[$keys[$j]]) $keys[$j] ^= $keys[$i] ^= $keys[$j] ^= $keys[i]; } } foreach($keys as $key) $matches[]=$list[$key]; return $matches; } header('Content-type: text/plain'); print_r(rsearch($list,$search)); ?> U can prolly add a lot more to the scoring system. maybe adding weights to the search terms position.
-
or assign a by reference function function swap(&$a,&$b) { $a~=$b; $b~=$a; $a~=$b; } $a1 = 15; $a2 = 75; swap($a1,$a2); echo "$a1,$a2";
-
time of day sorting problem please help!!!!!!
laffin replied to shooff2332's topic in PHP Coding Help
since int and char are seperated, i wud guess it wud be yer merging or sorting algorithm i wud either make it 24 hr designation (am/pm extracted from the time instead) this cud save a lot of time than switching everything over to timestamps but timestamps wud provide better flexibility when doing sql searches -
Star Rating Script.... anyone know one that can do this...?
laffin replied to Alexhoward's topic in PHP Coding Help
I wud skip the id and have it link_id user_id rating with the link_id and user_id as primary keys. it does have the potential of getting huge, however sql is a database, driven for large amounts of data. the average can be done thru mysql as well SELECT link_id,AVG(rating) as avg_rating FROM ratings GROUP BY link_id -
[SOLVED] Adding <b> tags to $str, where $str is seperated by linebreaks
laffin replied to Dale_G's topic in PHP Coding Help
Hmm, this almost does what I'm trying to do, except it turns. One. Two. Into... <B>One. </B> <B> </B> <B>Two.</B> Where it should be. <b>One.</b> <b>Two.</b> Not shure which php version u are using, but I get the output u expected, not the one u say u got. add_format function returns <B>$str</B> or an empty line if $str is empty, so there is no newline in between the <B> tags the first thing it does, is explode on newlines, so there is no newlines in the array. then it adds the <B> Tags to each array line if necessary (no newlines added). then after this is done, it concats the array adding the newlines, thus the tags are on the same line so either, u didnt test the code, or u got a messed up php installation. -
[SOLVED] Adding <b> tags to $str, where $str is seperated by linebreaks
laffin replied to Dale_G's topic in PHP Coding Help
<?php function add_format($str) { return (!empty($str)?"<B>$str</B>":''); } $str="Oh, hey everyone! What's up?\nThis is a news article.\n\nI like it very much! Lol. =)"; $lines=implode("\n",array_map('add_format',explode("\n",$str))); header('Content-type: text/plain'); echo $lines; ?> -
MM_redirectLoginSuccess = "list.php?user=$row_rsUsers[username]"; that is if u dun have any special chars in the username otherwise use MM_redirectLoginSuccess = "list.php?user=". urlencode($row_rsUsers[username]);
-
is there a way to calculate how many mysql queries on a php page?
laffin replied to Fog Juice's topic in PHP Coding Help
u replace the main queries with your own; function mysqlquery($sql) { global $sqlcounter; $sqlcounter++; return mysql_query($sql); } add a timer routine to time the execution of the page