Jump to content

alpine

Members
  • Posts

    759
  • Joined

  • Last visited

Everything posted by alpine

  1. This i believe is one way: SELECT   products.id, products.productid, products.productname,   productdetails.id, productdetails.size   FROM productdetails, products WHERE products.productid = productdetails.productid
  2. Example: You create table called "users" In users table you create columns (or fields - thats the same) for each separated info you want to store in the users table. This is an example of what "users" may look like, but ideal it should contain even more info ----------------------------------------------- | id | username | name | email | approved | ----------------------------------------------- where the sql could look like this `id` int(11) NOT NULL auto_increment, `username` varchar(30) collate latin1_danish_ci NOT NULL default '', `name` varchar(30) collate latin1_danish_ci NOT NULL default '', `email` varchar(30) collate latin1_danish_ci NOT NULL default '', `approved` int(1) collate latin1_danish_ci NOT NULL default '',   PRIMARY KEY  (`id`) Now, for each user that signs up, one row of info will be added with this structure containing datas added by e.g. PHP You will however learn more by using the manual at www.mysql.com
  3. It would be better to understand you if you posted some code of what you try to accomplish...
  4. I think you should make your form so that html is not included - no need to be dependable of modifying any message Here is a very basic form that you can start with, should be set up easy and hopefully you can learn from it. File is named "contact.php" (or change name in form action) [code] <?php if(isset($_POST['submit'])) { foreach( $_POST as $key => $value ) { ${$key} = htmlspecialchars($value); } if(!empty($name) && !empty($phone) && !empty($email) && !empty($message)) { // alter this to suited $to = "your@email.net"; $from = "your@email.net"; $from_name = "Your Name"; $subject = "Email message"; // alter this to include every {$}formfield-name, \r\n is linebreaks in email message $msg = "Posted info:\r\n\r\nName: $name\r\nPhone: $phone\r\nEmail: $email\r\nMessage: $message"; // no need to toutch headers $headers = "From: $from_name <$from>\r\n"; $headers .= "Reply-To: $from_name <$from>\r\n"; $headers .= "Return-Path: $from_name <$from>\r\n"; $headers .= "X-Mailer: PHP v".phpversion()."\r\n"; $send = mail($to, $subject, $msg, $headers); if($send) {   echo "Info was sendt";   $done = 1; // hides form } else {   echo "An error may occurred, please try again"; } } else {   echo "Please fill in all fields..."; } } if(!$done) { echo <<<__HTML <form method="post" action="contact.php"> Name: <input type="text" name="name" value="$name" size="25" /> <br /> Phone: <input type="text" name="phone" value="$phone" size="25" /> <br /> Email: <input type="text" name="email" value="$email" size="25" /> <br /> Message: <br /> <textarea name="message">$message</textarea> <br /> <input type="submit" value="Send Info" name="submit" /> </form> __HTML; } ?> [/code]
  5. [color=red]if(this.style.backgroundColor!='#ccff66')[/color] works in IE and Opera but not in Firefox while [color=red]if(this.style.backgroundColor!='rgb(204, 255, 102)')[/color] works in Firefox but not in IE or Opera I normally try to use things that works in all those browsers, and hate to be dependable of browserdetection scripts - but this time i really don't know...... not anyone out there that can give any answers or come up with other ideas ??
  6. OK - i found out that it must be the tbody properties IE cant handle, and it get worse the more rows and tbody tags i have. So i headed on another angle to switch bgcolor as IE handles TR much much faster. Now my problem is that it works in IE (and Opera) but not in Firefox. The following script sets onmouseover and onmouseout style bgcolor IF the current colour is not one particular. But Firefox ignores the if condition: [color=blue] <tr id="tr_$unique_id" style="background-color: $bgcolor;" onmouseout="javascript: if(this.style.backgroundColor!='#ccff66')this.style.backgroundColor='$bgfarve';" onmouseover="javascript: if(this.style.backgroundColor!='#ccff66')this.style.backgroundColor='#dddddd';" onclick="blah..">[/color] Any ideas ?
  7. Can anyone look at this javascript and maybe point out why it is so slow in Internet Explorer ? (IE6) In Firefox it is all ok and very responsive, while in IE its really slow and not following the mouse as i move it over the rows. [color=blue]var oppr_tbody_bgcolor; function set_tbodybg(obj,col) { oppr_tbody_bgcolor=obj.style.backgroundColor; obj.style.backgroundColor=col; } function reset_tbodybg(obj) { obj.style.backgroundColor=oppr_tbody_bgcolor; }[/color] Called like this: [color=blue]<tbody id="tbody_$unique" style="background-color: $bgfarve;" onmouseout="reset_tbodybg(this);" onmouseover="set_tbodybg(this,'#dddddd');"> <tr> <td blah..>ksgdk</td> </tr> </tbody>[/color] I have another function setting the tr bgcolor something if something is done and want that color to be always on top if set, thats why i use the set/reset on tbody as this has lower priority and will be surpressed.
  8. You must escape double quotes if used within double quotes, $message = "Welcome to Sell your own home The easiest and cheapest way to sell your own home <br> <br> <a href=[b][color=red]\[/color][/b]"localhost/activate.php[b][color=red]\[/color][/b]"> <br> <br> Thanks";
  9. alpine

    Bulk insert

    ah, i see. Thanks. I just rebuilt my insert parser and now it inserts 10.000 new rows in one query without any probs (havent fount the max_packet_size setting) - i also made a meta-refresh link in 5 sek intervals to parse the textfile until all rows is inserted.
  10. alpine

    Bulk insert

    Thanks. Lock tables is not nessesary since this is a new table later to be renamed replacing another one, so no queries will be ran on it during insert. I'll have to look on INSERT IGNORE what that means. But why should i disable keys ??
  11. alpine

    Bulk insert

    I have a need to insert approx 400.000 rows once a month, and this is done from parsing 4 text files. Once this is done, i dump the old tables and renaming my new ones. However - My isp has a insert/update limit of 36.000 rows per hours - so its a real time-spender  :o Then i was tipped about the bulk insert possibility, from the mysql manual: [color=blue]INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);[/color] Now, i havent startet rebuilding my update/insert script for this yet, as i'm not sure how many bulks of values i can attatch in one query..... any oppinions on this ? I can hardly imagine that i can insert 100.000 rows on one query like this... or can i ???
  12. ok - i've tested and found this so far: [color=green]<?php $dir_path = "/www/www.what.net/dir/dir/dir"; $file = $dir_path . "/disc.txt"; $dfile = file_get_contents($file); $disklines = explode("\n", $dfile); $arr = array(); foreach ($disklines as $line) { $line = explode(";", $line); $disc_code = $line[0]; $disc = $line[1]; $arr[$disc_code] = $disc; //echo "<p r e>"; //print_r($arr); //echo "</ p r e>"; } // $query = mysql_query(" blah... "); // while($row = mysql_fetch_array($query) { $discount_code = $row["discount_code"]; if (array_key_exists($discount_code, $arr)) { $disc = $arr[$disc_code]; } } ?>[/color] seems fast and ok... ? any improvements out there ?? (...always seem to be...)
  13. thanx, but i'm seeking the fastest way to retrieve a match from a file - not a table, already have that  :)
  14. I have a table with items that i want to match up with the price discount. Currently i have the discounts stored in a separate table, but as the amount of users grows i cannot add one table with discount for each customer. Thats why i must find another solution. illustrating the items table: -------------------------------- item_id | discount_code | etc.... -------------------------------- 1        | 5600              | -------------------------------- and the discount goes like ------------------------- discount_code | discount ------------------------- 5600              | 20 ------------------------- I am thinking about writing discount codes and discount values to a discount file (.txt or whatever) for each customer and read this to match each item upon request. I am however concerned about how to do this the right way so its still very fast to find/read while looping the items table and showing results. Any ideas? Just making a file like: 5600;20 5601;15 etc... or is it possible to save a file as an two dimentional array like array(5600 => 20, 5601 => 15 ......); ...havent tested to see if it works though... WHATS FASTEST to retrieve datas ???
  15. I'm not sure what you are asking here, but your parse error is $sql <? include "functions/include_fns.php"; if (isset($_POST['username']) && isset($_POST['password'])) { $username = $_POST['username']; $password = $_POST['password']; $usertype = $_POST['usertype']; if (login($username, $password, "admin")) { [color=red]$sql[/color] $_SESSION['valid_user'] = $username; $_SESSION['valid_name'] = getname($username, "admin"); $_SESSION['valid_type'] = get($usertype, "admin"); if (isset($_POST['url']) && !empty($_POST['url'])) { $go_url = "".$url; header("Location: $go_url"); } else { header("Location: home.php"); } exit; } else { //status = 0: Incorrect Username or password //status = 1: Session has timed out or your are not logged in header("Location: index.php?status=0"); exit; } } else { header("Location: index.php?status=0"); exit; } ?> Also you have some functions like get() ,getuser() and login() that affects your code here. If this is a 3'rd party script i suggest you try the forum-section --> [url=http://www.phpfreaks.com/forums/index.php/board,34.0.html]http://www.phpfreaks.com/forums/index.php/board,34.0.html[/url]
  16. You would be easiest off with a Main-post ID in your table, all sub-posts would relate to the main id, then the parent id will sort further. That way cou can order them by one table.
  17. I take it that both my indexes is needed, just the FULLTEXT / or the INDEX would not do handling both the ORDER BY and select WHERE clause ?
  18. Just an update as i made a small progress by adding INDEX on the two cols i am ordering by, this actually did a difference in speeding up :) So now i have both a KEY and a FULLTEXT KEY - the KEY on the ORDER BY cols and a FULLTEXT on those cols used in search-query. [code] mysql_query("ALTER TABLE tablename ADD INDEX indexkeyname (col_itemno,col_price)") or die(mysql_error()); mysql_query("ALTER TABLE tablename ADD FULLTEXT fulltextkeyname (col_itemno,col_description)") or die(mysql_error()); [/code]
  19. well, i'm happy with my current union query and now i have explored the possibilities. The best about it is that i have learned yet another thing that does come in handy in some situations - the VIEW. Thanks a bunch for your splendid help fenway!
  20. I could have checked that myself using my Mysql Turbo Manager, just wasn't thinking *lol* - sorry about that OK - with that in mind i created a full VIEW once ordered as above and tested again, only with the LIMIT in final select query. But it is slow, i havent bothered to measure exact time, but my original query using UNION ALL on four tables takes about 0,5-1 sec to display full results while one select on the VIEW table takes roughly 3-4 sec to display the same results. Is it any INDEX that is failing in VIEW here ?
  21. But the view isn't stored permanantly as a new mysql-table is it? I was under the impression that it's stored in memory only...
  22. Thanks for your reply, i'm not sure i understand exactly what you mean by creating a VIEW - do you mind giving me a small example ? *edit* I looked up on MYSQL VIEW and puzzled with it, but i just can't seem to get the hang of it... This is what i have and its working but it's extremely!! slow [code] $view = mysql_query("CREATE VIEW goods AS (SELECT * FROM $table_10) UNION ALL (SELECT * FROM $table_11) UNION ALL (SELECT * FROM $table_12) UNION ALL (SELECT * FROM $table_13) ORDER BY itemno,price limit $limit") or die(mysql_error()); $result = mysql_query("SELECT * FROM goods WHERE MATCH(itemno) AGAINST('$s*' IN BOOLEAN MODE)") or die(mysql_error()); [/code] On second search i get error "table goods already exists" so i tried a CREATE OR REPLACE VIEW making it very slow altogether.. So i put back my original query again. I'm sure i miss out something regarding VIEW Btw- the query can be found live here to test speed --> [url=http://www.elektrostart.no/multiplukk/]http://www.elektrostart.no/multiplukk/[/url] (type e.g. 10348 or 13173)
  23. I have so far 4 identical tables that i query like this [code] mysql_query("(SELECT * FROM $table_10 WHERE MATCH(itemno) AGAINST('$s*' IN BOOLEAN MODE)) UNION ALL (SELECT * FROM $table_11 WHERE MATCH(itemno) AGAINST('$s*' IN BOOLEAN MODE)) UNION ALL (SELECT * FROM $table_12 WHERE MATCH(itemno) AGAINST('$s*' IN BOOLEAN MODE)) UNION ALL (SELECT * FROM $table_13 WHERE MATCH(itemno) AGAINST('$s*' IN BOOLEAN MODE)) ORDER BY itemno,price limit $limit") or die(mysql_query()); [/code] Can this be optimized to return faster than with my query? The reason for it being 4 separate tables is due to different times for new issues to update as the tables are sorted on different suppliers of mine. So putting them in one table is not an option at this time. The query is not slow, but it would not hurt for it to be slightly faster as i use ajax to query results. The total rows of all four tables is approx 400.000, and i have a index on itemno Thanx for any helps :)
  24. Thanks for your reply. I do however get --> Unknown modifier '(' <-- on line --> if (($extra_data = preg_replace($lookfor,$repwith,$data)) === true) Tried to mix with it back and forth - but with no luck  :-\
  25. I realize that my first post was incomplete in the problem-description as it would not work along with the db querys. I've come up with a solution that works, i am however sure it can be done more efficient, maybe in one regex match - so please pinpoint anything that can make it faster (apart from the mysql "LIKE" part though...) [code] function query_dotsandcommas($data) { $new_query = array(); if (preg_match("/([0-9]+[,][0-9])/i", $data)) { $extra_data =  str_replace( "," , "." , $data); $new_query[] = "AND (beskrivelse LIKE '%$data%' OR beskrivelse LIKE '%$extra_data%')"; } elseif (preg_match("/([0-9]+[.][0-9])/i", $data)) { $extra_data =  str_replace( "." , "," , $data); $new_query[] = "AND (beskrivelse LIKE '%$data%' OR beskrivelse LIKE '%$extra_data%')"; } else { $new_query[] = "AND beskrivelse LIKE '%$data%'"; } $query = implode(' ', $new_query); return $query; } [/code] I also realized that a match inbetween numbers is sufficient
×
×
  • 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.