Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. You could loop through the words and remove entries that are empty. Are you looking to preserve the HTML code? If not, you could look into using strip_tags() to remove it. Otherwise, you'll need to figure out how to repair any broken tags caused by limiting the text to X words.
  2. If you output the array of words ($words), you'll see that some of the slots are taken up by white space. function limit_words($string, $word_limit) { #$words = explode(" ",$string); $words = preg_split('/\s+/', $string); echo '<pre>' . print_r($words, true) . '</pre>'; return implode(" ",array_splice($words,0,$word_limit)); }
  3. If you are looking to pass variables through anchor tags, you use a format like this: <a href="?myVar=hello">Link</a> Note the question mark before the variable named "myVar". When you click the link, the variable is passed to PHP and can be retrieved using $_GET['myVar']. Here's a quick code sample that you could use: <?php if(isset($_GET['myVar'])) { echo $_GET['myVar']; } ?> <div><a href="?myVar=hello">Link</a></div>
  4. What does the related code currently look like?
  5. explode() returns an array. So you'll need to access the values using array format (e.g. $player_name[0]). More information can be found here: http://php.net/manual/en/function.explode.php
  6. Topic has been moved to PHP Help. As for your question, you could try an online solution like the following: http://phptester.net/ Note that I haven't used PHPTester. I just ran a Google search for "test PHP code" and this was the first result.
  7. For what it's worth, the first thing that comes up when searching for Mail::factory() is PEAR. Is that what you're using? https://pear.php.net/manual/en/package.mail.mail.factory.php
  8. With the following code, $bird, $cat, $mouse, and $goat will always contain a value. They will be set to whatever was selected in the form or NULL: $bird = ( ! empty($_POST['author'])) ? $_POST['author'] : null; $cat = ( ! empty($_POST['genre'])) ? $_POST['genre'] : null; $mouse = ( ! empty($_POST['year'])) ? $_POST['year'] : null; $goat = ( ! empty($_POST['publisher'])) ? $_POST['publisher'] : null; So if the publisher field, for example is blank, $goat will be set to NULL. And your query will look something like this: Unless you have a database record that looks like that (including the "null"), the query will not return anything. Instead you could try something like this $whereClause = array(); if(!empty($_POST['author'])) { $whereClause[] = "author='" . mysql_real_escape_string($_POST['author']) . "'"; } if(!empty($_POST['genre'])) { $whereClause[] = "genre='" . mysql_real_escape_string($_POST['genre']) . "'"; } if(!empty($_POST['year'])) { $whereClause[] = "year='" . mysql_real_escape_string($_POST['year']) . "'"; } if(!empty($_POST['publisher'])) { $whereClause[] = "publisher='" . mysql_real_escape_string($_POST['publisher']) . "'"; } And then the query would be modified to the following: $sql = "SELECT * FROM books WHERE " . implode(' AND ', $whereClause); Note that the code is untested. But the query should only search fields where the user selected something in the dropdown.
  9. In case you didn't see it, this was covered in a previous post. See Reply #19.
  10. Are you familiar with the basics of CSS? If not more information can be found here: http://www.cssbasics.com/ If you prefer learning from a book, Eric Meyer has some good books. You could start here: http://www.ericmeyeroncss.com/
  11. It sounds like there is an error in the query. For debugging purposes, you could use mysqli_error(). For example $result = mysqli_query($con, "SELECT * FROM users WHERE email = '" . $email. "' and password = '" . md5($password) . "'") or die(mysqli_error($con)); Side note: in case you're not aware, md5() isn't recommended for securing passwords. More information can be found here: http://php.net/manual/en/function.md5.php#refsect1-function.md5-notes
  12. Here's a test for the Quote feature next to the code tags button (<>). Ding, ding, ding. We have a winner.
  13. Test in Firefox. (Quote and Post) Does the Quote button work for anyone else in Internet Explorer 11? Note that I'm referring to the button in the lower-right corner under a person's post. I don't use IE for much, other than for testing. I don't think I modified the browser with any plugins or anything that would get in the way.
  14. It looks like the second part of the query isn't being added. Where does $size come from in you if statement? if(isset($size)) $sql.=" WHERE software_title IN (".implode(',', $software_title).")"; If $size isn't set, the $sql line below it will not execute.
  15. Hmm...that seems to have taken care of the issue for me. Thanks requinix!
  16. Yay! Now Quote, More Reply Options, and Add Reply.
  17. Just testing. The above quote came from pushing the Quote button. And then pressing Post.
  18. I personally liked many of the design changes. And was happy to see the tag bug go away, as well as the double space issue. Of course, there were many things I would have needed to adjust to and some that I'm still trying to repress.
  19. For what it's worth, there were a few posts to this question yesterday. But it looks like those were lost when the forum was rolled back to IPB v3. I believe they suggested the LIMIT clause and array_slice().
  20. You could try something like the following: echo "<select name='stat_id' onchange='filterContent(this);'>"; foreach ($row_stat as $r) { echo '<option value="'.$r['statid'].'"'; if (isset($statid) && $statid==$r['statid']){ echo ' selected="selcted"'; } echo '>'.$r['stat_name'].'</option>'; } echo "</select>";
  21. Do they need to fill out the form at the same time? In other words, do you really need to combine both forms so that each party can see that other person is filling out their portion? Perhaps you could build a system which assigns a common identifier that both parties use to fill out their portion. Both pieces would then be saved to a database and connected with that identifier. Then you could have a separate script that combines both responses for whoever needs to see the results.
  22. Alternate solution: array_sum() - http://php.net/manual/en/function.array-sum.php
  23. One thing to keep in mind about PHP, and other programming languages, is that the error doesn't always point to the correct line. Sometimes, the error is caused by something earlier in the script. For example, I get a similar error with the following code: <?php print 'hello' if(1) { print ' there'; } ?> PHP says there is an error on line 3. However, the actual error is on line 2, where I'm missing a semi-colon.
  24. Where does $result come from? We may be able to help if you show the code that creates the variable being passed to the class constructor.
  25. Yay! I hope all goes well.
×
×
  • 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.