Jump to content

How to write mysql-record to the file


chilicoctail

Recommended Posts

Hi all.

 

I am quite green in PHP and I have one problem.

 

I have table, where I have records:

ID  col1  col2  col3  col4
1    a      b     c     d
2    e      f     g     h

 

Now I want to get one record from table and I can get it like this: SELECT col1, col2, col3, col4 FROM table where id=1;

 

The question is:

 

How I could write col-names and values to the file like this:

col1   a
col2   b
col3   c
col4   d

 

I dont want to get id-column-name or value to the file.

 

Can someone help me ?

 

Link to comment
https://forums.phpfreaks.com/topic/93158-how-to-write-mysql-record-to-the-file/
Share on other sites

Hi tinker !

 

1. I meant a text file.

 

2. Sure

 

<?php

$link = mysql_connect('localhost', 'db_user', 'password');

if (!$link) {
die('Cound not connect: ' . mysql_error());
}

mysql_select_db('database');

$query="SELECT col1, col2, col3, col4 FROM table WHERE id=1";
$result=mysql_query($query);


?>

 

I really appreciate your help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.