Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 5 of 5

Thread: Query not working.

  1. #1

    Query not working.

    ok... i'm not sure where the problem is here...

    $start is equal to the number of rows in the blog table (this is working and its 1)
    $display = 5 (the number of entries i want per page this is for pagination)
    USERID = 1 (this is a constant set by an included page thats all i need to tell you)

    PHP Code:
    $query "SELECT name, blog_id FROM blog ORDER BY blog_id DESC LIMIT $start$display WHERE author_id=" USERID;
    $result mysql_query($query);

    '<form action="comm_handle.php" method="post"><table>';

    if (
    $result) {
    //Do something
    } else {
    'You Currently Have no blogs.';

    THe error message "You Currently Have no blog" keeps being displayed...but there is data in the database >.<

    My database currently looks like this.

    In the 'blog' table there is 1 row:
    blog_id: 1
    name: Almost Finished!
    content: some content is here.
    author_id : 1
    posted_on: the date it was posted.

    the point of the page i was building was to display all blog titles and under them all the comments stored for the blogs.

    so inside the if($result) { condition if have

    PHP Code:
    if (mysql_num_rows($result) > 0) {
    // fetch and display results
    } else {
    // display a different error than the one im getting

    If i remove the first condition if($result)
    then i get this error message (not one i programmed)

    mysql_num_rows(): supplied argument is not a valid MySQL result resource
    what am i doing wrong?

    Twitter / The Human Conditions

    biznuge: "that doesn't grammatical sense..."

  2. #2
    Do you ever connect to the database and supply login credentials?

  3. #3
    yes i just didn't feel the need to post that.

    Twitter / The Human Conditions

    biznuge: "that doesn't grammatical sense..."

  4. #4
    cause your query is malformed and in the wrong order perhaps ...
    PHP Code:
    $query "SELECT name, blog_id FROM blog WHERE author_id = " USERID " ORDER BY blog_id DESC LIMIT $start$display"
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  5. #5
    i found out the issue.

    one thank you simplistik the order was a problem.

    and 2nd i was using a foreach loop to pull out the info instead of a while loop.

    Now it's working.

    Thanks everyone.

    Twitter / The Human Conditions

    biznuge: "that doesn't grammatical sense..."

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012