Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. That's what he was doing originally, just forgetting the 'echo'. That's what I thought he meant.
  2. It's not a hack. It's the 'correct' way. 'echo' just means that it's outputting it to the browser.
  3. echo '<img src="' . $array[$randnumber] . '" />';
  4. $sql = 'SELECT * FROM `table` WHERE title="' . $find . '"';
  5. echo the variable within the value.
  6. 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
  7. 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
  8. Edit:: Wait that's horrible let me edit it.
  9. $query = "select * from Products where (ProductName like \"%$trimmed%\" or ProductBrand like \"%$trimmed%\" or ProductDesc like \"%$trimmed%\");
  10. $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.
  11. $sendinfo=mysql_query('INSERT INTO `dummies`(`User`,`Pass`) VALUES ($name, $password)') or die('request - ' . mysql_error());
  12. The same way you normally would. eg. echo $game_title;
  13. 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(); ?>
  14. $check_adventures = mysql_query("SELECT * FROM adventures WHERE image='{$_GET['adventure']}'");
  15. 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
  16. 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?
  17. 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 />"; }
  18. $decimal = 56.578; $split = explode('.', $decimal); echo strlen($split[1]); Output: 3
  19. Isn't that because after you submit the form you're outputting the display variable before you update it?
  20. 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; }
  21. 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..
  22. 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)) { }
  23. 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.