Jump to content

Fergusfer

Members
  • Posts

    40
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Fergusfer's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The recursion here is simply that the function has calls to itself. It allows it to climb up the generational tree without requiring any idea of how far it needs to go. That's correct. I chose to use nullity to indicate a condition where there is no ID. If every dragon has parents, there will be an infinite number of dragons, and in that scenario it is impossible to recur through or display the entire tree. Well, for a start, we need to know what sort of database you are using. MySQL is a popular database server for use in PHP development. You need to review the documentation of the mysqli extension paying particular attention to connection, querying, and fetching arrays from a result set.
  2. Indeed. Do not mix mysqli and mysql. They are different extensions.
  3. This warning reveals that the connection is not being created using the credentials you intend. For example, "www-data" is the Apache process. This is the user that would be used to connect if no user were specified. $user is not initialized correctly. Since your server is reporting the problem at line 3 and there is no connect statement at line 3 in the code you show us, I also conclude that the code you posted is not the code you are using. That makes it very hard to help you. Check the initialization of $user. Check the other variables $host, $pass, and $db. If $user is not initialized, the others may not be either.
  4. You are discussing a sort of recursion then. Recursion is the act of a function calling itself. It is most often applicable to, surprise, recursive structures. It isn't necessarily the fastest approach, and it can have difficulty with scalability. Here's an example: <?php $selectedDragon = 5; $dragons = array( 1 => array('mom' => null, 'dad' => null), 2 => array('mom' => null, 'dad' => null), 3 => array('mom' => null, 'dad' => null), 4 => array('mom' => 1, 'dad' => 2), 5 => array('mom' => 4, 'dad' => 3) ); ?> <h1>Lineage of Dragon <?=$selectedDragon ?></h1> <table> <tr> <th>Dragon</th> <th>Mother</th> <th>Father</th> </tr> <?php getParents($selectedDragon, $dragons); ?> </table> <?php function getParents($dragonId, $dragons) { if (isset($dragons[$dragonId])) { $dragon = $dragons[$dragonId]; $mom = (!is_null($dragon['mom'])) ? $dragon['mom'] : 'unknown'; $dad = (!is_null($dragon['dad'])) ? $dragon['dad'] : 'unknown'; printf("<tr> <td>%d</td> <td>%s</td> <td>%s</td> </tr>\n", $dragonId, $mom, $dad); if (!is_null($dragon['mom'])) { getParents($dragon['mom'], $dragons); } if (!is_null($dragon['dad'])) { getParents($dragon['dad'], $dragons); } } } ?>
  5. http://ca3.php.net/manual/en/faq.databases.php#faq.databases.access
  6. Could you clarify your problem by asking a more specific question? The subject and the body of your post don't seem clearly related. If you do not know how many items are in data set, you'll often want to use foreach() for an array or while() to iterate it.
  7. http://ca.php.net/manual/en/function.session-start.php#70033
  8. That depends on how and why the slashes are being added. It's difficult to diagnose the problem without the code. I have seen this problem manifest when code escaped strings twice before submitting it to the database, resulting in some of the escape characters themselves being saved.
  9. The ternary operator will set the value of the first variable to the result of either the first statement or the second statement depending on whether the condition evaluates true. It makes sense to use the ternary operator where you wish to assign one value or another depending on the condition. If you only want to make an assignment in one case or the other, it doesn't make sense. I would re-write your example as so: <?php if (isset($_POST['chkNotes'])) { $_SESSION['rmbrNotes'] = $notes; } elseif (isset($_SESSION['rmbrNotes']) { unset($_SESSION['rmbrNotes']); } ?>
  10. You sure can. If $_POST['value'] is empty, both $message and $value will equal "You forgot something", though.
  11. I don't understand your question. If you add "ORDER BY RAND() LIMIT 1" to the end of the query, it will give you one result at random. Is that not what you want?
  12. Glad to help. Please mark this thread solved. Thanks.
  13. Good point. I didn't notice the array's keys were sequential. Since I assume we're dealing with an INT field in the database, this WHERE clause might be preferable: <?php $sql .= "WHERE team='$team_ident' AND position BETWEEN 0 AND 20"; ?>
  14. I'd like to see your phpinfo() output. It seems this is a server configuration issue either in Apache or PHP.
  15. This looks like a case for "WHERE field IN (item1, item2, ..., itemN)". I don't really understand what you're trying to do specifically, but if you need to match a set of 21 possible values of the position column, use this: <?php // ... $positions = implode(',', array_keys($what)); $sql .= "WHERE team='$team_ident' AND position IN ($positions)"; ?> I don't understand why you are creating an array of keys will null string values. This is inefficient (necessitates the call to array_keys() in order to provide valid input to implode()).
×
×
  • 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.