MySql variable ? please.
Firefox Wins Offline
Member
***
Posts: 164
Joined: Mar 2008
Post: #1
MySql variable ? please.
Simple way (without details)
In a MySql table is it possible to use the value of a field as part of the default value of another field?  Biggrin
^^^

OK, here is exactly what I'm looking to do:
1) `my_link` is a new field added to `mybb_forums` table
2) A sample entry is,

Code:
<a href="http://example.com/bb/forumdisplay.php?fid=2">Go To Sample Forum</a>

so when this field (from the row with fid=2) is retrieved, there is a link created to the forum w/ fid=2.**

3a) What is the best (automated) way to create the entries into this field?
3b) I know how to do it with php, but I'm looking for something more "direct."

Edit:
These next sections (below) "probably will not work",
http://dev.mysql.com/doc/refman/5.0/en/d...http://dev.mysql.com/doc/refman/5.0/en/data-type-def
is there a way to do something similar?


3c) If the default value of the field is set to (for example),

Code:
<a href="http://example.com/bb/forumdisplay.php?fid=%fid%">Go To Sample Forum</a>

(or something similar)
3d) Will MySql 'retrieve' this value %fid% (or whatever format will work), from the (newly created) 'fid' field and use that value in the `linkto` field (in the "default sample code?")

  • Like in an Excel spreadsheet, how do I "grab" a value from a different column in the same row?

Searching Google for "MySql variable" mostly gives results related to variables used in queries, and / or user defined "session" variables.

A) How can I use a variable (based on a field value) directly in a MySql table?
and
B) Can the same method work as part of a default value? (Probably not)

Thank you very much


...

..

.
**ps. I do know:
Normally this code (for example)

Code:
<a href="http://example.com/bb/forumdisplay.php?fid=2">Go To Sample Forum</a>

could easily be created "on the fly", but I have a situation where it would be really useful to pull the above example straight out of the db.

(This post was last modified: 09-09-2010 08:05 AM by Firefox Wins.)
09-08-2010 06:49 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: MySql variable ? please.
If I understand what you're saying, then no.  Default values must be constant and cannot be variable in any way.

My Blog
09-08-2010 07:53 PM
Find all posts by this user Quote this message in a reply
Firefox Wins Offline
Member
***
Posts: 164
Joined: Mar 2008
Post: #3
RE: MySql variable ? please.
(09-08-2010 07:53 PM)ZiNgA BuRgA Wrote:  If I understand what you're saying, then no.  Default values must be constant and cannot be variable in any way.

OK... (when they are not default values)
Can variables be used at all "inside" a table (i.e. similar to Excel), ?
  • Can a field contain a string which includes a variable that is defined by another field?
If Yes, what is the format for MySql variables (like_%status, like_%status%, etc)
Thanks again.
(This post was last modified: 09-08-2010 08:51 PM by Firefox Wins.)
09-08-2010 08:48 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: MySql variable ? please.
No, databases give out what is put into them.  It's not like Excel where you can have separate input (format) and output (text) values.
You can generate calculated values in a SELECT statement, but it cannot be stored (dynamically at least).
Eg

SQL Code
SELECT CONCAT("abc", fid, "def") AS my_field FROM mybb_forums;


My Blog
(This post was last modified: 09-08-2010 09:21 PM by ZiNgA BuRgA.)
09-08-2010 09:19 PM
Find all posts by this user Quote this message in a reply
Firefox Wins Offline
Member
***
Posts: 164
Joined: Mar 2008
Post: #5
RE: MySql variable ? please.
Good to know for certain.
Thanks, Zinga  Smile
09-08-2010 09:22 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: