Entries Tagged 'PHP' ↓
April 3rd, 2008 — MySQL, PHP
This post teaches you how to set your MySQL search queries to be Case sensitive or case insensitive.
It's all in the database collation. MySQL by default search case insensitive. In phpMyAdmin or or Putty change the Collation of your fields. Collations that are binary search case-sensitive. Collations that end with _ci like latin1_swedish_ci are case insensitive (ci is an acrynm for case insensitive.
To change your Collations quickly run this code in a loop:
ALTER TABLE tablename CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci;
February 27th, 2008 — How to, PHP
Striping the file extension is valuable on many levels. If i could have a nickel for every time I need to strip the file extension I'd have close to 3 bucks. One method to achieve stripped extensions is the PHP substr(), which takes in the String, Starting point, Ending point. To start from the end of the string use negative values. i.e. substr("my chicken", 0, -2) would make it "my chick", perfect
<?php
$my_file = "foobar.jpg";
$my_file= substr($my_file, 0 , -4);
echo $my_file;
?>
Result: foobar
Note: Spaces count, so count them!
February 25th, 2008 — PHP
Great PHP code that displays how the arrays break down when passing from HTML forms to $_POST variables.
echo "<pre>";
print_r ($_POST);
print_r ($_FILES);
echo "</pre>";
This helps when juggling multiple files or big database entries.
February 8th, 2008 — JavaScript, MySQL, PHP, Web Development
Wrote this function to check email addresses already in a database, so I dont have to change pages, and check with javascript. Problem: it exposes your whole email list to the public in the source code, and the source code can become a monster length. So it isnt practical, but it works. (I'm not using it to check emails)
The script proves useful to do other things with javascript and spawn arrays to manipulate data... etc.
function jarray(){
$sql = "SELECT * FROM table_name LIMIT 0, 100000000";
$jarray = "var your_array = new Array();\n\t\t";
$i = 0;
$q = mysql_query($sql);
while($object = mysql_fetch_object($q)){
$jarray = $jarray."your_array[{$i}] = \"{$object->field_name}\";\n\t\t";
$i++;
}
print $jarray."\n";
}
Put your own info where the Text is bold
October 10th, 2007 — MySQL, PHP
Here is an example of a function that was created to count the number of book spreads attached to a certain book number. The problem was there were more than one book number attached to a whole table of bookspreads. By using SQL COUNT and WHERE it is possible to find the total count of entries with the same field input.
$book // the book number i wanted to count if a spread was attached to it
function spreadcount($book){
$query = "SELECT COUNT(*) FROM table WHERE book={$book} ";
$result = mysql_query($query) or die(mysql_error());
echo mysql_result($result,0); // 0 pulls the first result which is our magic number.
}