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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.