Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. Did you change $news_id to whatever variable you're using for the ID? Maybe: WHERE n.ID = $_GET['id']
  2. Note: to setup a table alias, you need to use the AS keyword: SELECT n.title, n.author, n.article, c.username, c.email, c.coment FROM news AS n LEFT JOIN newscomments AS c ON (c.News_ID = n.ID) WHERE n.ID = $news_id You could also use the full table name if you find table aliases confusing: SELECT news.title, news.author, news.article, newscomments.username, newscomments.email, newscomments.coment FROM news LEFT JOIN newscomments ON (newscomments.News_ID = news.ID) WHERE news.ID = $news_id
  3. Ok, it turns out that the GET variables are only carried through if you leave the action attribute blank.
  4. I usually use the actual file name in the action attribute. So if the form page is called "myform.php", I'll use action="myform.php". I've heard there are security issues with setting the action tag to be blank or "#", but I haven't seen anything on what those security risks are. I suppose it has something to do with the GET variables being included in the action attribute. In other words, if you call the form as: www.mywebsite.com/myform.php?id=1 The action attribute would be set to: action="myform.php?id=1" If register globals is turned on, there could be an issue with GET data interfering with POST data.
  5. The following tutorial shows a couple methods of looping through and displaying data from a multidimensional array: http://www.webcheatsheet.com/PHP/multidimensional_arrays.php
  6. You could create a cookie that stores the timestamp of their first visit. Using PHP, you could then compare the cookie timestamp to your midnight deadline. If the cookie timestamp is less than the midnight deadline timestamp, show them the data. mktime() could be used to create the midnight deadline timestamp: http://php.net/manual/en/function.mktime.php time() could be used to get the initial timestamp of the cookie: http://php.net/manual/en/function.time.php setcookie() could be used to create the cookie: http://php.net/manual/en/function.setcookie.php $_COOKIE could be used to read the cookie: http://php.net/manual/en/reserved.variables.cookies.php
  7. Are there any software suggestions for analyzing raw log files? Note that it doesn't need to be free.
  8. No problem, glad it finally works!
  9. As mentioned through PM, the issue is caused by the offset calculation. When there isn't a space after the 30th character, $offset is set to a Boolean false value. And if the third argument in substr() is set to false, it returns an empty string. http://us.php.net/manual/en/function.substr.php The following code should fix the issue: <?php while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { $question = stripslashes($row['question']); if(strlen($question) > 30) { //FIGURE OUT WHERE THE NEXT SPACE IS $offset = strpos($question, " ", 30); //IF A SPACE WAS FOUND, SHRINK THE STRING BASED ON $offset if($offset !== false) { $string = substr($question, 0, $offset) . '...'; //ELSE...USE THE ENTIRE STRING } else { $string = $question; } } else { $string = $question; } echo ' <tr> <td>"' . $string . '"</td> <td><a href=# class="answers" title="' . stripslashes($row['question']) . ' Answers">Answers</a></td> <td>' . $row['totalVotes'] . '</td> <td style="text-align:center;"><img src="img/notepad.png" class="edit" rel="' . $row['ID'] . '"/></td> </tr>'; } ?> Note that the new if statement uses '!==' with two equals signs. This tells it to match the value and type, see the following pages for more information: http://php.net/manual/en/function.strpos.php http://www.php.net/manual/en/language.operators.comparison.php
  10. That's weird, do you have a redirect set up or something? Or maybe you have some CSS that causes the image to move over top of the string?
  11. So what happens if you echo $string in the if statement? <?php if(strlen($question) > 30) { $offset = strpos($question, " ", 30) ; $string = substr($question, 0, $offset); $string = $string ."..."; echo string; } else { ... } ?>
  12. Good point, the ellipsis marks aren't needed if the full string is displayed. As for the issue with the ellipsis marks only showing for strings shorter than 30 characters, I'm not sure what you mean. It works fine for me. Is the code in your last post exactly the same as what you're using?
  13. No problem, glad to help! I didn't realize the curly quotes would cause problems with code until today. So we both learned something. Of course this means I need to modify my own blog posts which contain code; WordPress loves those curly quotes.
  14. What do you mean by "disappears forever", are you looking to delete the data altogether once the cookie expires? Or are you just wanting the content to be unavailable to the user post-cookie?
  15. The error is caused by the curly quotes used throughout the code. If you change everything to straight quotes, it should work just fine. <?php $name = $_POST['name']; $email = $_POST['email']; $fp = fopen("formdata.txt", "a"); $savestring = $name . "," . $email . "n"; fwrite($fp, $savestring); fclose($fp); echo "<h1>You data has been saved in a text file!</h1>"; ?>
  16. As kney suggested, the error comes from the initial string being too short. To prevent the error, wrap the code with an if statement which determines if the string is greater than 30 characters. To get the code to work with where you display the strings, it needs to go inside the while loop: <?php while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { $question = stripslashes($row['question']); if(strlen($question) > 30) { $offset = strpos($question, " ", 30) ; $string = substr($question, 0, $offset); } else { $string = $question; } echo ' <tr> <td>"' . $string . '..."</td> <td><a href=# class="answers" title="' . stripslashes($row['question']) . ' Answers">Answers</a></td> <td>' . $row['totalVotes'] . '</td> <td style="text-align:center;"><img src="img/notepad.png" class="edit" rel="' . $row['ID'] . '"/></td> </tr>'; } ?>
  17. You need to define the table aliases before using them. So "t." and "g." won't work as the query is currently set up.
  18. As gizmola suggested, using a multidimensional array should work. The following tutorial shows a few ways to set up and loop through a multidimensional array: http://www.webcheatsheet.com/PHP/multidimensional_arrays.php
  19. To use column names from another table, you'll need to use a MySQL Join. http://dev.mysql.com/doc/refman/5.0/en/join.html You need to join "table" and "game".
  20. echo count($AnArray[1]);
  21. Not sure if this is causing the problem, but you need to change <php to <?php
  22. It just seems like you need to rework the patterns. As with "bus_it_requests", you'll need to run all the patterns which start with "bus" before the "/bus/" pattern. For example, it looks like you have patterns like "bus_service" and "bus_financial". Those need to be moved.
  23. Did you see Reply #7 about the underscore pattern?
  24. I experimented with the code and it looks like the issue is coming from the "/_/" pattern near the beginning. Since this removes the underscores, the following pattern "/bus_it_requests/i" doesn't do anything. Moving the underscore pattern to the end seems to work for me.
  25. Is there something around the keywords you're replacing that could be used? For example, in the original string is the word "bus" followed by a space? If so, you could modify the pattern to "/bus /".
×
×
  • 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.