Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. Not.. if (!$_POST['update']) { Use: if (isset($_POST['update'])) {
  2. Use: if(isset($_POST['something']) && isset($_POST['somethingelse'])).. Instead of: if($_POST['post']).. Also, why would you have the date as a text field? They could put whatever they want. You should use date as a unix time stamp. You can use time(), and when fetching the blog posts use date()
  3. That's what he was doing originally, just forgetting the 'echo'. That's what I thought he meant.
  4. It's not a hack. It's the 'correct' way. 'echo' just means that it's outputting it to the browser.
  5. echo '<img src="' . $array[$randnumber] . '" />';
  6. $sql = 'SELECT * FROM `table` WHERE title="' . $find . '"';
  7. echo the variable within the value.
  8. Arg, I edited that last post wrong.. And now I can't edit it again.. this is it: function pad_string($str, $arr) { $amt = (strlen($str)/2); $split = str_split($str); $num = 0; while($num < $amt) { array_splice($split, rand(0, count($split)), 0, $arr[rand(0, count($arr))]); $num++; } return implode('', $split); } $arr = array('x', 'b', 'c', 'd'); $str = '4362755647'; $new_str = pad_string($str, $arr); echo 'Original String: ' . $str . '<br />'; echo 'Original Length: ' . strlen($str) . '<br />'; echo 'New String: ' . $new_str . '<br />'; echo 'New String Length: ' . strlen($new_str) . '<br />'; Output: Original String: 4362755647 Original Length: 10 New String: 4c36275564b7cdx New String Length: 15
  9. Try: function pad_string($str, $arr) { $amt=(strlen($str)/2); $split = str_split($str); $ori = $split; for($i = 0;$i < $amt;$i++) { $replace = rand(0, count($split)); array_splice($split, $replace, 0, $arr[rand(0, count($arr))]); } return implode('', $split); } $arr = array('x', 'b', 'c', 'd'); $str = '436275547'; $new_str = pad_string($str, $arr); echo 'Original String: ' . $str . '<br />'; echo 'Original Length: ' . strlen($str) . '<br />'; echo 'New String: ' . $new_str . '<br />'; echo 'New String Length: ' . strlen($new_str) . '<br />'; Output: Original String: 4362755647 Original Length: 10 New String: 4c36275564b7cdx New String Length: 15
  10. Edit:: Wait that's horrible let me edit it.
  11. $query = "select * from Products where (ProductName like \"%$trimmed%\" or ProductBrand like \"%$trimmed%\" or ProductDesc like \"%$trimmed%\");
  12. $rs = mysql_query($sql); The connection isn't a parameter of mysql_query() Edit: And yea, you have to change it to a mysql connect, not mysqlite.
  13. $sendinfo=mysql_query('INSERT INTO `dummies`(`User`,`Pass`) VALUES ($name, $password)') or die('request - ' . mysql_error());
  14. The same way you normally would. eg. echo $game_title;
  15. function getVehicles() { $sql1 = "SELECT vin, plate, year FROM vehicles"; $rt = mysql_query($sql1); while($row1 = mysql_fetch_array($rt)) { $list1 .= '<option value="' . $row1['vin'] . '">' . $row1['plate'] . ', ' . $row1['year'] . '</option>'; } return $list1; } <?php echo getVehicles(); ?>
  16. $check_adventures = mysql_query("SELECT * FROM adventures WHERE image='{$_GET['adventure']}'");
  17. In your code it seems like you're only updating row '1'. To fetch the info for only row 1 it would be like this: $result = mysql_query("SELECT sitename, siteurl FROM `info` WHERE id='1' LIMIT 1"); $row = mysql_fetch_assoc($result); echo $row['sitename']; //sitename echo $row['siteurl']; //siteurl
  18. The problem is obviously that you're selecting all the columns, you have to choose which one you want. But I don't understand what you're trying to do.. You have the sitename and you want to select the sitename?
  19. Edit: $query = "SELECT country, COUNT(country) FROM contries GROUP BY country"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['country'] . ' - ' . $row['COUNT(country)']; echo "<br />"; }
  20. $decimal = 56.578; $split = explode('.', $decimal); echo strlen($split[1]); Output: 3
  21. Isn't that because after you submit the form you're outputting the display variable before you update it?
  22. Well, if it's a function you want it to return, rather than echo.. right? function getDrivers() { $sql = "SELECT fname, lname, dl FROM drivers"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { $list .= '<option value="' . $row['dl'] . '">' . $row['lname'] . ', ' . $row['fname'] . '</option>'; } return $list; }
  23. Echoing is outputting? Do you mean making it only output a single string? If so then you can just build it all into one string. Instead of echoing something just add it a collective output string, that you'll echo at the end. $string .= "stuff"; $string .= ", more stuff.."; echo $string; Output: stuff, more stuff..
  24. You mean just getting the result of a query into an array? $result = mysql_query($sql); $row = mysql_fetch_assoc($result); //or this if it returns more than 1 row while($row = mysql_fetch_assoc($result)) { }
  25. Works for me: <?php $total= 1244.70; $mitax = 11.70; $sub = $total - $mitax; echo $sub; ?> Output: 1233
×
×
  • 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.