Jump to content

awjudd

Staff Alumni
  • Posts

    422
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by awjudd

  1. I'm guessing for each of the tables there is at least 1 field within each of the rows which are different.  Thus making the DISTINCT catch it as a unique value.

     

    You will probably have to reduce the returned set (from * to something else) in order to remove the duplication.

     

    Another thing I noticed is you are using a cross join between tbl1 and tbl2 (,) and then restricting it.  This may affect the speed of your query.  You may want to change it to something like this:

     

    $sql = "SELECT DISTINCT tbl1.*, tbl2.*
    FROM tbl1 a
    JOIN   tbl2 b ON ( a.site1ID = b.siteID OR a.site2ID = b.siteID )
    WHERE tbl1.active='0'
    AND tbl2.userID='".$me['id']."' 
    ORDER BY b.success DESC 
    LIMIT 10";
    

     

    to work better.

     

    It won't fix your DISTINCT problem, but it may speed things up a bit ... You'll need to identify the key fields before you can get the DISTINCT to work as you wanted it to.

    ~juddster

  2. It appears that your field names in your list are in single quotes.  This is invalid because they will be treated as individual strings.  If you want to delimit the field values use the `.

     

    i.e. INSERT INTO `blah` ( `id`, `blah2` ) VALUES ( NULL, 'Hi' )

     

    That should resolve your issue.

     

    ~juddster

  3. I believe that the error you are getting caused by the exact thing that bh was saying ... your strings aren't in quotes, so it looks in the database for those fields and when it can't find a field called 'bobo' (assuming $_POST [ 'username' ] = 'bobo' ) then it'll error.

     

    ~juddster

  4. There is no need for a LEFT JOIN here ... you will be mostly eliminating the benefits with your where clause anyways (original set that is returned will be much larger than it needs to be) ...

     

    SELECT `p`.`name` FROM `players` p JOIN `users` u ON `p`.`player_id` = `u`.`player_id` WHERE `u`.`mem_id` = $mId

     

    Or you could move the restriction of the member id to the ON clause so it has more conditions (returning less results from the beginning of the join).

     

    SELECT `p`.`name` FROM `players` p JOIN `users` u ON ( `p`.`player_id` = `u`.`player_id` AND `u`.`mem_id` = $mId )

     

    ~juddster

  5. $search = "SELECT p1.rating, MAX(p1.date_of_pr) as date_of_pr, e1.employee_ID 
        FROM performance_review p1 JOIN employee e1 ON e1.employee_ID = p1.employee_ID 
        WHERE e.manager_ID = '".$m_id."' ORDER BY p1.date_of_pr GROUP BY p1.employee_ID, p1.rating";

     

     

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY p1.employee_ID, p1.rating' at line 3 :(

     

    ORDER BY comes after GROUP BY

     

    $search = "SELECT p1.rating, MAX(p1.date_of_pr) as date_of_pr, e1.employee_ID 
        FROM performance_review p1 JOIN employee e1 ON e1.employee_ID = p1.employee_ID 
        WHERE e.manager_ID = '".$m_id."' GROUP BY p1.employee_ID, p1.rating ORDER BY p1.date_of_pr";

     

    ~juddster

  6. I have an attempt as well ... this was my first trial ... I'm pretty sure that this could be simplified some more ... but here it is ...

     

    SELECT e.employee_id, pr.rating
    FROM Employee e
    JOIN ( SELECT employee_id, MAX(date_of_pr) AS date_of_pr FROM performance_review pr WHERE e.employee_id = pr.employee_id GROUP BY pr.employee_id ) p ON e.employee_id = p.employee_id
    JOIN ( SELECT employee_id, rating FROM performance_review pr WHERE p.employee_id = pr.employee_id AND p.date_of_pr = pr.date_of_pr ) pr ON p.employee_id = pr.employee_id AND p.date_of_pr
    WHERE e.manager_id = $mid

     

    The first join (p) will basically get a list for each employee under specific manager and the day of their last review.

     

    The second join (pr) will then grab the corresponding reviews.

     

    However, this will have the same problem as premiso's ...

     

    Something doesn't look right ... and now it's bothering me ...

     

    ~juddster

  7. To make it easier for them you could make a form of sorts to make the CSS file for them ... i.e.

     

    Cell 1:

    Font Name: >input<

    Font Colour: >input<

    Background Colour: >input<

     

    Cell 2:

    Font Name: >input<

    Font Colour: >input<

    Background Colour: >input<

     

    Then when its posted ... you change it to:

    .cell1
    {
       color: $_POST [ 'cell1_colour' ];
       background-color: $_POST [ 'cell1_bg' ]; 
    }
    
    ...
    

     

    This way all they need to know is font names and colours ... not CSS.

     

    Then you save that generated CSS file to the database.

     

    ~juddster

     

     

  8. It works only, when i change action of form to get. Then all informations is in adress bar. I don't really know this time, what can i do, to change bad things to POST, and make it working.

     

    Yet again ... my first post here contains code which would be very useful for the conversion to the $_POST

     

         foreach ( $_POST as $key => $value ) // Loop through all of the posted values (and their associated keys (keys are the 'name' field from the HTML) )
         {
                // TODO: Add some verification to make sure that the field specified exists
                $value = msyql_real_escape_string ( $value ); // Sanitize the input (more should probably be done)
    
                $query = "UPDATE `teksty` SET `" . $key . "` = '" . $value . "'"; // Generate the query
                mysql_query ( $query ); // Update the table
         }
    

     

    When action is GET - i must refresh once to get real data from base in textarea.

     

    I don't know...

     

    Your script does the following:

    i) Grabs the data

    ii) Updates the database

    iii) Displays the data from step 1

     

    This will make it so that you will never get the updated values until you actually refresh.  Move the update up, or re-do the SELECT query within the block of code where it is being updated and it will work as expected.

     

    ~juddster

  9. I was saying let them set all of the CSS for themselves in that area.. or if you don't want it directly in the text area like that, make it so that they have individual fields for each of the classes you want and then build the css file before entering it into the database.

     

    Then you will basically be able to do a query on the user, and just echo whatever they have as their CSS on the page.

     

    ~juddster

  10. For starters, you are going to have to throw all of your text areas into a <form> tag.  This will tell the web browser where to send the data once the button has been pressed.

     

    After that, you will need to add the actual submit button and then process the information which is sent to the processing script.

     

    [php
    $connection = mysql_connect("localhost", "root", "root")
    or die('Brak po³¹czenia z serwerem MySQL');
    $db = mysql_select_db("podreglami")
    or die('Nie mogê po³¹czyæ siê z baz¹ danych');

    $query = "SELECT tresc FROM `teksty`";
    $result= mysql_query($query);
           
            echo "<form method = 'post' action = ''>"; // Tell the form to send data through $_POST and then send it back to the current page

    while ($row = mysql_fetch_array($result))
    {
    echo(' <textarea rows="10" cols="60" name="' .$row['tytul']. '">' .$row['tresc'].' </textarea><br /><br />');
    }

            echo "<input type = 'submit' value = 'Save Settings' />"; // Add the 'sending' button

            echo "</form>";
    [/code]

     

    Then for the processing part, which would probably end up being placed above the previous code, you could do something like this.

     

         foreach ( $_POST as $key => $value ) // Loop through all of the posted values (and their associated keys (keys are the 'name' field from the HTML) )
         {
                // TODO: Add some verification to make sure that the field specified exists
                $value = msyql_real_escape_string ( $value ); // Sanitize the input (more should probably be done)
    
                $query = "UPDATE `teksty` SET `" . $key . "` = '" . $value . "'"; // Generate the query
                mysql_query ( $query ); // Update the table
         }
    

     

    Something along those lines should work I believe.

     

    ~juddster

  11. Why would you have having 600 columns per user?  Just make a text field in and you should be good to go ...

     

    CREATE TABLE user_styles
    (
        user_id UNSIGNED INT PRIMARY KEY NOT NULL,
        style TEXT NOT NULL
    )

     

    Something along those lines where user_id would actually be a foreign key to a users table of some sort.

     

    ~juddster

  12. Will there only be one user?  If yes, then this solution is fine (the CSS will require a page reload before it takes place).  However, if there is more than one user, you may want to consider throwing it in a table in a database and then just echoing the contents whenever they load pages.

     

    ~juddster

  13. It means that you haven't actually set a value to it before trying to use the value in a statement.

     

    Was this supposed to be a global variable?

     

    If yes, you need to tell PHP this.

    <?php function customError($errno, $errstr)
    {
        global $global_error_reporting; // Tell PHP to look in the global scope rather than local.
        ...
    }

     

    ~juddster

  14. As mentioned on IRC, there are two syntactical errors that you have here.

     

    <?php
    require_once('../auth.php');
        require('connet.php'); // Missing semi-colon here (should this be connect.php?)
    
    $user_id = $login;
    $query = "SELECT * FROM `members` WHERE user_id = '$user_id'";
    $resultm = mysql_query($query);
    $user = mysql_fetch_assoc($resultm);
    ?>
    <?php
    
    echo "Hello {$user['firstname']}:<br /><br />\n";
    //Only display link four for users of level 1
    if($user['level']=='1')
    {
        echo "<a href='#'>Link 4</a><br />\n"; // You used " as both the outside and inside the string ... so you would either have to escape it or swap to single quotes
    }
    ?>

     

    ~juddster

×
×
  • 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.