vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Coding advise about adding to a db column? (https://vborg.vbsupport.ru/showthread.php?t=92331)

Mr Blunt 07-19-2005 08:24 PM

Ahhh, so the periods basically join your 3 "seperate strings" in the last example, one of which doesn't use double quotes since it's a var .... and those joining periods never get put into the actual saved string.

It's sinking in I think.

So if I declare an array key with $var['keyname'], and I come across a place where I'd rather call it with a simple $var[keyname], will it fly in most situations or must I do something stupid like $var[keyname] = $var['keyname'] beforehand? .... in which case it would probably be best to just use a new keyname to distinguish the difference?

I guess the reason I'm getting so technical is that I'm afraid of using non-arrayed variables as I don't want to conflict with anyone elses vars .... sooo one of my goals, as you might notice from my php file, was to try and handle all my vars from mainly one single array named "whodl" (3 really, but who's counting LOL).

Part of me says I'm going too far since it's a self contained webpage being displayed one time, and since control isn't going back to the origin page, I should be able to declare just about any simple (non-array) var that I want .... but then the inexperience in me thinks that's sloppy code so I've taken the long route so far.

Marco van Herwaarden 07-20-2005 03:38 AM

Quote:

Originally Posted by Mr Blunt
So if I declare an array key with $var['keyname'], and I come across a place where I'd rather call it with a simple $var[keyname], will it fly in most situations or must I do something stupid like $var[keyname] = $var['keyname'] beforehand? .... in which case it would probably be best to just use a new keyname to distinguish the difference?

You don't need to declare the version without the quotes. It will fail however if you have defined a constant with the same name as your keyname.

I even in a seperate script prefix most of my var's (since you are also including standard vB scripts, there could still be a name conflict even in a standalone script).

Mr Blunt 07-29-2005 09:47 PM

Just a follow-up....

Thank you BIGTIME for the help here.
I finished a beta copy of my script.
I'll leave the old code here, but it shouldn't be used by anyone.
Maybe someone else will learn from comparing this vs. that.


https://vborg.vbsupport.ru/showthread.php?t=93167


I don't know if anyone is up for it, but I'd sure love to have someone double check my work. I feel pretty confident, but between a ton of rewrites and a wireless keyboard that sometimes skips a character LOL ... another set of eyes to check me would be awesome because I DO care about the people who install my products.

And if anyone does check it out .... I'm up for any suggestions, ideas, and or little coding tips if you feel like sharing them with me.

Mr Blunt 08-24-2005 06:13 AM

Somewhat important follow-up.
The code examples above don't reflect UNSIGNED integer values.
vBulletin uses unsigned for these 4 INT values, so I should too.
PHP Code:

    $db->query("CREATE TABLE " TABLE_PREFIX "blunts_whodownloaded_ip (
        blunts_whodownloaded_ipid INT(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
        userid INT(10) UNSIGNED NOT NULL default 0,
        username VARCHAR(100) NOT NULL default '',
        filename VARCHAR(100) NOT NULL default '',
        fileid INT(10) UNSIGNED NOT NULL default 0,
        ipaddress VARCHAR(15) NOT NULL default '',
        alt_ip VARCHAR(15) NOT NULL default '',
        dateline INT(10) UNSIGNED NOT NULL default 0
    )"
); 

Here's a quote from dev.mysql.com
http://dev.mysql.com/doc/mysql/en/numeric-types.html
Quote:

All integer types can have an optional (non-standard) attribute UNSIGNED. Unsigned values can be used when you want to allow only non-negative numbers in a column and you need a bigger upper numeric range for the column.

As of MySQL 4.0.2, floating-point and fixed-point types also can be UNSIGNED. As with integer types, this attribute prevents negative values from being stored in the column. However, unlike the integer types, the upper range of column values remains the same.
And from the same thread:
Quote:

For example, the range of an INT column is -2147483648 to 2147483647. If you try to insert -9999999999 into an INT column, MySQL clips the value to the lower endpoint of the range and stores -2147483648 instead. Similarly, if you try to insert 9999999999, MySQL clips the value to the upper endpoint of the range and stores 2147483647 instead.

If the INT column is UNSIGNED, the size of the column's range is the same but its endpoints shift up to 0 and 4294967295. If you try to store -9999999999 and 9999999999, the values stored in the column are 0 and 4294967296.

When a floating-point or fixed-point column is assigned a value that exceeds the range implied by the specified (or default) precision and scale, MySQL stores the value representing the corresponding end point of that range.
In a nutshell .... Not only does unsigned not allow a negative number to be inserted, but an unsigned column allows for DOUBLE the amount of possible positive integer values than a signed column .... unless floating point numbers are involved.

Just trying to help the next guy....
:D

Marco van Herwaarden 08-24-2005 10:59 AM

Yes that is the reason some fields are defined as unsigned.


All times are GMT. The time now is 04:58 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03754 seconds
  • Memory Usage 1,738KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete