WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
Web Development Resources
Web Development Content
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
Mobile Dev World

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 : dynamic table columns
Categories : PHP, HTML and PHP, Arrays, Databases, MySQL Click here to Update Your Picture
Joseph Crawford
Date : Aug 28th 2004
Grade : 2 of 5 (graded 6 times)
Viewed : 23382
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Joseph Crawford
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

THIS IS NOT WORKING OUT OF THE BOX

this is a small bit of code i did the other day that i found very usefull and maybe you will too ;) $catsCnt is the result from count() ing a result from mysql_fetch_array. The first line of this file is where you define how many columns you want in your table.

you need to edit this code to fit your site and maybe even just remove the part marked important


<?php

define
('NUM_COLS', 2);

require_once (
'../includes/config.inc');

if (!isset(
$_SESSION['user']['auth'])) {

   
header ("Location:  http://www.nyaspdp.org/nyaspdp.php");
   
ob_end_clean();
    exit();

} else {

   
// set the page title
   
$page_title = 'NYASPDP Browse Subjects';

    include (
'../includes/reg_header.htm');

   
// connect to the database
   
require_once ('../includes/dbconnect.php');

// START THE IMPORTANT STUFF

   
$query = "SELECT cat_id, cat_name FROM catg WHERE cat_name !='!INSTRUCTOR SELECT ONE'";
   
$result = @mysql_query($query) or die(mysql_error());
   
$cats = array();
    while(
$cat=mysql_fetch_array($result)) {
       
array_push($cats, $cat);
    }

   
$catsCnt = count($cats);
    echo
"\n<h1>Select A Subject</h1>";
    echo
"\n<table border='0' cellpadding='2' cellspacing='2' width='90%' align='center'>";
    echo
"\n<tr>";
    for(
$x=0; $x < $catsCnt; $x++) {
        if((
$x+1) % NUM_COLS == 0) {
            echo
"<td class='tblData' width='".(100/NUM_COLS)."%' NOWRAP><a href='courses.php?sid=".$cats[$x]['cat_id']."' class='normal'>".$cats[$x]['cat_name']."</a></td></tr>";
            if (
$x!=($catsCnt-1)) echo "\n<tr>";
        } else {
            echo
"<td class='tblData' width='".(100/NUM_COLS)."%' NOWRAP><a href='courses.php?sid=".$cats[$x]['cat_id']."' class='normal'>".$cats[$x]['cat_name']."</a></td>";
        }
    }
   
$numSpaces=$catsCnt%NUM_COLS;
    if (
$numSpaces!=0) {
        for (
$i=0;$i<=$numSpaces;$i++) {
            echo
"<td width='".(100/NUM_COLS)."%' NOWRAP> </td>";
        }
        echo
"</tr>\n";
    }

    echo
"\n</table>";

// END THE IMPORTANT STUFF

    // Include the HTML footer.
   
include ('../includes/reg_footer.htm');
}
?>



Database resultset navigation
Categories : PHP, HTML and PHP, Databases, MySQL, Navigation
This program will take data from a user via a web based form, validate it, show it to the user for re-validation, and finally insert it into the database. Plenty of sanity checking on the fields in the form.
Categories : MySQL, HTML and PHP, PHP, Complete Programs, Databases
A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL
Sort the results from a SELECT query (any number of columns) into an array automatically.
Categories : PHP, PHP Classes, Arrays, Databases, MySQL
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
How can i Preload a 'SELECT MULTIPLE'?
Categories : HTML and PHP, PHP, MySQL, Databases
Paginating the mySQL data
Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP
This functions makes it easy to use session-variables known from ASP. With one Cookie the array "session" will save and restore from a db-record. In this version MySQL is used but it's should very easy to change
Categories : PHP, Arrays, Cookies, MySQL, Databases
DDN FFA Network Script
Categories : PHP, MySQL, Complete Programs, HTML and PHP, Databases
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
This simple function will take a few arguments and easily set a associative array for each column in a result from a MySQL query
Categories : Databases, PHP, MySQL, Arrays
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
PHP and MySQL scripting for Muyltiple CheckBoxes
Categories : HTML and PHP, MySQL, Databases, PHP
Function for retrieving MySQL enum values into a PHP array.
Categories : PHP, Databases, MySQL, Arrays