Jump to content

pallevillesen

Members
  • Posts

    135
  • Joined

  • Last visited

Everything posted by pallevillesen

  1. It\'s not your test, it\'s your access that is the problem... You probably have a special password set for the user pj@localhost... That\'s the error anyway... Try and connect with mysql -h localhost -u pj -p buzz from a terminal window... And/Or browse the mysql:user table... Hope this helps, P.
  2. Yes... You are not inserting the bal_id.... P.
  3. If your ID field is auito_increment then select artist, title from table order by id desc limit 5; will give you the 5 records with the highest ID numbers P.
  4. $sql = \"SELECT userid, userpassword, username, useremail FROM $user_tablename WHERE userid = \'$userid\' OR useremail = \'$email\'\"; If you get 1 row - same person 2 rows - userid allready taken, email allready taken - by different persons. This is only valid IF you check for a unique userid, i.e. that you don\'t allow two persons to have the same userid (which I assume you do). Reading your post again, I think you want to check that a given userid and email match the SAME RECORD ? Then your original solution is the correct one: $sql = \"SELECT userid, userpassword, username, useremail FROM $user_tablename WHERE userid = \'$userid\' AND useremail = \'$email\'\"; This returns only one row, if the submitted userid and email are in the same record, if NOT it will return zero rows! P.
  5. Hmm... that is going to be ugly. Let\'s start slowly: 1. Top level parents select ID where parent IS NULL; returning ID 1 only... Now join this with the table again creating NULL values for all first level children... JOIN ON PARENT! Returning ID name parent description ID2 1 VOLVO (NULL) Volvo NULL 3 70 2 Volvo S70 NULL 6 C 1 Volvo C? 1 2 S 1 Volvo S? 1 5 60 2 Volvo S60 NULL 4 60 6 Volvo C60 NULL 2. 1st level children select ID from joined where ID2 IS NOT NULL; Anf then you may work your way through like this.... BUT: I don\'t like this solution, but I fear there is no simple nicer solution. You want subselects but they do not exist in mysl 3.23 - try version 4 or use temporary tables like crazy... It would be a lot easier to grab the result and then parse it in php to get what you want. P.
  6. Well.... select 1+2+3+4+5 AS result; does work fine enough.... So select (a+b+c) as result from table; should work as well.... check your syntax and if you are absolutely sure that there is something wrong, then please post some more info on tables and variables... But you are using the correct syntax. It should work. P.
  7. Hi, I don\'t think you\'re right, since your query still have to look through the entire index. But a: select id where php = \'5\'; would be about 1/5 of the normal time, since the index would be used. You should probably have another coloumn \'php2\' widht random values from 1 to 5 and then see the speed difference to find specific rows, i.e. 1. where php = \'5\' would be a LOT faster than 2. where php2 = \'5\' because php2 wasn\'t indexed. Maybe I\'m wrong - I\'m not strong on indexes - but look around in http://www.mysql.com/doc/en/MySQL_indexes.html P.
  8. pallevillesen

    Average?

    I meant that in the VERY SAME statement you must specify the values first and then the calculations after... like insert into blabla (col1, col2, col3) values (4,4, average(col1, col2)); P.
  9. Hi Everybody... I just saw that some clever guy edited his question and changed the subject to [RESOLVED]: dsjfhdafd... That would make life a lot easier in here, and it would save tons of time, so I would suggest that people start doing this - when they feel they have an answer, they should edit their original post. P.
  10. Nice.... Here\'s my sql class definition: So I use something like: $sql->query("secret bioinformatics content... "); for ($i = 0; $i < $sql->rows; $i++) { $sql->Fetch($i); printf("<tr> <td><A href=\'getpromotor.php?stable_id=%s\' target=\'_promotorview\'>Get promotor</a></td> <td><A href=\'http://www.ensembl.org/Homo_sapiens/geneview?gene=%s\' target=\'_geneview\'>%s</a></td> <td>%s</td> <td>%s</td> <td>%s</td> </tr>",$sql->data[0], $sql->data[0], $sql->data[0], $sql->data[1], $sql->data[2], $sql->data[3]); } mysqlbase.inc.php: P. <? /* * Utility routines for MySQL. */ class MySQL_class { var $db, $id, $result, $rows, $data, $a_rows; var $user, $pass, $host, $errorno; /* Setup selects host, username and password */ function ServerConnect ($host, $user, $pass) { $this->host= $host; $this->user = $user; $this->pass = $pass; } /* Create select database to work on and connects to it */ function Create ($db) { $this->db = $db; $this->id = @mysql_pconnect($this->host, $this->user, $this->pass) or MySQL_ErrorMsg("Unable to connect to MySQL server: $this->host : \'$SERVER_NAME\'"); # Call select database function, since we found the server $this->SelectDB($db); } function SelectDB ($db) { @mysql_select_db($db, $this->id) or MySQL_ErrorMsg ("Unable to select database: $db"); } # Use this function is the query will return multiple rows. Use the Fetch # routine to loop through those rows. function Query ($query) { $this->result = @mysql_query($query, $this->id) or MySQL_ErrorMsg ("Unable to perform query: $query"); $this->rows = @mysql_num_rows($this->result); $this->a_rows = @mysql_affected_rows($this->id); } # Use this function if the query will only return a # single data element. function QueryItem ($query) { $this->result = @mysql_query($query, $this->id) or MySQL_ErrorMsg ("Unable to perform query: $query"); $this->rows = @mysql_num_rows($this->result); $this->a_rows = @mysql_affected_rows($this->id); $this->data = @mysql_fetch_array($this->result) or MySQL_ErrorMsg ("Unable to fetch data from query: $query"); return($this->data[0]); } # This function is useful if the query will only return a # single row. function QueryRow ($query) { $this->result = @mysql_query($query, $this->id) or MySQL_ErrorMsg ("Unable to perform query: $query"); $this->rows = @mysql_num_rows($this->result); $this->a_rows = @mysql_affected_rows($this->id); $this->data = @mysql_fetch_array($this->result) or MySQL_ErrorMsg ("Unable to fetch data from query: $query"); return($this->data); } function Fetch ($row) { @mysql_data_seek($this->result, $row) or MySQL_ErrorMsg ("Unable to seek data row: $row"); $this->data = @mysql_fetch_array($this->result) or MySQL_ErrorMsg ("Unable to fetch row: $row"); } function Insert ($query) { $this->result = @mysql_query($query, $this->id) or MySQL_ErrorMsg ("Unable to perform insert: $query"); $this->a_rows = @mysql_affected_rows($this->id); } function Update ($query) { $this->result = @mysql_query($query, $this->id) or MySQL_ErrorMsg ("Unable to perform update: $query"); $this->a_rows = @mysql_affected_rows($this->id); } function Delete ($query) { $this->result = @mysql_query($query, $this->id) or MySQL_ErrorMsg ("Unable to perform Delete: $query"); $this->a_rows = @mysql_affected_rows($this->id); } function Getsql_error() { $this->error[0] = mysql_errno(); $this->error[1] = mysql_error(); return $this->error; } function ServerDisconnect () { mysql_close($this->id); } function Freemem() { mysql_free_result($this->result); } /* End CLASS definition */ } /* ******************************************************************** * MySQL_ErrorMsg * * Print out an MySQL error message * */ function MySQL_ErrorMsg ($msg) { # Close out a bunch of HTML constructs which might prevent # the HTML page from displaying the error text. // echo("</ul></dl></ol>n"); //echo("</table></script>n"); # Display the error message $text = "<font color="#ff0000"><p>Error: $msg :<br>"; $text .= mysql_error(); $text .= "</font><p>"; echo ($text); // die ($text); } ?>
  11. EDIT: Whoups.... the calculation fucks it up... You should convert the created_date to seconds first... Hang on... GOT IT... Use UNIX_TIMESTAMP(date) to convert to seconds.... /EDIT Try: expr BETWEEN min AND max SELECT * from userlist WHERE ( UNIX_TIMESTAMP(created_date) BETWEEN (max(UNIX_TIMESTAMP(created_date)) - (7 * 24 * 60 * 60)) AND max(UNIX_TIMESTAMP(created_date)) ); P.
  12. pallevillesen

    Average?

    If you just insert the other values before the calculations, then it can be done in sql. Like INSERT (\'Start\' = 5, \'End\' = 8, \'Distance\' = (End-Start) (this is pseudo pseudo sql... check the correct synax in the manual): Here\'s a little help from the manual: # An expression may refer to any column that was set earlier in a value list. For example, you can say this: mysql> INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2); Check the syntax: http://www.mysql.com/doc/en/INSERT.html P.
  13. EDIT: Aaaargghhh. too late.... Please post your working code just for friday fun... P. /EDIT You\'re close... I\'m not good at OOP but this works: include("lib/pbMySQL.class.php"); $db = new pbMySQL; $db->pbMySQL_open("localhost","user","pass"); $db->pbMySQL_useDB("database"); $db->pbMySQL_query("SELECT * FROM pbn_news ORDER BY id DESC"); while($row=mysql_fetch_array($db->query)) { print $row[\'name\']."<br>rn"; } $db->pbMySQL_close(); function pbMySQL_query($query) { if(!isset($this->conn) || !isset($query)) { print "Error : argument(s) missing.<br>rn"; } else { $this->query = mysql_query($query,$this->conn) or die("Error : query failed.<br>rnmysql said: <i>".mysql_error()."</i><br>rn"); } } I changed a few bits in both parts...
  14. Ok, but if the design of table user1 and user2 and so on are identical, i.e. same number of coloumns, format etc. then it\'s a lot better to make one big table to hold this information. Then just make a single coloumn identifying the \"owner\" of the current row (the username). Otherwise you could quickly end up having a lot of tables, and you would need to allow create table permissions to your scripts. P.
  15. Ok, here\'s a function which returns all kinds of adresses: function showlinks($text){ // match any " word://word.word " $text = eregi_replace( "([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href="\\1://\\2\\3">\\1://\\2\\3</a>", $text); // match any " word.word " no @ or //: allowed $text = eregi_replace( "[[:space:]]([^[:space:]|//:|@]*)(.[^[:space:]]*)([[:alnum:]#?/&=])[[:space:]]", " <a href="http://\\1\\2\\3">\\1\\2\\3</a>", $text); // match email adresses $text = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href="mailto:\\1">\\1</a>", $text); return $text; } $text = "Welcome to our site, please visit http://www.biodyk.dk for information about our scubadiving or mail me palle@biodyk.nospam.dk or try www.biodyk.dk <p>"; echo $text; echo showlinks($text); P.
  16. Hi Guys, I agree to Aveach\'s solution, but the problem is that if the text is stored like: $text = \"Welcome to our site, please visit http://www.biodyk.dk for information about our scubadiving or mail me palle@biodyk.nospam.dk\"; And you want to find adresses like the biodyk.dk address above, highlight and format it correctly... And it gets worse, what is people don\'t write the http:// or the mailto: ? You could be really evil, parse all places with www.word.* until a space and words with a @ in them - let php check if it exists and if it does insert the formatting. (I don\'t think you can get php to check if a mail address is valid though. P.
  17. Basically this is not the best design. Make two tables: 1. Having the usernames called users 2. Having the 8 names and the username Like A: Billy Bob Thornton B: Billy Donald Billy Duck Billy Palle Bob Bush Bob Sadam and so on... To get Billys friends... select * from a left outer join b on a.user = b.user where a.user=\'Billy\'; P.
  18. Try this function (not mine, just found it at http://www.bjclark.com/code/linkmail.phps ) function show_links($text) { $ret = eregi_replace( "([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href="\\1://\\2\\3">\\1://\\2\\3</a>", $text); $ret = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href="mailto:\\1">\\1</a>", $ret); return($ret); } i.e. use echo show_links($text); P.
  19. IF it is only urls in the text it is pretty easy to add some <a href=.... stuff... If the links are in a block of text like: For more information please go to [url]http://palle.ninja.dk[/url] For more information please go to http://palle.ninja.dk You probably need to do a really fancy regular expression to catch them all and make no mistakes OR do like this site and add some tags to the text (like the URL /URL tags used above). I have a quick cheat sheet for reg.expression on the folowing url http://www.daimi.au.dk/~biopv/public/reg.exp.php it\'s not only for php, so if you\'re stuck, look around... But my guess would be something like /.*(http://[^s].[^s]).*/ Matches http://anything.anything stop at spacecharacter.. But needs at least one dot in the webaddress... You then need to make the correct replace string, which is not so easy, look around - you\'re probably not the first facing this problem... P. P.
  20. Nope.... I actually quite dislike them, but I couldn\'t figure out how to this is one long ugly sql statement (ahem.. that is in mysql, where subselects and full outer joins are nonexistent (in version 3.34))... And I was freaked out by the lack of results when googling for MYSQL FULL OUTER JOIN.... I think we could need a tutorial on temporary tables and what they are good for (i.e. subselects and outer joins tips and trick)... Anyone? P.
  21. I have two tables, a and b which contains the following: A: +----+ | id | +----+ | a | | b | | c | +----+ B: +----+ | id | +----+ | b | | c | | d | +----+ And I would like to do a search returning ALL rows from both tables. I.e. A B C D (Somebody might want something like A NULL B B C C NULL D Which is easy, but this example is the simplest. create temporary table t1unique as select a.id from a LEFT OUTER JOIN b on a.id = b.id where b.id IS NULL; This will get all rows with ONLY a value in table A. create temporary table t2unique as select b.id from a RIGHT OUTER JOIN b on a.id = b.id WHERE a.id IS NULL; This will get all rows with ONLY a value in table B. create temporary table t3 as select a.id from a, b where a.id = b.id; This will get all rows with matching values in A and B. INSERT INTO t3 select * from t1unique; INSERT INTO t3 select * from t2unique; Putting the first two queries into the third one.... select * from t3 order by id; Tadaa... drop table t1unique; drop table t2unique; drop table t3; Cleaning up. Ugly code, I know - but it\'s working. mysql> select * from t3 order by id; +----+ | id | +----+ | a | | b | | c | | d | +----+ 4 rows in set (0.00 sec)
  22. I just checked my notes about full join on mysql from earlier work. It is rarely used and NOT implemented in mysql v. 3.23 BUT IT IS IN mysql 4. I wrote that you may emulate a full join using \"two consequtive left joins, where one will be an empty query\" - now I\'m trying to figure out what I was thinking when I wrote this.... I think it is faster doing a dump into a temp table though, since two left joins on big tables will take some time. That\'s my thoughts - if anybody comes up with a nice solution or figures out what I mean by two left joins - then please post it as a new thread under the header, \"How to do full joins in mysql\" - since this would be something many people request. P.
  23. select * from table1 LEFT OUTER JOIN table2 on table1.coloumnname = table2.coloumnname This will insert NULL values where needed, i.e. missing rows from one of the two tables. EDIT: OUPS! Just realised that IDs in table2 but missing in table1 won\'t be returned, sorry.... Will look at this later. P.
  24. Please post a describe Products; .. or tell us what the error is. I can\'t see any errors in your sql statement, but it may be the database schema or something not so obvious... P.
  25. The first error is a pure php error. It may be causing the sql error. Check your local.php for the line saying include(\'loginform.php\'); (It should be line 60). You should try and specify the correct path to loginform.php... and see if that solves the problem. P.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.