Jump to content

maxudaskin

Members
  • Posts

    628
  • Joined

  • Last visited

Everything posted by maxudaskin

  1. You cannot use the header function after the <head> tag is placed in HTML.
  2. Hi guys, I'm still stuck on making this multi-level drop down menu, so I figure that I'll listen to how you guys would do it. I don't necessarily need any code, but just ideas on how to code it. Basically, I need it to store each item in a database. It needs to: be accessed, processed, and formatted with PHP end up returning either a multi-dimensional array, or the raw HTML. Examples: <?php array( array( 'label'=>'Test', 'link'=>'index.php?r=test', 'sort'=>0, 'children'=>array(--blah blah blah--) ), array(--blah blah blah--) ); <div id="menu"> <ul> <li><a href="index.php?r=test"><h2>Test</h2></a> <ul> <li><a href="blah">Blah</a> <ul> <li><a href="blah">Blah</a></li> </ul> </li> </ul> </li> </ul> </div> That's pretty much it. If you have any ideas or suggestions, please feel free to help me out. Thank you guys!
  3. It's not impossible! It's just that we haven't figured out how to do it right yet. I'm sure that if some professional programmer looked at this, they would know exactly how to do it.
  4. Looking at it now, I think that my pattern string is erroneous, but I guess you got that figured out Thanks for the tutorial, it's pretty cool, although, I cannot access any of those features for Google Voice with my account. I assume that it's because I live in Canada.
  5. You have to give us some code to work with. Giving us a class name does not help, unless we can actually see that class, or at least the docs for it.
  6. I'm not quite sure what you mean when you say that the query is clumbsy? It does exactly what I want it to do, and it's not going to have to change based on a user or settings because the menu will be displayed in the same order every time.
  7. I just used a short tag for the links because I didn't want to write out a full url for the example. The sql is written to draw uniform and persistent data from the database, but I forgot to include it. <?php /** * Menu Class * * This file is used to create a dynamic menu based on the user's permissions and status * @author Max Udaskin <[email protected]> * @version 1.0 * @package navigation */ /** * @ignore */ if(!defined('ALLOW_ACCESS')) { // Do not allow the file to be accessed by itself die('Restricted File.'); } require_once("Database.php"); class Menu { protected $login; protected $all_rows; protected $menu_items; protected $html = NULL; /** * The constructor * @param Login $login */ function _construct() { } /** * Get All Items * Retrieves all database menu items */ private function getAllItems() { $sql = 'SELECT * FROM `menu` ORDER BY `depth` ASC, `parent` ASC, `sort` ASC'; $database = new Database('default'); $database->connect(); $database->query($sql); $query = $database->getLastQuery(); while($row = mysql_fetch_array($query)) { $this->all_rows[] = $row; } } /* * Selects the menu items that are appropriate for the user */ private function chooseMenuItems() { $this->menu_items = $this->all_rows; } /** * Formats the menu items for the HTML output */ private function formatMenuItems() { $menu = array(); $menu_imploded = ''; for($i = 0; $i < count($this->menu_items); $i++) { if($this->menu_items[$i]['parent'] == 0) { $menu[] = $this->parseItem($this->menu_items[$i]); } else { $parent = $this->search($menu, $this->menu_items[$i]['parent']); print_r($parent); } } $menu_imploded = $this->combineMultiArray('', $menu); echo '<div id="menu">'; echo $menu_imploded; echo '</div>'; } /** * Searches an array and it's sub arrays for a defined value ($for) * @param array $array * @param mixed $for */ private function search($array, $for) { } /** * Gets the array item and returns it * @param array $arr The array to insert the child into * @param string $string The * @param array $child */ function insertIntoArray($arr, $string, $child) { preg_match_all('/\[([^\]]*)\]/', $string, $arr_matches, PREG_PATTERN_ORDER); $return = $arr; foreach($arr_matches[1] as $dimension) { $return = $return[$dimension]; } return $return; } /** * Parses HTML for the item, as an array * @param array $item */ private function parseItem($item) { if($item['parent'] == 0) { $h2_s = '<h2>'; $h2_e = '</h2>'; } else { $h2_s = ''; $h2_e = ''; } $return[0] = '<ul><li>' . $h2_s . '<a href="'; $return[0] .= $item['link'] . '">'; $return[0] .= $item['label'] . '</a>' . $h2_e; $return[1] = false; // Children $return[2] = '</li></ul>'; $return['parent'] = $item['parent']; return $return; } /** * Puts all of the HTML in the array together */ private function produceHtml() { $this->getAllItems(); $this->chooseMenuItems(); $this->formatMenuItems(); } /** * Get HTML * @return string The HTML menu */ public function getHtml() { $this->produceHtml(); return $this->html; } /** * Combine Multi Array * Takes any array of any dimension and combines it into a single string * @param unknown_type $array */ private function combineMultiArray($glue, $array) { $return = ''; foreach($array as $piece) { if(is_array($piece)) { $return .= $glue . $this->combineMultiArray($glue, $piece); } $return .= $glue . $piece; } return $return; } }
  8. Doesn't really need more colour, but it would be nice. Needs distinction between the main parts of the page (header, body, footer). That can be done with horizonal lines, colours, or even changes in text size. It's too simple and minimalistic. The use of an image for you text logo looks bad, it's not as sharp as text in HTML. As my sister always says, black and blue make a bruise. The layout does not promote flow. What I mean by this is that there is no clear way to look around the page. Here's a link to show you what I mean.
  9. Very simple to use and understand and to the point. A pretty minimalistic design that draws the attention to the "Custom Ice Bags at Low Cost" banner, which I like. It is very easy to figure out what you are selling, and ever so easy to figure out how to either purchase from you or contact you. I would give it a 10/10. Good job!
  10. +1 I'm taking a wild guess and assuming that all the information is in one database (each row is a user, and contains all of the information for that user). You can get multiple rows from a database with one query. See the following links: PHP MySQL Select - W3Schools MySQL Query Strings Tutorial - W3Schools
  11. Hi guys, I'm still not having any luck with coming up with an idea of how to make my multi-level drop down menu work with items from a database. I don't necessarily need code, but an idea of how to make it work, so any ideas are welcome. The table: Column Descriptions: id - The unique id label - The text to display link - The link to be used relation - I cannot remember why I wanted that... just disregard it parent - The parent item's id (0 for no parent) sort - A sort number for the item (ascending) active - 0 for false, 1 for true (not implemented yet, will add a WHERE `active` = 1 into the sql later) depth - How many parent items there are Now, here's what it has to do (the class): [*]Grab items from the database (sorted by depth, parent, and sort) [*]Place the children in a child array of the parents (or however it can be sorted) [*]Implode the array and turn it into an html menu with the below structure Menu HTML Structure <div id="menu"> <ul> <li><h2>Level 1 A</h2> <ul> <li><a href="?r=level2/a">Level 2 A</a> <ul> <li><a href="?r=level3/a">Level 3 A</a></li> <li><a href="?r=level3/b">Level 3 B</a></li> </ul> </li> </ul> </li> <li><a href="?r=level1/b"><h2>Level 1 B</h2></a></li> </ul> </div> And here is the code I have so far, but I can't figure out how to get the children into the parent array, or at least sort it so that I can achieve the above HTML structure. Thank you in advance for your help, and as I said above, I don't necessarily need code, but an idea of how to make it work, so any ideas are welcome.
  12. Can you give us an example of the data it's using? -- OFF TOPIC -- Also, did you hear about BF3? They made an entirely new engine (again) that allows for even more destruction in an urban area. Check it out
  13. What the amount was supposed to be for is the amount of un-obscured characters. If $amt_type is set to percentage, the function would find an actual whole number of characters that correspond to the percentage amount. Basically, if you said you wanted 50% of the characters un-obscured, and the string was twenty characters long, it would obscure 10 characters. I see that it's obscuring all the characters anyways, and I'm not too sure why, but I'll take a look at it soon.
  14. Wrong Forum.. I don't know how I messed this one up.
  15. You just have to break the loop once found. Better yet, change your SQL to get the password from the database using the username. Instead of <?php $query = "SELECT username, password FROM userTable"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $logged = (($row['username'] == $username) && ($row['password'] == $password)); if(!$logged){ echo "Sorry"; } else { echo "Good!"; } } } Do this: <?php $sql = 'SELECT `password` FROM `userTable` WHERE username = \'' . $username . '\''; $query = mysql_query($sql); if(mysql_num_rows($query) < 1) { // If there are no results found with that username, tell the user echo 'Incorrect Username'; } else { // Use and else statement so that it doesn't give errors when checking the password (no result means no password to check) $result = mysql_result($query); if($result != $password) { echo 'Incorrect Password'; } else { echo 'Login Success!'; } }
  16. No problem. I rushed it when I was at work, in between sales. When I head down to my room, I'll take another look at it and fix any errors or inconsistencies. It's about time that I give back to the PHPFreaks community.
  17. Learn something new every day +1
  18. First off, I would suggest setting an empty value to $message before your if/else statements. <?php $message = ''; Then you have to find the part of the string (x/y). Use preg_match. <?php $message = ''; $pattern = "/^\([0-9]+\/[0-9+]\)/"; if(preg_match($pattern, $sms)) { // It is a multi-part message } else { // It is not a multi-part message } Then your going to want to collect all of the messages, then sort them. I'll let you figure that out, but to append one after another is as simple as doing this. <?php $message = ''; $pattern = "/^\([0-9]+\/[0-9+]\)/"; if(preg_match($pattern, $sms)) { // It is a multi-part message $message .= $message_part; // You will have to loop to get it to continually append to the end of the string. } else { // It is not a multi-part message $message = $message_part; }
  19. You can use links with a GET value (xbox_games.php?id=1234), or if you're feeling rather adventurous, or willing to take something really advanced on, you can use AJAX. Take a look at this W3Schools tutorial for PHP. $_GET Tutorial Learn PHP (Main Page)
  20. +1 Please copy and paste the relevant code inside tags. Don't forget the opening <?php tag, or it won't highlight your code.
  21. <?php for($i=0;$i<=10;$i++){ // You have $i set to 0, going up to 10. (11 rows) echo $i; } Output: 012345678910 <?php $start = //your code here $end = //your code here $total_cnt = //your code here for($i = $start; $i <= $end;$i++){ // Now you have $i as a variable, and the end as a variable // some code here } echo "Displaying $start to $end of $total_cnt rows."; Output (assuming that start is 2, end is 17, and total count is 150: Displaying 2 to 17 of 150 rows.
  22. Try this out. I just wrote it up without testing it, so it may have some minor errors, but the idea is what you're after. <?php /** * Obscure characters in a string * * @param $string The string to be obscured * @param $amt The amount of characters to be left un-obscured * @param $amt_type The type of value that the amount is (as per $amt_types) * @return The obscured string */ function obscure($string, $amt = 2, $amt_type = 'percent', $obscure_char = '*') { if($amt_type = 'percent') { // If percentage, calculate an actual number if($amt > 100) // If the amount is greater than 100%, return all obscured $out = ''; for($i = 0; $i < strlen($string); $i++) { $out .= $obscure_char; } return $out; if ($amt < 0) // If the amount is less than 100%, return the unchanged string return $string; $amt = $amt*0.01; // Turn from percentage into decimal $amt = round(strlen($string) * $amt); // Calculate number of characters to not obscure (replace round() with floor() to round down) } else { if($amt > strlen($string)) $amt = strlen($string); } $chars = array(); // Will contain the string as separate characters $obscured = array(); // Will contain a list of which characters are already obscured for($i = 0; $i < strlen($string); $i++) { $chars[] = substr($string, $i, 1); // Split string into array } for($i = 0; $i < $amt; $i++) { // Obscure characters, but don't obscure the same one twice do { $rand = rand(0, strlen($string)); } while (array_search($rand, $obscured)); $obscured[] = $rand; $chars[$rand] = $obscure_char; } return implode('', $chars); // Convert the array back into a string } echo obscure('This is a test string', 5, 'percent');
  23. Get all of the id numbers of the results you want in an array. Use the shuffle() function and call the rows you want using their id numbers.
  24. The issue was that I was calling the first item in my database class (using mysql_fetch_array), moving the pointer to the second item.
  25. Wrong forum. Click here to goto the Javascript Programming Help Forum.
×
×
  • 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.