David Blomstrom wrote:

--- David Rodman <[EMAIL PROTECTED]> wrote:

You mean something like this?

mysql> create table nads(
   -> state varchar(50),
   -> url varchar(100));
Query OK, 0 rows affected (0.03 sec)


OK, you're creating a table named "nads," with fields
named "state" and "url," right?

Yes. As an example. You said you had a table with fields for state name and state URL, but you didn't provide the name of the table or the fields, so David Rodman made an example table to illustrate how his suggestion works.


mysql> insert into nads values('California',
'http://www.california.gov');
Query OK, 1 row affected (0.00 sec)

mysql> insert into nads values('Florida',
'http://www.florida.gov');
Query OK, 1 row affected (0.00 sec)

Here he puts two example rows into the example table.

I'm a little confused here. I'm slightly more familiar
with manipulating PHP than MySQL. It looks like your
suggestion is a permanent fix. It just occurred to me
that it would be nice if I had the option of
displaying Florida as plain text or as a link.

I'm not sure what you mean by permanent fix, but you are again confusing data with how it is presented. You have a states table which has a column for the state name, a column for the state URL, and columns for other state data. You display data from that table as you see fit by writing an appropriate SELECT statement. If you want a list of states linked to their web pages, you


  SELECT CONCAT('<A HREF="', url, '">', state,'</A>') FROM states;

See, you sre pulling values from the url and state columns of the states table, and ***displaying*** them concatenated with some other text, so the result is the state name linked to the URL.

If you want a list of states with no links, then you don't request the url column in your SELECT, and you have no need of CONCAT:

  SELECT state FROM states;

But if I do this, Florida will always be linked,
right? Also, it looks like you have to do this

SELECT does not link columns in your DB. It retrieves data from your DB. The output is determined by what you ask for.


operation for each row - California, Florida, etc. Is
there a simple command that merges two entire columns?

You are not merging columns. You are **displaying** the values from two columns in a single string. No change has been made to the underlying data.


Like every other SELECT statement, the two I gave above will print results for every row in table states. If you want the same format results, but only for certain states, you must add a WHERE clause which restricts the results to what you want.

Print the state name linked to its URL, but only for California:

  SELECT CONCAT('<A HREF="', url, '">', state,'</A>')
  FROM states
  WHERE state = 'California';

Print the state name only (no link), but just for Alaska and Alabama:

  SELECT state FROM states WHERE state IN ('Alaska','Alabama');

Or is that what you're doing here?:


mysql> SELECT CONCAT('<A HREF=', url, '>', state,
'</A>') as link from nads;
+--------------------------------------------------+
| link                                             |
+--------------------------------------------------+
| <A HREF=http://www.california.gov>California</A> |
| <A HREF=http://www.florida.gov>Florida</A>       |
+--------------------------------------------------+


So this is the "concat" method, another posted alluded
to. That's the term I remember seeing in another
thread. Thanks.

I would like to respectfully suggest that you modify your strategy. You are working on a project that is fundamentally about storing and retrieving data from a database in mysql. You've been asking questions since January, most of which boil down to "How does mysql work?", which is the one piece of the puzzle which, by your own admission, you have steadfastly avoided studying. Considering that the success or failure of your project rests on getting mysql to do what you want, I think it is time you overcame your reluctance. Find some web tutorials or get Paul DuBois' excellent book and start learning mysql with the mysql client program. It is easy to have PHP perform a mysql query once you've figured out what the right query should be. Given the nature of your questions, I think you'd be much further along in your project now if you had started with that, but it's never too late to start.


Michael


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to