SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Addict smittenbite's Avatar
    Join Date
    Jul 2005
    Location
    Friendswood
    Posts
    397
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    different results when query run from php vs phpmyadmin

    i run the same mysql query from a php file and phpmyadmin (by echo-ing the query in the php file before it is run and then copy and pasting) and they give different results! the difference is the results should give 2 results or entries from the database. whenever i run it in php, it only gives one of the two results and no errors are reported when running the php. anyone know what might be wrong? any help or suggestions appreciated
    Last edited by smittenbite; Jun 10, 2007 at 20:49. Reason: spelling
    nothing.

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Are you fetching all results in php or just the first one? Maybe that might be the problem.
    -- Jelena --

  3. #3
    SitePoint Addict smittenbite's Avatar
    Join Date
    Jul 2005
    Location
    Friendswood
    Posts
    397
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well i did not put a limit on the results though , shouldn't it just return all results if i dont specify any limit? thanks for the reply.


    *edit* oh yeah actually it gives me the second result, and not the first one when i run the php. ???
    nothing.

  4. #4
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Could you show us the code where you fetch results and display them?
    -- Jelena --

  5. #5
    SitePoint Addict smittenbite's Avatar
    Join Date
    Jul 2005
    Location
    Friendswood
    Posts
    397
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $query2 "select set.article_name, set.notes, set.set_id from set where set.user_id = "$row[0] ."";  

                    
    $result2 mysql_query($query2);
                    
                    if (
    $result2)
                        {
                            
    $row2 mysql_fetch_array ($result2MYSQL_NUM);
                            echo 
    "<table border=2px>";
                            echo 
    "<tr> 
                                        <td> Set Name</td>
                                        <td> Notes </td>
                                        <td> View as Html</td>
                                  </tr> "
    ;
                                        
                            
                            while (
    $row2 mysql_fetch_array($result2MYSQL_NUM))
                                {
                                    echo 
    '
                                    <tr>
                                        <td> ' 
    $row2[0] . '</td>' 
                                        
    '<td>'  $row2[1] . '</td>' .
                                        
    '<td> <a href="showhtml.php?id=' $row2[2] . '">View Html</a></td>' 
                                    
    '</tr>';                            
                                }
                            echo 
    "</table>"
    that is the code snip from the php where i use that sql . $row[0] gives a number 1. i know there are two results because i inputed them myself directly into the database, and also when i run that exact query with phpmyadmin, it gives me the two results i expect. any help appreciated
    nothing.

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Remove this:

    PHP Code:
    $row2 mysql_fetch_array ($result2MYSQL_NUM); 
    That line retrieved the first row from the result set, but you didn't do anything with it. If you don't do it, the pointer into the result set will be at the first row when you start your loop a few lines below.

  7. #7
    SitePoint Addict smittenbite's Avatar
    Join Date
    Jul 2005
    Location
    Friendswood
    Posts
    397
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah Thank you Dan for pointing that out, it works now
    nothing.


Bookmarks

Posting Permissions

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