
Alex
Staff Alumni-
Posts
2,467 -
Joined
-
Last visited
Everything posted by Alex
-
echo '<img src="' . $array[$randnumber] . '" />';
-
[SOLVED] MySQL query to find table name exactly equal to input
Alex replied to ArizonaJohn's topic in PHP Coding Help
$sql = 'SELECT * FROM `table` WHERE title="' . $find . '"'; -
echo the variable within the value.
-
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
-
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
-
Edit:: Wait that's horrible let me edit it.
-
$query = "select * from Products where (ProductName like \"%$trimmed%\" or ProductBrand like \"%$trimmed%\" or ProductDesc like \"%$trimmed%\");
-
$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.
-
$sendinfo=mysql_query('INSERT INTO `dummies`(`User`,`Pass`) VALUES ($name, $password)') or die('request - ' . mysql_error());
-
The same way you normally would. eg. echo $game_title;
-
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(); ?>
-
$check_adventures = mysql_query("SELECT * FROM adventures WHERE image='{$_GET['adventure']}'");
-
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
-
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?
-
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 />"; }
-
$decimal = 56.578; $split = explode('.', $decimal); echo strlen($split[1]); Output: 3
-
Isn't that because after you submit the form you're outputting the display variable before you update it?
-
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; }
-
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..
-
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)) { }
-
Works for me: <?php $total= 1244.70; $mitax = 11.70; $sub = $total - $mitax; echo $sub; ?> Output: 1233