[PHP] Re: Select from 24 tables
Dave Carrera wrote: Hi List, How do I select data from 24 table in my database. Each one is identical in structure layout being Id,name,list I want to select where like $_POST[var] from a form all of the tables but I am having trouble :( I thought making a var string like $string = table1,table2,table3,.; And doing (select * from $string where list like \%$_POST[var]%\); Would work but I get a MySql error which say Column: 'list' in where clause is ambiguous I am stumped so I ask the list for help or advise please. Any advise is very much appreciated and I thank you in advance for any help or pointers. Thank you Dave C Try constructing a query that looks like this... select 't1' as source, t1.* from t1 where t1.list like $criteria union select 't2' as source, t2.* from t2 where t2.list like $criteria union select 't3' as source, t3.* from t3 where t3.list like $criteria union ... select 't24' as source, t24.* from t24 where t24.list like $criteria ; This query can be created by 1. storing all the table names in an array 2. constructing the individual select portion using array_map() 3. combining all individual selects using join($selects, 'union') -- Richard A. DeVenezia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP, MySQL and Foreign Keys - relations()
Here is a helpful function for making sense of - foreign keys: which columns of this table refer to primary key of another table - referential: which tables columns refer to the primary key of this table Presumes you are running MySQL with innodb tables. Tested with MySQL 4.1.1-alpha. function relations () { $statement = SHOW TABLE STATUS ; $res = mysql_query ($statement) or croak (mysql_error()); $meta = array(); while ($row = mysql_fetch_array($res)) { $bits = array_map ('trim', explode (';', $row['Comment'])); $name = $row['Name']; foreach ($bits as $bit) { if (!preg_match ('/\((.*)\) REFER (.*)/', $bit, $ab)) continue; $fk = array(); $fk ['columns'] = preg_split ('/\(|\)|,/', $ab[1]); $refers = array(); preg_match ('/(.+)\/(.+)\((.+)\)/', $ab[2], $x); $y = preg_split ('/,/', $x[3]); $refers['database'] = $x[1]; $refers['table'] = $x[2]; $refers['columns'] = $y; $fk ['refer'] = $refers; $meta[$x[1]][$name]['foreign_key'][] = $fk; $meta[$x[1]][$x[2]]['referential'][$x[3]][] = $name; } } return $meta; print 'pre'; print_r ($meta); print '/pre'; } The multi-level meta hash might look something like this: [ticketing] = Array ( -- data base [event] = Array ( -- table [foreign_key] = Array ( [0] = Array ( -- first foreign key [columns] = Array ( [0] = VenueId ) [refer] = Array ( [database] = ticketing [table] = venue [columns] = Array ( [0] = Id ) ) ) ) [referential] = Array ( [Id] = Array ( -- what tables refer to columns of this table (keyvalue will be comma separated string of column names if composite foreign key) [0] = eventseatclass [1] = price [2] = reserved [3] = ticket ) ) ) [venue] = Array ( -- table, no foreign keys [referential] = Array ( [Id] = Array ( -- column id of this table is referred to by 5 other tables [0] = event [1] = paymenttype [2] = seat [3] = seatclass [4] = venueuser ) ) ) ... -- Richard A. DeVenezia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Shared session ? (frames application)
I am wondering if it is possible to let two or more scripts share a common session id ? I am guessing not, but would like to be proved wrong. This is the situation cut down about as small as I could make it. Five files: index.php, login-form.inc, frames.inc, left.php, main.php index.php - ? session_name('cesh'); session_start(); $function = $_POST['function']; if (!isset($function) || $function='') { include login-form.inc; die; } //test, user always valid function validuser () { return true; } if ($function == 'login') { if (!validuser($_POST['user'], $_POST['pass'])) { include login-form.inc; die; } } $_SESSION['user'] = $user; $_SESSION['foo'] = 'bar'; include frames.inc; ? - login-form.inc - htmlbody form method=POST user input type=text name=userbr pass input type=text name=passbr input type=submit value=Login input type=hidden name=function value=login /body/html ? die; ? - frames.inc - ? // get var used to pass session id to left and main scripts $sid = SID; $src = EOF frameset cols=350,* rows=* frameborder=1 frame src=left.php?$sid name=left frameborder=1 frame src=main.php?$sid name=main frameborder=1 noframes body bgcolor=#FF pphpMyAdmin is more friendly with a bframes-capable/b browser./p /body /noframes /frameset EOF; $src = str_replace(\n, , split ( \n, $src )); ? html script type=text/javascript !-- ? foreach ($src as $line) { echo document.writeln('${line}');\n; } ? //-- /script noscript ? foreach ($src as $line) { echo ${line} . \n; } ? /noscript /html - left.php - htmlbody Leftbr Is it possible to access (read/write/set/unset) the variables of session ?=$_GET['cesh']?br ? /body/html - main.php - htmlbody Mainbr Is it possible to access (read/write/set/unset) the variables of session ?=$_GET['cesh']?br ? /body/html - -- Richard A. DeVenezia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] adult content censoring
Richard Davey wrote: and that's it - I pass any string I need to this whenever someone posts a message, subject, etc etc and it hasn't failed me yet :) (unless the bad word isn't in your list of course!) To guard against 'lame' impressions of words to be filtered, you might also check all combinations of variations of lettering of each undesired word. You can do this programmatically without have to list them all. i.e. l replaced with digit 1 or any l looking characters with byte code 128 o replace with digit 0 or any o looking characters with byte code 128 f replaced with any f looking characters with byte code 128 Read a spample erectile dysfunction or pain medication mail to get the idea. Definition: spample - Spam samples; a sampling of spam. -- Richard A. DeVenezia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] SQL like processing on array of keyed arrays ?
Suppose I don't have access to a database server. I have any indexed array of like keyed arrays, essentially mimicing a database table. Are there any libraries or functions that I can use to 'query' the array in a SQL like manner ? e.g. $data = array (array(a=1,b=2,c=3) ,array(a=2,b=3,c=4) ,array(a=3,b=4,c=5) ); I would like to be able to do $subset = arraysql_query ($data, where a=3); instead of $subset = array(); foreach ($data as $dat) { if ($dat['a'] = 3) $subset[]=$dat; } -- Richard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] [4.3.4] Can't ksort a subarray
I have this little code. I want all arrays sorted case insensitive key order, but only the first dimension gets key sorted properly Thanks -- Richard A. DeVenezia ? $A = array ( C = array ( x = 1, Z = 2, y = 3) , b = array ( z = 1, Y = 2, x = 3) , A = array ( z = 1, X = 2) ); print_r ($A); // sort dim1 uksort ($A, strcasecmp); print_r ($A); // sort each dim2 while (list($key,$dim2) = each ($A)) { uksort ($dim2, strcasecmp); } print_r ($A); ? It comes out Array ( [A] = Array ( [z] = 1 [X] = 2 ) [b] = Array ( [z] = 1 [Y] = 2 [x] = 3 ) [C] = Array ( [x] = 1 [Z] = 2 [y] = 3 ) ) I want Array ( [A] = Array ( [X] = 2 [z] = 1 ) [b] = Array ( [x] = 3 [Y] = 2 [z] = 1 ) [C] = Array ( [x] = 1 [y] = 3 [Z] = 2 ) ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [4.3.4] Can't ksort a subarray
Red Wingate wrote: while (list($key,$dim2) = each ($A)) { uksort ( $A[ $key ] , strcasecmp); } print_r ($A); $dim2 will not change $A[ $key ], so you will have to change your script to alter them directly. -- red Like thus: uksort ($myArray, strcasecmp); foreach (array_keys($myArray) as $key) { $dim = $myArray[$key]; uksort ($dim, strcasecmp); } address operator is hard to come by in the docs I have (PHP.chm) -- Richard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Any security issues with preg_match and web form input ?
I accept a regex search term posted from a form, but I use $_REQUEST, so a person could throw the search term on the url if they wanted to. Am I open to any security breaches ? $search_term = isset ($_REQUEST ['search']) ? $_REQUEST ['search'] : ''; if ($search_term != ) { ... $contents = join (, file($file)); if (preg_match (/$search_term/i, $contents)) { } ... } Thanks, -- Richard A. DeVenezia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] HTML Template, PHP, Javascript PATH_INFO
Help: --- problem My page generated via a template can't find some javascript. setup I am hosted on Apache 1.* I have a folder containing many *.html containing content which I want to be displayed in another style of page. Suppose there is foo/ foo/content1.html ... foo/contentN.html foo/content1.js foo/template.html foo/js1.js foo/js2.js foo/slick.css foo/slick.php The content might have it's own style and javascript parts template.html --- HTML HEAD TITLE:title:/TITLE LINK REL=stylesheet HREF=slick.css TYPE=text/css SCRIPT SRC=js1.js LANGUAGE=JavaScript/SCRIPT SCRIPT SRC=js2.js LANGUAGE=JavaScript/SCRIPT :script: :style: :link: /HEAD BODY DIV ID=logoLogo .../DIV DIV ID=main DIV ID=linksSCRIPT/* navbar('js') *//SCRIPT/DIV DIV ID=content:content:/DIV /DIV DIV ID=copyrightCopyright .../DIV /BODY /HTML --- slick.css --- div#logo { background: #AAA } div#content { background: #DDD } div#links { background: #CCC } div#copyright { background: #EEE } --- content1.html --- HTML HEAD TITLEContent 1/TITLE SCRIPT SRC=content1.js LANGUAGE=JavaScript/SCRIPT /HEAD BODY H1Content is king/H1 SCRIPT LANGUAGE=JAVASCRIPT helloFromContent1() /SCRIPT /BODY /HTML --- content1.js --- function helloFromContent1 () { document.write ('PHello from content1.js/P') } --- js1.js --- alert ('js1 here') --- js2.js --- alert ('js2 here') --- slick.php --- ? list ($slash, $page) = explode ('/', $HTTP_SERVER_VARS['PATH_INFO']); if (!file_exists ($page)) { header(HTTP/1.0 404 Not Found); echo (HTMLHEADTITLE/TITLE/HEADBODYP$page not found./P/BODY/HTML); return; } $template = 'template.html'; $template = implode (, file ($template)); $source = implode (, file ($page)); preg_match (|HEAD.*?(.*)?/HEAD|is,$source, $head); // i insensitive, s newlines are a character preg_match (|TITLE.*(.*)?/TITLE|is, $head[1], $title); preg_match_all (|(SCRIPT.*?.*?/SCRIPT)|isU,$head[1], $script); // U ungreedy preg_match_all (|(STYLE .*.*/STYLE)|isU, $head[1], $style); preg_match_all (|(LINK .*)|isU, $head[1], $link); preg_match (|BODY.*?(.*)/BODY|is, $source, $content); $title = isset($title [1]) ? $title[1] : ''; $script = isset($script [1]) ? implode ($script[1]) : ''; $style = isset($style [1]) ? implode ($style [1]) : ''; $link = isset($link [1]) ? implode ($link [1]) : ''; $content= isset($content[1]) ? $content[1] : ''; $html = preg_replace ( array (/:title:/, /:style:/, /:script:/, /:link:/, /:content:/ ) , array ( $title , $style , $script , $link , $content ) , $template ); echo $html; ? --- I can do - site.com/info/template.html and get two alerts - site.com/info/content1.html and see a new text under H1 - site.com/info/slick.php/content1.html and get neither alert nor new text. - instead I get 4 browser (IE) 'problem alerts', I presume - 1. for not finding js1.js - 2. for not finding js2.js - 3. for not finding content1.js - 4. for not finding helloFromContent1() function I don't want to change my SRC references to be site absolute, I want them relative. Any ideas how I should 'wrap' my content using php and get functioning pages ? Thanks -- Richard A. DeVenezia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTML Template, PHP, Javascript PATH_INFO
John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Richard A. DeVenezia wrote: [snip] I can do - site.com/info/template.html and get two alerts - site.com/info/content1.html and see a new text under H1 - site.com/info/slick.php/content1.html and get neither alert nor new text. - instead I get 4 browser (IE) 'problem alerts', I presume - 1. for not finding js1.js - 2. for not finding js2.js - 3. for not finding content1.js - 4. for not finding helloFromContent1() function I think you're confusing HTML. While the server understands slick.php/content1.html, HTML probably doesn't and is looking for slick.php/content1.html/js1.js (and the other files). I don't want to change my SRC references to be site absolute, I want them relative. Well, I'm glad that's what you want, but how about using it anyhow because it'll work. Like Chris said, you can use a function/variable to get the complete path so it's really no extra work for you. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com Thanks for the response. I figured out what was happening slick.php/content.html has a relative href js1.js which means the browser is going to do a get on slick.php/js1.js Thus, slick has to differentiate between html and non-html. If non-html, just echo back the file contents. slick changed to article, contentPath can be placed in folder out of webs way, or if in webs way .htaccess can restrict access to original form content. ? list ($slash, $page) = explode ('/', $HTTP_SERVER_VARS['PATH_INFO']); if ($page == '') { // just in case, make sure things start out right redirect ('/javascript/article.php/index.html'); return; } $contentPath = './content/'; $template = $contentPath . 'article-template.html'; /* $f = fopen ('c:\\temp\\article.log', 'a'); fwrite ($f, looking for $page.\n); fclose ($f); */ $page = $contentPath . $page; if (!file_exists ($page)) { header (HTTP/1.0 404 Not Found); echo HTMLHEADTITLE/TITLE/HEADBODYP$page not found./P/BODY/HTML; return; } $source = implode (, file ($page)); // server does not want html, just send the stuff back unaltered. if (!preg_match(/html$/, $page)) { echo $source; return; } // html!, rip out the pieces and replace into template page $template = implode (, file ($template)); preg_match (|HEAD.*?(.*)?/HEAD|is,$source, $head); // i insensitive, s newlines are a character preg_match (|TITLE.*(.*)?/TITLE|is, $head[1], $title); preg_match_all (|(SCRIPT.*?.*?/SCRIPT)|isU,$head[1], $script); // U ungreedy preg_match_all (|(STYLE .*.*/STYLE)|isU, $head[1], $style); preg_match_all (|(LINK .*)|isU, $head[1], $link); preg_match (|BODY.*?(.*)/BODY|is, $source, $content); $title = isset($title [1]) ? $title[1] : ''; $script = isset($script [1]) ? implode ($script[1]) : ''; $style = isset($style [1]) ? implode ($style [1]) : ''; $link = isset($link [1]) ? implode ($link [1]) : ''; $content= isset($content[1]) ? $content[1] : ''; $html = preg_replace ( array (/:title:/, /:style:/, /:script:/, /:link:/, /:content:/ ) , array ( $title , $style , $script , $link , $content ) , $template ); echo $html; function redirect($to) { $schema = $_SERVER['SERVER_PORT']=='443'?'https':'http'; $host = strlen($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:$_SERVER['SERVER_NAME']; if (headers_sent()) return false; else { header(Location: $schema://$host$to); exit(); } } ? -- Richard A. DeVenezia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php