loop through mysql columns

We need a col_loop() function in php that loops through all the columns of a given mysql table and identifies specific character patterns.

It will take 3 arguments:




For example, suppose we have the widgets table as follows:

id / varchar1 / varchar2

1 / lsdkfabclksdf / asldfkj

2 / fldskflds / dkfabc sdf

The [url removed, login to view] page will call the function as follows:

$myresult = col_loop("widgets","id","abc");

The following would be returned when one runs [url removed, login to view] in the browser (preferably via echo()):

Row: id=1 Column(s): varchar1

Row: id=2 Column(s): varchar2

If we add new columns to the table the script must pick them up automatically the next time it is run.

The function must work with db config files in the following format:

[url removed, login to view]


$hostname = "localhost";

$dbname = "mydbname";

$username = "myusername";

$password = "mypassword";


The function must include the config file early on in a manner that is well commented so that we can change config files when working with other dbs.

I'm not sure how this should be done in php but it should probably be similar to the jdbc code below:



Statement s = [url removed, login to view] ( );

[url removed, login to view] ("SELECT * FROM profile");

ResultSet rs = [url removed, login to view] ( );

ResultSetMetaData md = [url removed, login to view] ( ); // get result set metadata

int ncols = [url removed, login to view] ( ); // get column count from metadata

int count = 0;

while ([url removed, login to view] ( )) // loop through rows of result set


for (int i = 0; i < ncols; i++) // loop through columns


String val = [url removed, login to view] (i+1);

We are still on version 4 of php.

Kemahiran: PHP

Lihat lagi: php mysql loop columns, mysql loop columns, php loop columns, mysql loop column, loop columns mysql, mysql loop, php loop column, php loop mysql columns, loop mysql, loop column mysql, php mysql loop column, php loop mysql, loop column php, using php loop table columns, mysql column loop, mysql loop rows, mysql php loop columns, php loop table columns, loop mysql php, php loop mysql fields, php loop, mysql loop row, mysql loop table, php loop mysql table, loop mysql column

Tentang Majikan:
( 6 ulasan ) Antelope, United States

ID Projek: #264038

Dianugerahkan kepada:


Hi,I can start immediately and complete it in two hours. Regards Bo Zhang

$30 USD dalam 0 hari
(215 Ulasan)

7 pekerja bebas membida secara purata $46 untuk pekerjaan ini


Easy project! Will be finished in several hours after you accept my bid. Let's start! Best Regards, Zeke.

$50 USD dalam 0 hari
(141 Ulasan)

Hi, please see PM.

$75 USD dalam sehari
(49 Ulasan)

I can do this

$30 USD dalam 0 hari
(84 Ulasan)

Very easy job. One hour may be. Lets talk in PMB.

$30 USD dalam 0 hari
(65 Ulasan)

i can make your project.. i have experience in php.. html.. css. mysql.. oracle.. design.. javascript... i can start now.. the script is easy... make the query... and get results.. in array... give me oportunity.. Lagi

$40 USD dalam 2 hari
(1 Ulasan)

Clear with requirements, escrow needed.

$70 USD dalam 2 hari
(0 Ulasan)