Jump to content

AbraCadaver

Staff Alumni
  • Posts

    1,893
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by AbraCadaver

  1. Better ways to do the whole thing, but here is the easy fix: foreach ($children as $kid) { $indent = str_repeat("\t", $level+1); if(in_array($kid, $data)) { //check if this kid is also a parent echo "$indent<item text='$kid' id='$kid'>\n"; tree($kid, $level+1); echo "$indent</item>\n"; } else { //if not then it is the last echo "$indent<item text='$kid' id='$kid' />\n"; } }
  2. Not PHP, but: UPDATE `table_name` SET `count` = `count` + 1
  3. 1. Why not just shuffle() $arr instead of sorting based on your shuffled array? 2. What conditions do you have as to how to get the subset? array_slice()? function custom_array_rand($array, $seed, $num) { srand($seed); shuffle($array); srand(); //reset so other functions don't use this same seed return array_slice($array, 0, $num); } Needs error/arg checking.
  4. Unless it is more complicated than you state. I can give a custom_array_rand(), but why is it needed? $answer = 2; $array = array(1=>'something one', 2=>'something two', 3=>'something three'); $result = $array[$answer];
  5. In PHP there is function() which does what traditional functions do and what traditional procedures or sub-routines do. The normal distinction is that functions take arguments and based on those return a value. Sub-routines or procedures normally don't return a value but instead carry out an action like modifying a table or sending an email etc. In PHP functions are used for both. In VB or VBA there are functions that return a value and subs that perform an action. In MySQL I believe this is roughly the same, stored procedure vs. stored function.
  6. In some languages there are differences between functions and procedures or sub-routines, but for the most part, and in your question they are really the same. What are you trying to accomplish?
  7. I don't get it. I'ts been well over 20 years since I've seen it, and it wasn't that great, but is it the peoples names? I thought they were all just called citizen.
  8. Also, maybe consider 'lastname', 'firstname' and 'middlename' columns. Easier to concatenate those than try to guess a split on one column.
  9. After this: $csv_array = file($file); Do This: unset($csv_array[0]);
  10. I would think with this simple example: $pattern = '#linkauth=([^&]+)';
  11. It doesn't look like it, and I've never seen anything like it. Maybe search the files that are included and see if they have comments telling what class it is. Most likely someone just wrote a class wrapper for mysql functions.
  12. I'm not sure if there's really a name for it. It's just a file with variables that is included into another file that uses those variables. You could just as easily have those variables in the same file as the echo. This just makes it more flexible and possibly modular. Most likely you're running into a quoting problem. Different quotes have different rules and purposes. Check here, especially the single and double sections: http://us2.php.net/manual/en/language.types.string.php
  13. Post the stylesheet link and function (I assume JS) link. Most likely its a path problem. If you have something like this: <link rel='stylesheet' type='text/css' href='style.css' /> You probably need to change to this: 'chat/style.css' since the links are relative to the homepage from where you are doing the include. If it needs to be dynamic, then you can do something like this in the script for the chat app: $path = basename(dirname(__FILE__)); And then use the $path var in your links.
  14. Yes, to you delete one you would do: unset($datasortarray->{$_POST['city']}); //or unset($datasortarray->Sofia);
  15. //probably do this in a main file that is always included or in the file with the include set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/share/pear'); include_once('PEAR5.php');
  16. //to add or change $datasortarray->{$_POST['city']}[0] = $_POST['numbers']; $datasortarray->{$_POST['city']}[1] = $_POST['latitude']; $datasortarray->{$_POST['city']}[2] = $_POST['longitude']; //or $datasortarray->{$_POST['city']} = array($_POST['numbers'], $_POST['latitude'], $_POST['longitude']);
  17. Well it looks like the file is called PEAR.php and you are trying to include PEAR5.php. Not sure what else given the limited info.
  18. I would just use a PHP file with PHP variables or possibly an array. Include this file when you need it and use the variables as usual.
  19. If you're using goto you're doing it wrong. There are many other ways to do what you want. 1. Change your IF to do that stuff if there ARE rows 2. Instead of goto End you could just exit;
  20. Assuming your original file is called image.php and you have a column in the table called name, then something like this in another file: $result = mysql_query("SELECT id, name FROM store_image"); while($row = mysql_fetch_array($result)) { echo '<img src="image.php?id='.$row['id'].'" alt="'.$row['name'].'"><br />'; }
  21. simplexml or DOM. How about real code with specific questions.
×
×
  • 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.