0

this may be very easy to do but I do not even know how to formulate my problem for search engines (google | stackoverflow).

I am trying to create a HTML form based on data from database.
my problem:
I have table with these columns:

  1. id
  2. file
  3. language
  4. etc...

filled with data (example):

//no < table > here
//only **file** column is really important for my select (that I am asking for)

id |    file            |  lanugage     | etc
====================================================================
1  |about.php           | english       | something
2  |conta.php           | english       | something
3  |mysql.php           | hungar        | something
4  |mysql.php           | english       | something
5  |mysql.php           | french        | something
6  |blog.php            | french        | something

after the select I am asking for array should look like this

0 => about.php, 1 => conta.php, 2 => mysql.php, 3 => blog.php



SOLUTION
I was looking for distinct option of SELECT
or
SELECT t1.file as Files from table as t1 group by Files

well this was fast :) thanks

Kyslik
  • 8,217
  • 5
  • 54
  • 87
  • 2
    show us your current PHP/MySQL code, we can't guess it. – Jocelyn Aug 02 '12 at 15:09
  • There is none :) I am just trying to "create" select nothing else. IF you like `$query = $this->db->query('SELECT file` – Kyslik Aug 02 '12 at 15:11
  • I agree with @Jocelyn and if you're worried about security, you could always just substitute names/labels (so long as you know the difference). – mason81 Aug 02 '12 at 15:12
  • So you just want to create a SELECT query that will pull out the "file" column from your table and put all rows into one array? – mason81 Aug 02 '12 at 15:13
  • 1
    http://en.wikipedia.org/wiki/Select_%28SQL%29 ? – Marc B Aug 02 '12 at 15:14
  • I am not worried about security at all :), just there is nothing to post, I am seeking for **select**, as I said I do not know how to explain more my issue/problem. Just try to understand from provided (exampled) information I posted here. – Kyslik Aug 02 '12 at 15:15

5 Answers5

1

Sounds like you are trying to get the unique (distinct) values for file from this table?

To do that you would use the following query

SELECT DISTINCT file from table_name
Mike Brant
  • 70,514
  • 10
  • 99
  • 103
1
SELECT t1.file as `Files` from table as t1 group by Files

This query is very simple you should learn to use sql.

Muhammad Raheel
  • 19,823
  • 7
  • 67
  • 103
1

It sounds like you want to

SELECT distinct(file) FROM mytable;

and then use

mysql_fetch_array()

something like that:

$result=mysql_query("SELECT distinct(file) FROM mytable");
$arr=array();
while($row = mysql_fetch_array($result)){
    $arr[] = $row[0];
}
Gryphius
  • 75,626
  • 6
  • 48
  • 54
1

try this:

$dbc = mysql_connect(SERVER, USERNAME, PASSWORD);
mysql_select_db($dbc, DATABASE);

$query = "SELECT DISTINCT `file` FROM `myTable`";
$result = mysql_query($dbc, $query);
John Woo
  • 258,903
  • 69
  • 498
  • 492
1

It looks like just want to pull all the values from the 'file' column and have them in one array. Try this:

// define your database connection in the
// $SERVER, $USERNAME, $PASSWORD, and $DATABSE variables

$link = mysql_connect($SERVER, $USERNAME, $PASSWORD);
mysql_select_db($link , $DATABASE);

// I don't know what you're table name is, so put it in place of 'myTable'
$sql= "SELECT file FROM `myTable` GROUP BY file";
$result = mysql_query($link, $sql);

That will grab only the 'file' column for all rows in the table, then you would need to loop through them to get the results into one array:

$files_array = array();
while($result && $row = mysql_fetch_assoc($result)){
    $files_array[] = $row['file'];
}

This should output the resulting array you are looking for.

mason81
  • 1,730
  • 2
  • 18
  • 33