Jump to content

AyKay47

Members
  • Posts

    3,281
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by AyKay47

  1. Thanks very much guys.  In the end, I did not even have to use the JOIN function of MySQL.  I simply combined a WHERE and IS NOT NULL with RAND() and LIMIT.  I'm going to have to look into this join stuff, though, because it seems like a very popular function.

     

    There are two ways to grab values from multiple tables; a subquery or a join.

    Can you post the final solution query please.

  2. This is how yours should look:

     

    select t1.user_email, t2.img_thumb from table_1 as t1 left join table_2 as t2 on t1.user_id = t2.img_id_fk having t2.img_thumb is not null order by rand() limit 5

     

    Yours does NOT check NULLs after the result set is built, if a member doesn't have a row in table 2 you will get a NULL in your result set when using a left join and no HAVING.

     

    My method will automatically ignore the NULLs, so I don't need to check for a null during a search and after the search.

     

    Again, the HAVING clause is used in conjunction with a group by clause, it does not replace the where clause, quite simply, the query you just wrote is wrong.

     

    I'm not here to argue, OP this is the query you should use for this, provided by Little Guy

     

    select t1.*, t2.img_thumb from table1 t1 inner join table2 t2 on (t1.user_id = t2.img_id_fk) order by rand() limit 5;

  3. I would do this in the query:

     

    select day(date_field) as day, monthname(date_field) as month, year(date_field) as year from table

     

    then using php you could do something like this.

     

    $query = mysql_query("select day(date_field) as day, monthname(date_field) as month, year(date_field) as year from table");
    while($row = mysql_fetch_assoc($query))
    {
        $day = $row['day'];
        $month = $row['month'];
        $year = $row['year'];
    }

     

    *pseudo code*

  4. <a href="delete.php?username=<?php echo $username; ?>">Delete User</a>
    
    Delete.php:
    
    <?php
    mysql_connect ("localhost","root","")
    or die("Cannot connect to Database");
    mysql_select_db ("test");
    $username = $_GET['username'];
    $username = mysql_real_escape_string($username);
    
    mysql_query ("DELETE FROM members WHERE username='$username'") or die ("Error- user has not been deleted");
        echo "User has been deleted";
       //header("Location: personaldetails.php");
    
    
    ?>

  5. I forgot the order by rand(),

     

    the is not null would also be in the having, not the where.

     

    the having clause is used in conjunction with the group by clause, you can use IS NULL and IS NOT NULL in the where clause.

  6. if (isset($_POST['Submit']))
    {
        $username=mysql_real_escape_string(trim($_POST['username'])); //this needs to match the nameattr of the input field   
        $sql = "select * from memberdetails WHERE username='$username'";
        $result = mysql_query ($sql);

     

    *snippet*

  7. you are trying to compare a resource to an integer, the code should read:

     

    $sqlid = "select * from temp where Email='".$a[8]."'";
    $idresult = mysql_query($sqlid) or die(mysql_error());
    $res  =  mysql_fetch_assoc($idresult); 
    if (mysql_num_rows($idresult) > 0)
    {
       $tempid = $res['ID'];
       die('sql id:' . $tempid . 'or' . $res['ID']. 'or ' . $sqlid );
    }
    

     

    also, don't use die()'s to display messages, they are very user unfriendly.

  8. select t1.user_email, t2.img_thumb from table_1 as t1 left join table_2 as t2 on t1.user_id = t2.img_id_fk where t2.img_thumb is not null

     

    Typically you want to name fields so they make sense with what they hold and with relationships, a user id is not an image id..

  9. Question: What exactly is the difference between a blank field and one that is checkmarked as NULL? Is there even anything that I need to worry about, or is it pretty much the same thing?

     

    check marked as null?

     

    But it also needs to be put back to NULL once a value is already in there if the user selects it. A default value in MySQL won't do that if he's doing an update. Will it?

     

    I'm trying to wrap my head around the logic here, but I haven't been given enough information, so it's hard to tell.

  10. I would simply set the arg $value to null as default:

     

    setlevel($world,$coords,$var,$value = null)

     

    Then, if $b == 0, do not pass a value for that arg:

     

    if($b == 0) setlevel($p,$co,"board");

     

    which will keep $value as NULL in your function.

     

    Depending on your logic for this, the best option would be to change the mysql field definition to default NULL, changing the value when yes is selected.

  11. I would use an input array for this, set the input name to an array format:

     

    <input name="quantity[]" type="text" value="" size="6" maxlength="2" />

     

    Then iterate the field values, adding the value to the previous value each iteration:

     

    $total_quantity = 0;
    foreach($_POST['quantity'] as $value)
    {
        $value = intval($value); //some sanitization to make sure the value is an integer
        $total_quantity += $value;
    }

     

    This eliminates the need for a regex and multiple loops.

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