Page 1 of 1

having a function inside a table

Posted: Fri Oct 15, 2004 10:06 am
by dsdsdsdsd
hello;

I have the_table:
col_1 , col_2
---------------
cook , cook the cookies

I would like to place a function inside of col_2 that reads the value of col_1 and then inserts that value into the col_2:
col_1 , col_2
----------------
cook , col_1.value the cookies

such that:

Code: Select all

$result = mysql_query("select * from the_table");
while ($row=mysql_fetch_array($result , MYSQL_ASSOC) )
  { print $row[col_2];
  }
will output ==> cook the cookies;

is this feasible;

thanks
Shannon Burnett
Asheville NC USA

Posted: Fri Oct 15, 2004 10:23 am
by phpScott
my question is why? you can put what ever you want inside the column but I believe mysql doesn't support subqueries which is what it sounds like what you are trying to do.
I believe postgressehttp://www.postgresql.org/ does, as well as oraclehttp://www.oracle.com if you want complete overkill.

Posted: Fri Oct 15, 2004 12:22 pm
by Weirdan
why don't you want to use the following table:

Code: Select all

col_1
----
cook
and use it as:

Code: Select all

$result = mysql_query("select concat(col_1, ' the cookies') from the_table");
while ( list($sentence) = mysql_fetch_row($result) )
    echo $sentence;
?

Posted: Fri Oct 15, 2004 2:52 pm
by dsdsdsdsd
hello phpscott and weirdan; thanks for your responses;

the example I posted is a simplified situation; ultimately I will need to go into a cell and replace some string with some other string; there are several php things I could do to do pattern matches within the query result in order to find an identified placeholder in a table;

however as with any pattern matching there is a large potential for problems; for instance if you are looking for 'cook' a simple pattern match would find 'cook' and also the c-o-o-k in 'cookies';

I cannot concat because I have no control over the table values nor any control over what a user may want to change a value to;

so it seems that the best solution is to embed a function that refers to another table cell;

thanks Shannon