Jump to content

dannyb785

Members
  • Posts

    544
  • Joined

  • Last visited

Posts posted by dannyb785

  1. thank you for your quick reply. I was worried that the only solution would be either:

     

    a) a cron job script every x sec/min/hours or

     

    b) running the script(which checks jobs) any time a user accesses any page(to simulate a cron job, but it'd only work when at least 1 user is browsing the site).

     

    I know that with a busy site, the script could be run every few seconds(using solution b) but if the site is dead then it could go hours without being run.

     

    Which solutions is better?

  2. I have a table `Message` and each new message sent will be a new row, but when viewing the inbox, I only want the latest message to show and I only want one row for each unique user that a message has been exchanged with, here's the queries I've tried:

     

    SELECT m_date,m_text,m_id,m_from,m_to FROM Message WHERE (m_to='4' OR m_from='4') ORDER BY m_id DESC
    // this is for user with id=4
    

    this code grabs all messages that have been sent to or from user=4. Not very helpful

     

    SELECT m_date,m_text,m_id,m_from,m_to FROM Message WHERE (m_to='4' OR m_from='4') GROUP BY m_from ORDER BY m_id DESC
    // this is for user with id=4
    

    This code is a little better but if userx and usery have both sent at least 1 message to each other, this query will return 2 rows, each row representing the message from the user.

     

    As an extra problem, I want to do a JOIN where I get the username from the `User` table but I can't just say "WHERE User.user_id=Message.m_from" because the value in the m_from column might be myself, and I just want it to show the OTHER person's username, whether I sent the message to them or if I got the message from them.

     

    How can I do this? Please please please nobody just say "Look into JOIN" because I know how to do joins but this is pretty complicated  :-[

  3. I'm building a site where a user has a timer after they've accepted a job. That timer could be a range from 1 hr to 2 days and if the user hasn't submitted their work within that period of time, I'd like it to automatically mark that job as late. Similarly, their job has to be approved by the boss within 2 days of submission or their work would be automatically approved.

     

    I know I could do a cron job every x minutes, but I'd like it to be instant, where as soon as the job late(based on the due date) it marks it in the database as late and sends an email to the user letting them know. Is there any other way other than running a cron job every 5 seconds?

  4. I have a site with a facebook-type newsfeed and each newsfeed post has comments and likes.

     

    So my code works like so:

     

    *query that grabs all newsfeed posts

    while(row = mysql_fetch_assoc())

    {

      *query to grab this post's likes and output the number

      *query to gran this post's comments and output them

    }

    I have the proper columns indexed to help a little bit, but I feel helpless, is there a way to do anything close without having to do these queries within the main query?

  5. EG

     

    SELECT r.R_id, a.user_username as userA, b.user_username as userB
    FROM report r
    INNER JOIN user a ON r.userid1 = a.userid
    INNER JOIN user b ON r.userid2 = b.userid

     

    I don't know your column names so can't be precise. Join one id col to user with one alias and the second id to user with another alias

     

    yes! this worked perfectly, thank you!!

  6. So here's my situation: I have a table called User and Report. The Report table has 2 columns, 1 for the person submitting the report and another for the user they are reporting. Each column contains the user id of the respective user. The User table has user_id and user_username. I know how to do a simple Join to get one of the usernames, but how do I get both?

     

    For example: to get the username of the person submitting the report, my query is:

    SELECT r_id,user_username,r_reason FROM Report,User WHERE User.user_id=Report.r_reporter
    

     

    This gives me results with theusername who submitted the report, but I also need to grab the username of the person being reported

     

     

     

  7. I'm making a social network site and I want the newsfeed page to have  wall posts that 1) I've made to friends, 2) that friends have made to me, and 3) that friends have made to other friends.

     

    I have code for #1 and #2, but I don't know how to do #3. I feel like the only way is to have an entry for every possible friend combination where if:

     

    user1 is friends with user2, user3, user4, and user5 that I'd have to check for wall posts where: (wall_user=user2 AND wall_poster=user3) OR (wall_user=user3 AND wall_poster=user2) OR (wall_user=user2 AND wall_poster=user4) OR (wall_user=user4 AND wall_poster=user2) and so on down the line of every possible combination

     

    Is there an easier way?

     

  8. The referrer is insecure. Don't rely on it.

     

    Do you mind having the file go through your server first? Means double the bandwidth (both site1 and site2 are sending the whole file) but it's the easiest answer.

     

    I understand that referrers can be spoofed, but the chances are pretty low of anyone knowing that's how I check for a valid download attempt. Can anyone just answer my question of how to do it? Or suggest a suitable alternative?

  9. Hi, I have decent knowledge of htaccess and know enough about php/mysql so a little direction/advice is mostly what I need. I host a website(site1.com) that has links to files that are hosted on a different website(site2.com) on a different server. When a file link is clicked from site1.com, first it will go to a local php file(within site1.com) that checks that the user is logged in and make sure the file exists. Then it redirects(using a simple header function) to the file located at site2.com to begin download.

     

    But since my files at site2.com stored in a simple folder(if you knew the folder name, you could download all the files without having to be logged in), I want a way for site2.com to check that the file request is coming from site1.com(maybe using php referrer?) before it allows the download to proceed. Any ideas?

  10. I'll second what the other guy said, but I'll type the code so it makes more sense

     

    home.php

    <?php
    include("config.php");
    
    $page = "home";
    include("header.php");
    
    /blah blah blah
    ?>
    

     

    header.php

    //html code blah blah
    <li><a href=#<?php if($page == "home" echo " class='current'; ?>Home</a></li>
    <li><a href=#<?php if($page == "about" echo " class='current'; ?>About</a></li>
    // etc etc...
    
    // rest of html
    

     

  11. Hi,

     

    I have setup my paypal payment method for a shopping cart on my site, all is well but in order for my server to flag an invoice as paid, the user must return to my website after paying and the query string in the url give the script the go ahead to mark it as paid which in turn alerts the appropriate department that its ok to source the order.

     

    ~The problem is, if the user for whatever reason skip the redirect back to my site, the invoice is remain 'unpaid' and has to be changed manually when the payment has been checked in the account. As you might imagine this is a bit of a problem because not only can it cause quite a delay, it also requires manually changing values which can lead to other problems.

     

    So if there is a better way i would appreciate the info, thanks a lot.

     

    That's why you have the "notify_url" variable in paypal. You can either specify it in the form itself or in your paypal settings. That file you set as your notify_url should be the php page that does all the processing. Plus paypal passes all the payment details(name, address, price paid, etc) through to the notify_url as $_POST variables which makes it easy to process. the return_url is just offered as a link after payment and they can choose to not click it

  12. That's why most sites have users as "recently online", where once they are logged in, viewing any webpage will update the user's "last_activity" value and the "Who's Online" box just shows the users who have a last_activity value within the last 5-10 minutes. Of course it doesn't account for someone who sits and reads one web page for 20 minutes, but there's no way to monitor idle activity(that I know of)

  13. Did you not understand when I said scanning numerous checkboxes, and then gave an example of 2 checkboxes next to each other?

     

     

    When you have a form with multiple checkboxes next to each other, the only way(it seems) to know if the box was checked is to see if the $_POST variable for that box is set to the input's value. So for <input type=checkbox name=a1 value='bob'>, you'd need to check if($_POST['a1'] == "bob"). But if you don't know how many checkboxes you're gonna have, what do you do?

     

    The thing is, most of my checkboxes are dynamically output in php(by grabbing users from a database and making a checkbox for each of them) so I can't make a loop that scans all possible checkboxes, plus just the value of the checkbox alone isn't enough to tell me which user that checkbox corresponds to.

  14. So I've been scanning forms with checkboxes the same way for years and I can't help but think there's a better way. Sometimes when testing, it get caught in infinite loops the way I do it because basically I'll have it like so:

     

    formpage.php

    <form action=processform.php>
    a1 <input type=hidden name=id value='1'> <input type=checkbox name=a1>
    <br>
    a2 <input type=hidden name=id value='2'> <input type=checkbox name=a2>
    // etc etc for all checkboxes and then, 
    <input type=hidden name=tracker value='-1000'>
    <input type=submit value='Submit'>
    </form>
    

     

    processform.php

    while(current($_POST) != '-1000')
    {
    
    // do stuff with current($_POST) to check the id and the value of the $_POST after it and then call next($_POST) to go to the next line
    
    }
    
    

     

    The reason I do this is because if a user clicks the a1 box, there is a value in the $_POST['a1'], but all boxes that are not checked do not pass through a variable. There must be a better way to do this

  15. In most jquery documentation, they recommend making the function call within the html page itself and not in a separate javascript file.

     

    If you're referring to the examples, that's done simply to make them more portable; it's not recommended.

     

    whatever, recommended or not, it works and it the best way to easily modify it instead of keeping it in a separate js file

  16. thank you very much...this code works with whatever extension it has been tested...

     

    $jpg_path = '../../users/user_avatars/' . $_SESSION['the_user'] . '.jpg';

    $jpeg_path = '../../users/user_avatars/' . $_SESSION['the_user'] . '.jpeg';

    $gif_path = '../../users/user_avatars/' . $_SESSION['the_user'] . '.gif';

    $png_path = '../../users/user_avatars/' . $_SESSION['the_user'] . '.png';

    $png_path = '../../users/user_avatars/' . $_SESSION['the_user'] . '.png';

    function fileExists($png_path){

        return (@fopen($png_path,"r")==true);

    }

    if(fileExists($png_path)) $png_test = '1';

    function fileExists1($gif_path){

        return (@fopen($gif_path,"r")==true);

    }

    if(fileExists1($gif_path)) $gif_test = '1';

    function fileExists2($jpg_path){

        return (@fopen($jpg_path,"r")==true);

    }

    if(fileExists2($jpg_path)) $jpg_test = '1';

    function fileExists3($jpeg_path){

        return (@fopen($jpeg_path,"r")==true);

    }

    if(fileExists3($jpeg_path)) $jpeg_test = '1';

     

    You're not using functions properly. You can use one function for all those tests, fileExists is fine with $path in the parenthesis and $path in the fopen() function, if you're gonna put the same code 4 times, there's no reason to even use functions. Their purpose is to make things easier

  17. I screwed up the code I gave, fileExists($png_path) should be fileExists($path)

     

     

    And I tested the code in mine and it works, so the part where you use $_SESSION variable has to be wrong. Replace that with the actual value of something that you know exists. I'm sure your session is not starting or something

  18. Since you're not getting the response you're looking for, you need to simplify your code until you get something correctly. Do this as your entire page:

    <?php
    $png_path = '../../../users/user_avatars/' . $_SESSION['the_user'] . '.png';
    function fileExists($png_path){
        return (@fopen($path,"r")==true);
    }
    if(fileExists($png_path)) echo "It exists";
    else echo "It doesn't";
    ?>
    

     

    Also, you're using session variables, but are you doing session_start() at the top of this 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.