MyBB Hacks

Full Version: MySql variable ? please.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.

If I understand what you're saying, then no.  Default values must be constant and cannot be variable in any way.
(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.
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;

Good to know for certain.
Thanks, Zinga  Smile
Reference URL's