Unless you're using a system where NULL isn't 0 or 1, and a ! wouldn't normalize it either way...
gms8994
@gms8994
Best posts made by gms8994
Latest posts made by gms8994
-
RE: How to invert a boolean
-
Storage of categories
Here's the code I've been dealing with for the past few weeks:
14:28:49 (9) > describe bg_listings; +-------------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | cust_id | int(11) | NO | MUL | 1 | | | category | varchar(255) | YES | | NULL | | | cat_id | int(11) | YES | | 0 | | +-------------------------+--------------+------+-----+---------+----------------+
The rest of the table is of no concern. Here's a bit of data stored in bg_listings:
14:30:47 (10) > select * from bg_listings where id = 280\G
*************************** 1. row ***************************
id: 280
cust_id: 228
category: xCustomer Feedback,xMystery Shopping,xOnline Services
cat_id: 0
1 row in set (0.00 sec)Please note that this table is not a view, this is the actual data. Then we go to the code:
function getAltCatTitle($names){
global $db,$SITE;
$titles = array();
$names = str_replace(',','|',str_replace(',x',',',preg_replace('/^x/','',$names)));
$sql = "SELECT cat_name as title FROM bg_categories WHERE cat_name REGEXP '^.({$names}).$'";
foreach($db->get_results($sql) as $title) array_push($titles,trim($title->title));
$titles = implode(", ",$titles);
return $titles;
}
and$catfilter = "(category REGEXP '^x".$cat_name."$' OR category LIKE '% ,x".$cat_name.",%' OR category REGEXP '^x".$cat_name.",' OR category REGEXP ',x".$cat_name."$')";
and
$linktocat = preg_replace("/^x/", "", $linktocat);
and
if($cid = $db->get_row("SELECT cat_id, parent_id FROM bg_categories WHERE cat_name = '$linktocat' AND site_id = $SITE",ARRAY_N)) {
Seriously, who's idea was it to store all of the categories in a single, character field, and have them all prepended by 'x'?
-
RE: Database without the database
Unfortunately, we actually have a table column that stores a CSV data :(
-
Database without the database
I'm trying to determine why my terminal is only displaying one column of data. There's a file named "marketplace_storefronts_client_products_moreinfo.htm". Please note the extension. There's nothing in Apache config stating that htm should be parsed by PHP. However, within this file is the following:
$i = $_GET[id];
$file = fopen('prod',"r");
$id = 0;
while (! feof($file)) {
$string = fgets($file);
if(preg_match("/$i/", $string)) {
$arr = explode("\t",$string);
if($arr[0] == $i) $id = $arr[1];
if($id > 0) break;
}
}
fclose($file);Note now that we're opening a file named 'prod'. This file contains 548 lines like the following:
3671 266
1000 224
1032 96
1033 100This file is used to redirect a browser request to another page. This file is read and parsed, one line at a time, *every* single time the browser requests the page that redirects here. Or, it would, if it weren't being returned directly to the browser :(
-
Javascript Trim
So convoluted:
function trim(s) {
while (s.substring(0,1) == ' ') {
s = s.substring(1,s.length);
}
while (s.substring(s.length-1,s.length) == ' ') {
s = s.substring(0,s.length-1);
}
return s;
}It works, but thank god for regex:
function trim(s)
return s.replace(/(^\s*)|(\s*$)/,'');
} -
RE: The oldies are the goodies
@Michael Buschbeck said:
@ChZEROHag said:
(For those who don't get regex, the if succeeds if the string passed matches digits with a single optional decimal point anywhere but the last character).
Actually, the "if" condition also succeeds for all of the following, err, numbers:
- 123.
- 123.Michael
- 123%"&%/)=
...anything, as long as it starts with a decimal digit.
(I like how the
;}
looks like it's smiling at me.)Actually, it returns the matching part, try it:
perl -e 'print "123.Michael" =~ /^(\d+\.?\d*)|(^\.\d+)$/'
123.perl -e 'print "123%\"&%/)=" =~ /^(\d+\.?\d*)|(^\.\d+)$/'
123 -
RE: The oldies are the goodies
Why exactly is this a WTF? Maybe I don't get it, but they're checking to make sure it's a valid number, simple as that.