-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
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.
-
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)); }
-
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>
-
why my explode and str_split code is not working?
cyberRobot replied to Michael_Baxter's topic in PHP Coding Help
What does the related code currently look like? -
why my explode and str_split code is not working?
cyberRobot replied to Michael_Baxter's topic in PHP Coding Help
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 -
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.
-
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
-
mysql query not working with drop down boxes
cyberRobot replied to lindisfarne's topic in PHP Coding Help
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. -
How do I merge two data forms in PHP and make one of them hidden?
cyberRobot replied to Anthon9's topic in PHP Coding Help
In case you didn't see it, this was covered in a previous post. See Reply #19. -
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/
-
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
-
Bug: Empty lines when [quote]ing
cyberRobot replied to requinix's topic in PHPFreaks.com Website Feedback
Here's a test for the Quote feature next to the code tags button (<>). Ding, ding, ding. We have a winner. -
Bug: Empty lines when [quote]ing
cyberRobot replied to requinix's topic in PHPFreaks.com Website Feedback
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. -
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.
-
Bug: Empty lines when [quote]ing
cyberRobot replied to requinix's topic in PHPFreaks.com Website Feedback
Hmm...that seems to have taken care of the issue for me. Thanks requinix! -
Bug: Empty lines when [quote]ing
cyberRobot replied to requinix's topic in PHPFreaks.com Website Feedback
Yay! Now Quote, More Reply Options, and Add Reply. -
Bug: Empty lines when [quote]ing
cyberRobot replied to requinix's topic in PHPFreaks.com Website Feedback
Just testing. The above quote came from pushing the Quote button. And then pressing Post. -
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.
-
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().
-
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>";
-
How do I merge two data forms in PHP and make one of them hidden?
cyberRobot replied to Anthon9's topic in PHP Coding Help
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. -
Alternate solution: array_sum() - http://php.net/manual/en/function.array-sum.php
-
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.
-
Undefined index error where it should not be
cyberRobot replied to Codin2012's topic in PHP Coding Help
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. -
Planned Downtime: Saturday Sept 17th, 12-4am PDT (7-11am UTC)
cyberRobot replied to requinix's topic in Announcements
Yay! I hope all goes well.