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.

Evner: PHP

Se mere: 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

Om arbejdsgiveren:
( 6 bedømmelser ) Antelope, United States

Projekt ID: #264038

Tildelt til:


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

$30 USD in 0 dage
(215 bedømmelser)

7 freelancere byder i gennemsnit $46 på dette job


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

$50 USD in 0 dage
(141 bedømmelser)

Hi, please see PM.

$75 USD på 1 dag
(49 bedømmelser)

I can do this

$30 USD in 0 dage
(84 bedømmelser)

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

$30 USD in 0 dage
(65 bedømmelser)

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.. Flere

$40 USD in 2 dage
(1 bedømmelse)

Clear with requirements, escrow needed.

$70 USD in 2 dage
(0 bedømmelser)