Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: Reading news from table on server

  1. #11
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by toplisek

    Do you know how to get $_GET['id'] form table on server where is ID first column?
    Do you know how to put code and receive $_GET['id'] ? Id is first column in table articles

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    So... you want to get the value of $_GET['id'] and find the article that matches that?

    Well... you need to use a mysql query.... try this:

    PHP Code:
    $var "SELECT * FROM articles WHERE id='".$GET_['id']."'";
    mysqlquery($var); 
    ...I think that'll work. The WHERE command is what you need.

    I might be slightly off on syntax... hope it helps, though.

  3. #13
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have put while sentence :
    PHP Code:

        
    // Make rows for records
        
    while($rec=mysql_fetch_array($result))
        {
           echo 
    "<tr>";
            for(
    $i=0;$i<count($rec);$i++)
            {
                if(
    $rec[$i])


    $query "SELECT ID FROM articles where ID = '$rec[$i]' ";
    $s mysql_query($query);
    echo(
    mysql_error($s));

    $result mysql_fetch_assoc($s);
    $ID=$result['ID'];
    //echo the article
    //echo("<p>".$result['ID']."</p>");


                
    echo '<td><a href="article.php?ID='.$ID.'"><B>'.$rec[$i].'</B></A></td>';
            }
            echo 
    "</tr>";
        }
        echo 
    "</table>";

    It gives me error:
    Warning: mysql_error(): supplied resource is not a valid MySQL-Link resource in .../read_news.php on line 59

    Line 59 is:
    echo(mysql_error($s));
    Do you know how is correct to get ID number in this while sentence? Need help

  4. #14
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hey, Twey, or someone else, is the syntax right on the $query, line?
    Looks like he's trying to embed a variable in it... inside single quotes, but it's in double quotes overall. that might be the problem, but I'm not sure.

    Ok... wait... nevermind. I figured it out.

    Here's the deal...

    You are using mysql_error... that's a function that is SUPPOSED to show an error. That's not really an error you're getting... but you're just displaying an error there.

    Or... maybe you're testing with that.

    I'm confused.

  5. #15
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by toplisek
    Do you know how is correct to get ID number in this while sentence? Need help

    I do not know how to get Id form each row of news.

  6. #16
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Quote Originally Posted by djr33
    guess the error was due to that. strange.
    Not at all. Nothing more than what usually happens when you forget to escape a quote.

    Hey, Twey, or someone else, is the syntax right on the $query, line?
    Looks like he's trying to embed a variable in it... inside single quotes, but it's in double quotes overall. that might be the problem, but I'm not sure.
    Yes, that bit's fine; the single quotes are just part of the double-quoted string, and have no special meaning. However, there may be other problems... ID is presumably a number, which means it doesn't need to be quoted. You might as well select *, being as you'll want it later, and there's no performance decrease.
    PHP Code:
    $query 'SELECT * FROM articles where ID = ' $rec[$i] . ';'
    More importantly, I just noticed the layout of the code. If we add in the effective braces:
    PHP Code:
    // Make rows for records
        
    while($rec=mysql_fetch_array($result))
        {
           echo 
    "<tr>";
            for(
    $i=0;$i<count($rec);$i++)
            {
                if(
    $rec[$i])
                {
                   
    $query "SELECT ID FROM articles where ID = '$rec[$i]' ";
                }
                   
    $s mysql_query($query);
    echo(
    mysql_error($s));

    $result mysql_fetch_assoc($s);
    $ID=$result['ID'];
    //echo the article
    //echo("<p>".$result['ID']."</p>");


                
    echo '<td><a href="article.php?ID='.$ID.'"><B>'.$rec[$i].'</B></A></td>';
            }
            echo 
    "</tr>";
        }
        echo 
    "</table>";

    So, if !$rec[$i], you're trying to execute a non-existant query. The fix is to move that brace to where it ought to be, or, better, to use the continue keyword to skip the rest of that iteration:
    PHP Code:
    // Make rows for records
        
    while($rec=mysql_fetch_array($result))
        {
           echo 
    "<tr>";
            for(
    $i=0;$i<count($rec);$i++)
            {
                if(!
    $rec[$i]) continue;
                
    $query "SELECT ID FROM articles where ID = '$rec[$i]' ";
                
    $s mysql_query($query);
                echo(
    mysql_error($s));

                
    $result mysql_fetch_assoc($s);
                
    $ID=$result['ID'];

                echo 
    '<td><a href="article.php?ID='.$ID.'"><B>'.$rec[$i].'</B></A></td>';
            }
            echo 
    "</tr>";
        }
        echo 
    "</table>";

    This is the sort of problem that can be avoided by using a consistent and accurate indentation scheme.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #17
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    It gives me error with your above code:
    Warning: mysql_error(): supplied resource is not a valid MySQL-Link resource in .../read_news.php on line 56

    Line 56: echo(mysql_error($s));

    and it shows only first row. I need to showw all rows which are on server from ID1 to last ID)

  8. #18
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You do realize you're telling it to tell you an error, right?
    You're using it for error checking purposes, yes?

    All that's gonna do is tell you the last mysql error, so it would be anything in the entire page that resulted as an error... doesn't have anything to do with line56 except that's when you decided to display it.

    I'm not saying you're wrong though... just wanted to be sure that is what you wanted.

    -------

    It would only show the first row. What Twey posted says 'select ID from...', meaning you're only gonna get data from the ID column.

  9. #19
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It ought to show 0: Success, though.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #20
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm... Yeah.

    But if there were an error before that point, it would show that, right?

    So it doesn't realy prove what the error is from?

    Maybe you should be sure the error is right there by doing an error check like that after the last command, but before this one.

    Also, use the command die('erroritshouldsay')... that way, when/if the funciton doesn't work, it'll stop working and display your error message, making it quite clear that's exactly where it didn't work.



    PHP Code:
    mysql_query('something') or die('error doing something'); 

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
  •