WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Initialize global variables for every field in a table. This is the generic version. It does not require phplib.
Categories : Global Variables, MySQL, PHP, Variables Update Picture
Victor Font
Date : Aug 05th 1999
Grade : 3 of 5 (graded 2 times)
Viewed : 6073
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Victor Font
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php

/* variable initialization

        will initialize a global variable for every field in a given table
        reduces coding later if a table structure changes

        written by Victor M. Font Jr.
        Abba Consulting group
        http://abba.fontlife.com

*/


        function initvar($varname, $value=null){
                global $$varname;
                if(!isset($$varname)){
                        if ($value == null){
                                $$varname = "";
                        }else{
                                $$varname = $value;
                        }
                }
        }

        $sServer = "localhost";
        $sUser = "your_user_id";
        $sPass = "your_password";
        $Database = "your_database";

        $db = mysql_connect($sServer, $sUser, $sPass);
        mysql_select_db($Database,$db);

        
        // populate this array with the tables for which you are initializing variables
        $sTableList = array("table1","table2","table3","table4","table5");

        for ($n=0; $n<count($sTableList); $n++){

                $id = @mysql_list_fields($Database, $table);

                $count = @mysql_num_fields($id);

         $results["num_fields"] = $count;

                for ($i=0; $i<$count; $i++) {
                        $results[$i]["table"] = @mysql_field_table ($id, $i);
                        $results[$i]["name"] = @mysql_field_name ($id, $i);
                        $results[$i]["type"] = @mysql_field_type ($id, $i);
                        $results[$i]["len"] = @mysql_field_len ($id, $i);
                        $results[$i]["flags"] = @mysql_field_flags ($id, $i);
                        $results["meta"][$results[$i]["name"]] = $i;
}

                @mysql_free_result($id);

                for ($i=0; $i<$results["num_fields"]; $i++){
                        /*
                         if you want to initialize variables for types other
                         than strings and numbers, you'll have to add your own
                         type in the switch statment below
                        */
                        switch ($results[$i]["type"]){
                                case "string":
                                        initvar($results[$i]["name"]);
                                        break;
                                case "int":
                                        initvar($results[$i]["name"],0);
                                        break;
                                case "blob":
                                        initvar($results[$i]["name"]);
                                        break;
                        }
                }
        }
?>



Initialize global variables for every field in a table. This version requires that phplib is installed on your server.
Categories : Global Variables, MySQL, PHP, Variables
How to make sure a that $foo is from a cookie and not from the URI.
Categories : PHP, Variables, Global Variables, Cookies
Make old style (PHP3) scripts using GET, POST, COOKIE and File uploads (POST) compatible with PHP 4.2.0
Categories : PHP, HTML and PHP, Global Variables, Cookies, Variables
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
Global Dump Highlighted
Categories : PHP, Variables, Global Variables
getting the name of the current script and query string
Categories : PHP, Global Variables, Variables, URLs
Simple script to passing persistent and growing array between recalls of one page (manipulate little stack).
Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables
FormWizard reads a mysql table and generates automatically a html formular in a html-table
Categories : PHP, MySQL, HTML
Convert date's in YYYY-MM-DD (i.e. mysql format) into PHP3 timestamps. Also Find the difference in days between two PHP3 timestamps.
Categories : HTML and PHP, PHP, MySQL, Date Time
PhpLens PHP Application Server
Categories : Content Management, Databases, PHP, MySQL
Writing Portable MySQL Code in PHP: Porting to Oracle, Microsoft SQL Server, Sybase, Interbase, PostgreSQL and other databases using ADODB class library.
Categories : MySQL, PHP, PHP Classes, ODBC, General SQL
A login page that require username, password and userlevel.
Categories : PHP, Security, Sessions, MySQL, Databases
Database resultset navigation
Categories : PHP, HTML and PHP, Databases, MySQL, Navigation
This is a redirection program which is as good as the come.to v3 url redirection, complete with admin interface all clients stored in mysql
Categories : PHP, MySQL, Ecommerce, HTML and PHP, Complete Programs
This script is a contact form between users of a website (kinda like the PM function on the forums)
Categories : PHP, Databases, MySQL, Regexps