Jump to content

laffin

Members
  • Posts

    1,200
  • Joined

  • Last visited

Everything posted by laffin

  1. because you still need the header content type (mime) so add this to the top of file.php header('Content-type: application/pdf');
  2. in a foreach statement &$val is a reference to the the original, so any change to $val changes the original $val is not referenced, any changes to $val does not alter the original so your logic is in err as this code proves what they mean $arr = array(1,2,3,4,5) foreach($arr as $val) $val+=5; print_r($arr) foreach($arr as &$val) $val+=5; print_r($arr)
  3. thats a much simpler match string: ^\d{3,5}(\s|-)\d{3,3}(\s|-)\d{4,4}
  4. forgot long distance format in the preg, just replace the pattern with: ^(((\+|((011|00)(\s|-)))(\d{2,2})|1)(\s|-))?\d{3,3}(\s|-)\d{3,3}(\s|-)\d{4,4}$
  5. when working with regex's always important to look at how to fit the pattern Hardest part about this pattern is the initial +/011/00 country designator but i think i worked it out (but no () parens around area code for local) <?php $numbers=array( '234-567-8901', '+01 234 567 8901', '011-01-234-567-8901', '00-01-234-567-8907', '0123456789' ); foreach($numbers as $val) { echo $val . " is ". (preg_match('@^((\+|((011|00)(\s|-)))\d{2,2}(\s|-))?\d{3,3}(\s|-)\d{3,3}(\s|-)\d{4,4}$@',$val)?'':'not ') . "ok<br />\r\n"; } ?> Wow, that regex is mad looking
  6. Yes, like I said, EASIEST wud be the recursion system the closure system is optimal in such a situation but its implementation is also a lot harder to implement and maintain. if u could provide a sample of the closure system using the same system above, u will soon realize that u have to write additional code for insertion, deletion, moving. So the closure system although is optimal is performance, is not the easiest system to implement.
  7. But you are using a referance to the original array, how do you not expect it not to change. if u dont want the original to change, make a copy, and work on the copy array
  8. Thats becase the reference value isnt tied to the array $example=array(1,2,3,4,5) foreach($example as $idx=>$val) { $example[$idx]+=2; } print_r($example);
  9. Well, Method 1 provides for versatility, and working with CSV type files, u can use php functions fgetcsv[/url — Gets line from file pointer and parse for CSV fields fputcsv — Format line as CSV and write to file pointer The nice thing about CSV, is that u can import/export the data from other sources (i.e.: maitaining the database in a spreadsheet) Option 2 would be significantly faster, however u lose the flexibility of a CSV file. (U maintain data from web page) both approaches work well for small databases
  10. Just read the article, and its a nice idea However in a tree based system, storing all paths would be a nightmare to try and maintain. Reason the recursion system is simpler and easier. According to the article u wud need another table with the ancestor and descendant so that table wud get rather huge when u are involving multiple paths as in the example given. the seperate table also means that your queries will be a lot more complex as well as your coding, in order to maintain the referances. Its an interesting article tho. But I don't see them as better than a simple recursion system. House Chores -> Grocery List House Chores House Chores -> Take Out Trash House Chores -> Clean Room Grocery List Grocery List -> Eggs Grocery List -> Produce Grocery List -> Produce -> Letutce Grocery List -> Produce -> Tomato Grocery List -> Milk
  11. Easiest answer: Recursion some sample code <?php $db= array( array(1,0,'House Chores'), array(2,1,'Take Out Trash'), array(3,1,'Clean Room'), array(4,0,'Grocery List'), array(5,4,'Eggs'), array(6,4,'Produce'), array(7,6,'Lettuce'), array(8,6,'Tomato'), array(9,4,'Milk') ); function buildtree($node = null,$parent=0) { $arr=null; $idx=0; foreach($node as $leaf) { if($leaf[1]==$parent) { $arr[$idx][0]=$leaf[2]; $arr[$idx++][1]=buildtree($node,$leaf[0]); } } return $arr; } function showtree($node,$indent=0) { foreach($node as $val) { echo str_pad(' ',$indent). (is_array($val[1])?'+':'>') . "{$val[0]}<br />\r\n"; if(is_array($val[1])) showtree($val[1],$indent+2); } } $tree=buildtree($db); showtree($tree);
  12. I dont think its about clicking the image to get access, its just clicking the link on a specific page to grant access. sessions is a good way to go. although the example given by your friend is very simple u have to set the session variable in yer main page, at the very top (before the html code) <?php session_start(); $_SESSION['access']=1; ?> will get it to work, but u should read up on sessions, especially the expiry period, and session_destroy.
  13. Most PHP installs do allow for sqlite, php has sqlite 2 built in, and sqlite 3 as a pdo object. if thats still not an option, flat files altho tricky can still handle the job (Just not a huge job) only problem with both of these, is that you define yer database file, so its not a good idea to have it within a web accessable folder (if u can store it below your web/public_html folder your in the good. I have used sqlite2 in a number of projects, and I've been quite surprised by its speed, and versatility. although its not as powerful as mysql, most ppl don't need all the extras anyhow.
  14. date_default_timezone_set affects all datetime functions including mktime. so $drawT = mktime($drawH, $drawMi, 0, $drawM, $drawD, $drawY); date_default_timezone_set("Australia/Melbourne"); shud be date_default_timezone_set("Australia/Melbourne"); $drawT = mktime($drawH, $drawMi, 0, $drawM, $drawD, $drawY);
  15. I don't see $nid being defined $nid=($t=intval($_GET['nid']))>0?$t:0; // make shure we have a valid whole number if($nid) { // post news } else { echo "Oopsie no news article by that id": } without $nid being defined the logic becomes reversed of what u wanted.
  16. I think u should give thought about the design of the db before making a db that becomes inflexible later on. there is no need to store all the recipes ingredients in the same table, if u design your db for flexibility in for the long run. as most of what your asking SQL can already handle Recipe Table: id Name Description Instructions Ingredients id Name RecipeIngredients RecipeId IngredientID Amount with those 3 tables, I can do exactly wut u need all within sql
  17. it's a notice not an error. its just bringing your attention to a possible problem. the code works as it should. but BlueSky is on the right track to fix it. easiest solution is to define the post if it doesn't exist. if(!isset($_POST['type'])) $_POST['type']=NULL; at the top should do the trick.
  18. This is where preg_match can show its power Not exactly the output format you wanted, but that can always be changed. as the hard part is done <?php preg_match_all('@^([A-Z]{4,5})(?:\s+(?:\d{3,4}\s+\d{7,7}|\d{7,7}))+@m', file_get_contents('sample.data'), /* change sample.data to your data file */ $matches,PREG_SET_ORDER); foreach($matches as $val) { $val[0]=explode(' ',str_replace(array(' ',"\r","\n"),' ',$val[0])); array_shift($val[0]); $step=($val[1]=='HIGHS' || $val[1]=='LOWS')?2:1; echo "{$val[1]}: "; for($i=0;$i<count($val[0]);$i+=$step) { $lonlan=intval($val[0][$i+($step-1)]); $lon=intval(substr($lonlan,0,3))/10; $lan=intval(substr($lonlan,3))/10; echo "{$lon}, {$lan}". ($step==2?",000,1,1,{$val[0][$i]}":'') . "\r\n "; } }
  19. The easiest way, is assign them to categories. glasses can go into kitchenware or wearables, if your good with db u can make subcategories so precisision of similar items can be found easily
  20. Ignace's statement should require some clarification read[] is valid, it will just assign they key index to the next available numeric sequence. But if all the values are 1 there is no way to differentiate for which id. So u need the array to either have a unique key index or a unique value to be able to differentiate. So its a question of, How do I pass an id from multiple rows of a table. and the answer really depends on how many values are possible from the form if all the checkbox values are the same, 1 u can easily use <td align='center'><input type='checkbox' name='read[]' value='<?php print $row['id']; ?>'></td> which can be retrived with foreach($_POST['read'] as $id) echo "Read Category $id selected"; if u plan on using a variety of values than <td align='center'><input type='checkbox' name='read[<?php print $row['id']; ?>]' value='1'></td> which can be retrieved with foreach($_POST['read'] as $id=>$val) { echo "Read Category $id selected with value: '{$val}'"); } It wasnt our method, that was the intitial method you posted. So you have to rethink how you want your POST variables set in order to process them by id's instead of actions lets take a look at your form <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td> <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td> <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td> <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td> <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td> <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td> Now ask yourself, how can I deliver this content by category instead of an action. simple answer, assign actions as a value instead of a variable name <td align='center'><input type='checkbox' name='action[<?php print $row['id']; ?>][]' value='read'></td> <td align='center'><input type='checkbox' name='action[<?php print $row['id']; ?>][]' value='create'></td> <td align='center'><input type='checkbox' name='action[<?php print $row['id']; ?>][]' value='modify'></td> <td align='center'><input type='checkbox' name='action[<?php print $row['id']; ?>][]' value='attach'></td> <td align='center'><input type='checkbox' name='action[<?php print $row['id']; ?>][]' value='comment'></td> <td align='center'><input type='checkbox' name='action[<?php print $row['id']; ?>][]' value='delete'></td> Now see the difference, I categorized an action array based on the id. which contains an array of which actions were chosen. foreach($_POST['action'] as $id=>$actions) { echo "Read Category {$id} selected with actions: '"; foreach($actions as $action) echo "{$action}"; echo "<br>"; }
  21. That does show a profile page, but the url would look like http://my.domain.com/view.php?id=1 but I dont see it as a vanity url as the topic title suggests. I think a vanity url would look like this: http://my.domain.com/profile/Username which u can accomplish with a script like premiso shows to display a profile page, but instead of the id, u will be using the username. with that accomplished, you will need Apache ModRewrite in order to take the vanity url and process it into a script url if you modify the view php to handle username lookups instead of id lookups http://my.domain.com/view.php?username=Test1 you can use mod-rewrite to use a url like above with .htaccess like RewriteEngine on RewriteRule ^profile/([^/\.]+)$ view.php?username=$1 [L]
  22. if you have the above, than you should also check before the <?php opening tag, its common to see this error because of a newline or space before the <?php tag. there should be nothing in front of <?php tag, it should be the very first line, otherwise your sending out display code.
  23. Its not overcomplicated. Those solutions provide no way for cleanup, if a user doesnt logs out. This means you will have to provide cleanup code yourself which should run on a interval basis. php sessions provide for that with expiration perioids, so do coookies but cookies can be falsified. storing a sessionid in the userrecord provides authentication that the user logged in, as sessionids are approx of 26 characters in length, it provides for a decent authentication that the user logged in within the expiry period of the session. if you can show me example code of in as little code as I provided, with cleanup, I might believe that just using a db field loggedin can be simpler.
  24. problem with time, or login values, your not shure from which user its coming from, reason I suggested the session id, since session id's are pretty unique, u can say that if the sessionid matches whats in the user record, than the user is logged in already. since php handles cleanup of the sessionid, this will also nullify long standing logins (ppl who dont logout) login.php <?php session_start(); $user=array(); if(isset($_SESSION['loggedin']) // user already logged in die('Already Logged in'); /* query database for username and password */ /* assume we fetch userrecord into $user */ if(!empty($user)) { // valid user record, so login info was correct die('Invalid User/Password'); $_SESSION['loggedin']=$user['id']; $sessionid=sessionid(); mysql_query('UPDATE users SET sessionid='{$sessionid}' WHERE id={$user['id']}"; // Update user record with their session id <?php logout.php session_start(); if(isset($_SESSION['loggedin'])) { // query db for userrecord, $user holding the user record if(sessionid()==$user['sessionid']) session_destroy(); } otherpages.php <?php session_start() if(!isset($_SESSION['loggedin']) die('Must be logged in'); $sessionid=sessionid(); $user=array(); // query db to retrive userrecord, note, that the userid logged in is in $_SESSION['loggedin']) // so can do something like mysql_query("SELECT * FROM users WHERE id={$_SESSION['loggedin']} AND sessionid='{$sessionid}'"); if(empty($user)) die('Invalid authentication'); just some sample code, but should give ya a general idea.
  25. logical way: when using '/" remember the closign '/" if you look at your post, ya will see ya missed the closing quote.
×
×
  • 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.