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 : Mimic ASP's GetString function with PHP
Categories : PHP, Databases, MySQL, Strings
bastien koert
Date : Mar 10th 2005
Grade : 1 of 5 (graded 3 times)
Viewed : 6980
File : No file for this code example.
Images : No Images for this code example.
Search : More code by bastien koert
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

ASP(VBScript), from time to time, has some neat features. One is a function called GetString, which pertains to the Recordset object. Its purpose is to pull the entire recordset into a formatted string and close the connection to free resources. This type of functionality can be quite useful in a high load environment. So I thought it would duplicate the functionality with PHP. So here it is...

<?php
require("conn.php");                             //require connection data

$delimiter_string = "</td>\n\t\t<td>";           //the \n\t\t pattern is
added to be able to format the source clearly

$sql
= "select * from tableName";

$result = conn($sql);                            //custom connection
function - so don't freak out

$data = GetString($result, $delimiter_string);   //call the function

echo "<table>$data</table>";                     //print out the results

function GetString($handle,$delimiter)
{
/*
    This function emulates the ASP GetStrings function. It creates an
    array of the dataset where the the array is a string with a certain delimiter

    ie if you were to pass a delimiter of "|" your data would be
    element1 | element2 | element3

    for a pipe-delimited string to pass around

    delimiter of "</td><td>" would get you
    element1 </td><td> element2 </td><td> element3

    to make it really easy to create a table dump of your data

    (Note: I added \n\t\t in the pattern to be able to see the output neatly formatted when I view the source code for it)

*/

    if (mysql_num_rows($handle)>0){

    //initialize the array
      $RsString   = ''; //array();

    //loop thru the recordset
      while ($rows =  mysql_fetch_array($handle,MYSQL_ASSOC))
      {
             //add some additional tags to open and close the table rows with some formattting
             $RsString .=
"\n\t<tr>\n\t\t<td>".implode($delimiter,$rows)."</td>\n\t</tr>\n";
      } //wend
      return $RsString;
    }else{
      //no records in recordset so return false
      return false;
    } //end if
    //close the connection
  mysql_close($handle);

} //end function
?>



bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
mysql_escape_string
Categories : PHP, MySQL, Databases, Strings
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
Phorum, MySQL, Language, UK date format, MySQL UK Date format
Categories : PHP, Date Time, Strings, MySQL, Databases
Simple db results paging example
Categories : PHP, MySQL, Databases, Form Processing
for each record, do this to the first record, and do that to any subsequent record
Categories : PHP, Databases, MySQL, Beginner Guides
DBXML- A Class to backup databases in XML Format using web interface
Categories : PHP, PHP Classes, Databases, MySQL, XML
Dynamically generated pop-ups (Select items)
Categories : PHP, HTML and PHP, MySQL, Databases
DB Connection Function with error handling and email failure notices
Categories : PHP, MySQL, Errors and Logging, Databases, Errors and Logging
database,php,mysql,demo,example,php3,training,tutorial,codes,code
Categories : Databases, MySQL, PHP, PHP Options and Info
Displaying records of database in more than one page (paging)
Categories : Databases, MySQL, PHP
MySQL Class to ease Database connectivity
Categories : MySQL, PHP Classes, Databases, PHP
Zip code range and distance calculation class v1.0.0
Categories : PHP, Databases, MySQL, Zip Code
This is a very simple BBS that uses MySQL
Categories : MySQL, Databases, Complete Programs, PHP
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs