Entries Tagged 'PHP' ↓

HTML POST PHP Array Debbugging code that tests passing variables

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.

Create a Javascript Array with PHP from a MySQL Database Table

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 <strong>table_name</strong> LIMIT 0, 100000000";
$jarray = "var <strong>your_array</strong> = new Array();\n\t\t";
$i = 0;
$q = mysql_query($sql);
while($object = mysql_fetch_object($q)){
$jarray = $jarray."<strong>your_array</strong>[{$i}] = \"{$object-&gt;<strong>field_name</strong>}\";\n\t\t";
$i++;
}

print $jarray."\n";
}

Put your own info where the Text is bold

PHP MySQL Count Query Using Where Clause

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.

}