#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    9
    Rep Power
    0

    **mysql get result or mysql query question??


    Hi,

    I'm curious how this 2 funcs. work.

    Basically, I have to generate a php page which has the result from 2 different queries.

    In a function, I call mysql_query or get_result 2 times.
    First, I fetch a result and send it to another func to put it in layout.
    Then, I try to fetch the result from different query to send to the layout function again.(the result from 2 query supposed to be in same page)

    The problem is first query is fine, but I can't get the second query. It said can't execute. Basically, it's die. I check the query, and it works fine in database. Just don't work in php function.

    So, can anyone give me the idea how this function work and store data?

    Can't I use get_result function 2 times in a row??

    Anyway to solve this problem??

    Thanks in advance.

  2. #2
  3. No Profile Picture
    I AM A GOLDEN GOD
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Apr 2003
    Location
    Camarillo, California
    Posts
    5,929
    Rep Power
    1170
    mysql_query() runs the SQL query on the database you've selected.

    mysql_result() gets a single result from the SQL query you've just run.

    They are mutually exclusive of one another a far as functions are concerned; they don't perform the same function in other words. You can certainly run a number of other functions on the query results returned from mysql_query(), but you can't run any of them without the query in the first place. Hope this in someway answers your question.

    If you have some code you're having a problem with, post a scrap of it and I'm sure we can help you out.
    "Seriously, we're not a search engine, we're actual people." ~ ManiacDan

    BookMooch.com : Give books away. Get books you want.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    9
    Rep Power
    0
    Thank for helping me out here.

    My code is long. So, I will give some example of code that I have problem with.


    $query ="select ... from table x";
    $query2 = "select ... from table y";

    $result = mysql_query($query) or die ("query can't execute");
    xy($result);
    $result2 = mysql_query($query2) or die ("query can't execute");//function die here. It said that query can't execute. I print out query2 and try it manually directly in database, and it works fine.

    xy($result2);

    function xy ($result){

    while( $row = fetch_row($result)){
    print"<tr><td>$row[0]</td></tr>";

    }
    }

    function xy also work fine. Since it print out the result from query1 correctly.

    I don't understand why mysql_query($query2) can't execute query since query itself correct and work fine in database??

    Any idea?? Thanks for any suggestion!!
    Last edited by minemo; December 30th, 2003 at 08:10 PM.
  6. #4
  7. No Profile Picture
    I AM A GOLDEN GOD
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Apr 2003
    Location
    Camarillo, California
    Posts
    5,929
    Rep Power
    1170
    PHP Code:
    $result2 mysql_query($query2) or die ("query can't execute");
    /*
    function die here. It said that query can't execute.
    I print out query2 and try it manually directly in database, and it works fine. 
    */ 
    Change your mysql_query() statement to give you an actual error so you understand what the problem is.
    PHP Code:
    $result2 mysql_query($query2) OR die("query2 error: " mysql_error()); 
    "Seriously, we're not a search engine, we're actual people." ~ ManiacDan

    BookMooch.com : Give books away. Get books you want.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    9
    Rep Power
    0
    Thanks so much.

    The problem is from my bug. It accidently call to my second database. If you didn't suggest the error query, I would still hang over with my stupidity.

    Thanks again.

    Happy New Year 2004. Wish you have a nice new year.

IMN logo majestic logo threadwatch logo seochat tools logo