T4VN is an online PHP Help community that provides PHP Tutorials, PHP Examples, PHP Scripts, PHP Support
    HOME  |  HOSTING COUPON  |  TEMPLATE  |  PHP SCRIPTS  |  LINK TO US  |  LINK  |  REGISTER | CONTACT
::: Member Login :::
 Username
 Password
 
Forgot your password ?
::: PHP Tutotal :::
  PHP Basic (7)
  PHP Advanced (4)
  PHP Database (2)
  Coding Step By Step (8)
  PHP and AJAX (0)
::: PHP Example :::
  Arrays (1)
  Code Highlighters (3)
  Database Functions (12)
  Date & Time (5)
  E-Mail (6)
  Forms (5)
  Guestbooks (1)
  Logging (2)
  Miscellaneous (10)
  Password Generators (3)
  Randomizers (3)
  String Manipulation (10)
  User Authentication (6)
::: Search On T4VN :::
::: T4VN Statistics :::
  PHP Scripts : 64
  PHP Example : 67
  PHP Tutorials : 21
  PHP News : 93
  Total Coupon : 36
  Other Tutorials :
  Member : 215
  Visitor Online : 3
  Today Visit: 309
  Total Visitor : 301331
  Most Online : 41
::: Sponsored Links :::

PR 4 For This Webpage

Vinaora Logo
Home Today :

Get data from multiple fields - tables

Author : mbills2

You can use this function to grab data from your database by creating an array and calling the function. You should be able to make each parameter an array (the table, field, etc) but I have only tested the field parameter. The require include.php contains the database info: $DBhost, $DBuser, $DBpass, $DBname, etc...

PHP Example :

<?php
require 'include.php';

function 
ConnectToTable$field$tableName$data$data2 )
{
    require 
'include.php';

    
$fieldCount count($field);
                
    for (
$i=0$i<$fieldCount;$i++)
    {
        
$connection mysql_connect($DBhost$DBuser$DBpass) or die ("Unable to connect to MySQL server."); 
        
$db mysql_select_db($DBname$connection) or die ("Unable to select database."); 
        
        
$sql "SELECT $field[$i] FROM $tableName WHERE $data = $data2";    
        
        
// testing sql statement
         
echo ("sql: $sql  <br>");    
        
        
$sql_result mysql_query($sql,$connection) or die ("Couldn't execute SQL query");
    
        while (
$row mysql_fetch_array($sql_result)) 
        {    
            
$data3[$i] = ( $row["$field[$i]"] );
        }                
    }    
    
    return 
$data3;    
}

//---------------------------------------------------------------------------------------------------------------
//
//  Put the fields you want to query from the database into an array 
//    Then make another array to hold the data.
//    ConnectToTable( A, B, C, D )
//
//    The query will look like:  SELECT A FROM B WHERE C = D 
//
//    $fieldCount just counts how many fields you use, in this case I used a 'for loop' to output the data.
//
//--------------------------------------------------------------------------------------------------------------- 

$field = array('manufacturer''seller''url''url2''url3''url4','url5');
$test ConnectToTable$field$photosphotoid113 );
$fieldCount count($field);

for (
$i=0$i<$fieldCount ;$i++)
{
    echo 
"data $i: $test[$i] <br>";    
}
?>


Usage Example:

PHP Example :

<?
Put the fields you want to query from the database into an 
array (add as many as u like). 


$field = array('manufacturer''seller''url''url2''url3''url4','url5'); 


Then make another array to call the function and store the data

function 
call looks like
yourVariable ConnectToTableABC); 
The query will look like:  SELECT A FROM B WHERE C 

$test 
ConnectToTable$field$photosphotoid113 ); 
  

$fieldCount just counts how many fields you use, in this case I used a 'for loop' to output the data

$fieldCount count($field); 
for (
$i=0$i<$fieldCount ;$i++) 

    echo 
"data $i: $test[$i] <br>";     


OUTPUT
data 0Output1 
data 1
Output2 
data 2
Output3 
data 3
Output4 
data 4
Output5 
data 5
Output6 
data 6
Output7 
?>



Other Example
Check if a table exists
SQL script import function
Data Type Converter between PHP and PostgreSQL
mssql escape string
Insert/Update/Delete functions
My Batch Query


::: Resources :::
  Links Directory
  Programming 2 3
  Webmaster 2 3
  Web Design 2 3
  Web Hosting 2 3
  Other Links 2 3
  Asian ShowBiz News
  Teach Seo For You
::: New Templates :::




::: Other Tutorials :::
 Program Design

  Powered By T4VN.NET - Version 2.0 - CopyRight © T4VN.NET 2005-2007