Results 1 to 12 of 12

Thread: [RESOLVED] function not working

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Resolved [RESOLVED] function not working

    I need some help, I tried to develop this function. Say I have a database that has 2 colums for now.

    Code:
    row1
    column1(id) - 1
    column2 - test
    
    row2
    colum1(id)-2
    column2 - test, testing, tester
    I coded up this function to retrieve that information seperately. For example, if a user has a URL query string with user=test, then when the query run, the user should get outputs of the id's "1 and 2", but if the user=testing, then the output should be only "1"... but my logic is not working.

    PHP Code:
    $userid $_GET['user'];

       
    $sql "SELECT * FROM interest";
       
    $return mysql_query($sql) or die ("Unable to query" mysql_error());
       while (
    $col mysql_fetch_assoc($return))
       {
             
    $values "{$col['Interested_ID']}";
                
    $test explode(","$values);
                for (
    $i=0$i<=3$i++)
                {
                    
    //echo $test[$i];
                    //echo "<br>";
                    
    if ($test[$i] = $userid)

                    
    //{
                    // find out who is interested in that user
                    
    $qry "SELECT UserID FROM interest WHERE Interested_ID = '$test[$i]'";
                    
    $result mysql_query($qry) or die ("Unable to query" mysql_error());
                    while (
    $row mysql_fetch_assoc($result))
                    {
                          
    $value "{$row['UserID']}";
                          echo 
    $value;
                          echo 
    "<br>";
                          exit;
                          
    //exit;
                    
    }
                    
    //}

                


  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: function not working

    Code:
    $userid = $_GET['user'];
    
       $sql = "SELECT * FROM interest";
       $return = mysql_query($sql) or die ("Unable to query" . mysql_error());
       while ($col = mysql_fetch_assoc($return))
       {
             /* why not use ? $values = $col['Interested_ID']; */
             $values = "{$col['Interested_ID']}";
                $test = explode(",", $values);
                for ($i=0; $i<=3; $i++)
                {
                    //echo $test[$i];
                    //echo "<br>";
    		
    		/* the statement below assigns the value of $userId to $test[$i]
                          this will always evalute to the boolean value of the expression on 
                          the left of the assignment operator. == is equality
    
                          Anyhow, that line will not even parse, it is missing a semicolon
                        */
                    if ($test[$i] = $userid)
    
                    //{
                    // find out who is interested in that user
                    $qry = "SELECT UserID FROM interest WHERE Interested_ID = '$test[$i]'";
                    $result = mysql_query($qry) or die ("Unable to query" . mysql_error());
                    while ($row = mysql_fetch_assoc($result))
                    {
                          /* why not use ? $values = $col['UserID']; */
                          $value = "{$row['UserID']}";
                          echo $value;
                          echo "<br>";
                          exit;
                          //exit;
                    }
                    //}
    
                }
    Aside from the above issues, can you explain to me the purpose of this table and why you should need to traverse the entire table each time you search for one user ID? I think your schema may need some revision.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: function not working

    hm... I am not sure, in fact besides the above issues, I still did not get what I want.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: function not working

    Why have you created the table? What are the meaning of the columns? What exactly does the function do?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: function not working

    Code:
    row1
    column1(id) - 1
    column2 - test
    
    row2
    colum1(id)-2
    column2 - test, testing, tester
    This is what I want to accomplish. I coded up this function to retrieve that information seperately. For example, if a user has a URL query string with user=test, then when the query run, the user should get outputs of the id's "1 and 2", but if the user=testing, then the output should be only "1"... but my logic is not working. I can't get this to work. I might have too many loops but please help me.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: function not working

    Using a single field to hold multiple values like that is making life hard for yourself. It's not what databases are designed to do.

    I suggest making a second table that contains the "test, testing, tester" values in individual rows linked to to your original ("interest"?) table. Tables should contain only contain data relevant to themselves; doing it all using one table does not work.

    I also suggest you invest some time in studying relational database theory. It is a valuable skill to have.

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: function not working

    You need to create another table called user_interest:
    Code:
    +--------+        +---------------+         
    |  user  |        | user_interest |         +---------------+
    +--------+        +---------------+         |   interest    |
    | id     |-+-----<| user_id       |         +---------------+ 
    +--------+        | interest_id   |>------+-| id            |
                      +---------------+         | name (UNIQUE) |
                                                +---------------+
    You can then just use a single query to pull out all the user ID's for a specfiic interest:
    Code:
    SELECT user_id FROM user_interest,interest 
        WHERE interest.name=##INTEREST NAME## AND
        interest.id=user_interest.interest_id;
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: function not working

    But the thing is if I have test, testing in different rows, that would be so hard to capture, and then my rows in the table is going to go forever. Above 3 examples just for examples, I allow user to put in the input box.

    Here is what it is. If User1 browses User2's profile, he clicked on "show interest", I wanna keep track that. So that if User2 logs in, he/she can see who is interested in him/her. And if User3 browses the profile, again interested in User2, then i wanna keep track that too. Which means User2 has 2 ppl or maybe more users that is interested in him/her.

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: function not working

    But the thing is if I have test, testing in different rows, that would be so hard to capture, and then my rows in the table is going to go forever. Above 3 examples just for examples, I allow user to put in the input box.
    You use the interest_id (a number to keep track of it). Firstly where does test and testing come into it? What exactly do you mean by interest (is this just a list of use ID's)?

    And what is a problem of keeping track of these in a separate table?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: function not working

    Yes, visual aid. I keep track the Interested_ID. the user ID will be the ID for the users that browse the profile and click on the Interest link. The interested_ID will be the User's ID who has been interested by another UserID. Forget about the testing, I was doing for example to see if it makes more sense with that function, apparently NOT.

    See I have a table called Interest
    Column1(UserID) - PK only one value
    colum2(Interested_ID) - I separate those UserID with commas for this filed by using implode.

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: function not working

    grrrrr.. i must be thinking out of the box. It was very simple but I made it too complicated and hard on myself. grrrr...

  12. #12
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] function not working

    Like penagate said, combing these is not a good idea. Instead separate each interest into a row.

    user_id,interested_user_id

    Make both these columns a composite primary key and you can extract the data you need a lot easier.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width