Jump to content

isedeasy

Members
  • Posts

    257
  • Joined

  • Last visited

Everything posted by isedeasy

  1. thanks AbraCadaver, that was the first method I tried but I did not have the $Item in the for loop as a reference which is why it did not work mjdamato, the array I posted was just an example to save space, that is why secondary array only has one element. I had a quick look at array_map but looking at your example I can't see where you tell it what element to effect? Thanks for help
  2. I have an array which I contains multiple arrays, I would like to loop through and run a function on a certain key within the array I have the following code which works but I was wondering if there was a better method? $i = 0; foreach($Items as $Item) { $Items[$i]['key'] = custom_function($Item['key']); $i++; } The array $Items structure is as follows array ( [0] => array ( [key] => 'blah' ) [1] => array ( [key] => 'blah' ) [2] => array ( [key] => 'blah' ) )
  3. Does anyone have an answer to my last question? "Shall I have a separate comment table for each of the three types or one comment table with a column for the type?"
  4. I just realised that the version I am using is well out of date. I will update to the latest version when I get home and see what happens then.
  5. I am using phpmailer to send emails from my site, the problem I have is that when I recieve an email it says its from '[email protected]' not 'websitename'. Why is it not picking up what I pass into $mail->FromName? <?php // from included settings file define ( "SITE_NAME", "websitename" ); define ( "ADMIN_EMAIL", "[email protected]" ); define ( "DOMAIN_NAME", "www.websitename.com" ); define ( "RUN_ON_DEVELOPMENT", TRUE ); define ( "USE_SMTP", TRUE ); define ( "SMTP_PORT", "25" ); define ( "SMTP_HOST", "**************" ); define ( "SMTP_USER", "**************" ); define ( "SMTP_PASS", "**************" ); define ( "MAIL_IS_HTML", TRUE ); //send mail function function send_email ( $subject, $to, $body ) { require ( "classes/class_phpmailer.php" ); $mail = new PHPMailer(); //do we use SMTP? if ( USE_SMTP ) { $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->Host = SMTP_HOST; $mail->Port = SMTP_PORT; $mail->Password = SMTP_PASS; $mail->Username = SMTP_USER; } $mail->From = ADMIN_EMAIL; $mail->FromName = SITE_NAME; // <------------------- Can't get to work $mail->AddAddress( $to ); $mail->AddReplyTo ( ADMIN_EMAIL, DOMAIN_NAME ); $mail->Subject = $subject; $mail->Body = $body; $mail->WordWrap = 100; $mail->IsHTML ( MAIL_IS_HTML ); $mail->AltBody = $body; if ( ! $mail->Send() ) { if ( RUN_ON_DEVELOPMENT ) { echo $mail->ErrorInfo; } return FALSE; } else { return TRUE; } } ?>
  6. CREATE TABLE `comments` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user` int(6) NOT NULL, `item` int(6) NOT NULL, `type` int(1) NOT NULL, PRIMARY KEY (`id`), KEY `user` (`user`), CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`user`) REFERENCES `users` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 CREATE TABLE `item1` ( `id` int(6) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 CREATE TABLE `item2` ( `id` int(6) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 CREATE TABLE `item3` ( `id` int(6) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(32) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 I'm not at home now so will this watered down version do? I have it set up so that 1 in the comments.type column refers to item1, 2 in the comments.type column refurs to item2 etc So would be best for each item to have its own comments table or is there a way to use foreign keys for comments.item to reference the id of the items?
  7. That's my point I want the correct structure. Shall I have a separate comment table for each of the three types or one comment table with a column for the type?
  8. Thanks for all the replies so far, they have all been very helpful. I have been looking into foreign keys and I have completely redone all my keys/indexes to use foreign keys where applicable. The problem I have at the moment is my comment system, I have 3 different types of items that users can comment on so I have a column for the items id and a column for the type of item (because the id's are auto increment). therefore all the comments are in one table. Should I use a separate table for each type of item users can comment on? that way I can use foreign keys to link the row with the items ID or should I keep it as it is and just have an index consisting of item combined with id? tableA - id tableB - id tableC - id CommentsTable - item (either tableA, tableB, or tableC), id Hope that makes sense
  9. If you are going to allow anonymous users to post then a captcha is a must, Otherwise you are open to spam (I guess you just found that out).
  10. Ah yeah did not think of that. Cheers
  11. I have the following query which works just fine until I have a few hundred rows in one of the joined tables, then it takes over 30 sec to load the page. How can I optimise this query? I have certain columns indexed. SELECT a.id, COUNT(DISTINCT b.id) AS table1no, COUNT(DISTINCT c.id) AS table2no, COUNT(DISTINCT d.id) AS table3no, COUNT(DISTINCT e.id) AS table4no FROM table a LEFT JOIN table1 AS b ON b.user = a.id LEFT JOIN table2 AS c ON c.user = a.id AND c.deleted = 0 LEFT JOIN table3 AS d ON d.user = a.id AND d.status != 2 AND d.stage = 5 LEFT JOIN table4 AS e ON e.user = a.id AND e.status != 2 AND e.stage = 5 WHERE a.id = $id
  12. I have a function that replaces certain characters with a hyphen function addHyphens($string) { $chars = array(" ", "&", "_", "/", "\\", "(", ")", "#", "?", "%", "\"","'", ".", ",", ":", ";", "[", "]", "!", "$", "£", "+", "="); $newstring = str_replace( $chars, '-', $string); return $newstring; } at the minute I get echo addHyphens('foo - bar'); // returns foo---bar echo addHyphens('foo! bar!'); // returns foo--bar- I would like the following to happen echo addHyphens('foo - bar'); // returns foo-bar echo addHyphens('foo! bar!'); // returns foo-bar What's the best way to go about this?
  13. You will still need a form, it's just that you want to lay the form out like a table.
  14. I prefer a black background, I use Komodo which allows you to customize your colour scheme.
  15. if (db_num_rows($queryGetNews) > 0) { //while loop } else { //throw error message }
  16. It looks a little dated to me, the dark colours and the boxy layout does not give me a professional feel. The main body text on the homepage should not be an image, if you want to use fancy fonts then have a look at JS/flash font replacement. There are a few methods about, my favourite being cufon. I would remove the validation icons from the bottom, the only people that care about that are web designers/developers.
  17. Judging by your site you should really brush up on your html/css, even if you only deal with back end stuff it's quite shocking...
  18. I downloaded an icon set months ago and cannot seem to locate it any more, which is great as I want to replace/add icons form the same set. if anyone knows which icon set this is could you please link me to it, or if anyone has a great application icon set with a similar style please share I know this may be a long shot but here goes... Cheers
  19. yeah last login will not be very good at all because of the remember me feature. The site uses memcache so maybe I could cache the last access time and run a cron job to delete the cache add update the database in the early morning? or does that sound like a stupid idea I don't want to decrease performance for a 'nice to have feature' but it would be nice to have that feature lol will running an update query every page load put much strain on the server?
  20. I would like to add a feature to my site to show when a user was last active (exactally as you have here at PHP freaks). I would like to know the best way to go about this. The method I came up with would be to simply update a value in a column in the users table every time a page is loaded. Now obviously this would work but I can't see it being very efficient as I am basically doing an mysql update every time a page loads. What's the best way to go about this? Thanks
  21. Maybe because he did not want google to pick up his url in a phpfreaks thread
  22. Thanks, that's exactly what I was looking for
  23. I want to do a query that finds out how many users joined over the past month grouped into days (for a chart). The problem is that I have the date registered as an integer 'time()'. How do I group by day?
  24. Each email needs to send a unique key so how do I send individual emails with out looping? I currently us PHPMailer class to send emails via smtp would I be able to use that? Sorry if I sound like a n00b but this is all new to me.
  25. I have created a mailing list where users can sign-up with their name and email address. I know have a mysql table with columns `name`, `email` and `key` (random string for unsubscription). My question is, whats the best way to send off the emails? I want to send off daily emails which get the content from a dynamic php page.
×
×
  • 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.