SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $query doesn't work?

    PHP Code:
    <? 
    $db 
    mysql_connect("localhost","xzazx","pass"); 

    mysql_select_db (xzazx); 

    $max="SELECT max_exp FROM exp1 WHERE pid='1'";

    $query="SELECT cur_exp FROM exp1 WHERE cur_exp > $max AND pid='1'";
    $result=mysql_query($query);
    if(@
    mysql_num_rows($result))
    {
      echo 
    "<h1>You HAve Gaimned an LEVEL!!</h1>";
    }
    else
    {

    ?>
    why doesn;t this work?
    thx!
    _o_ OOP _o_

  2. #2
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IF pid is numeric, you do not have to enclose the value in quotes.
    PHP Code:
    $query="SELECT cur_exp FROM exp1 WHERE cur_exp > $max AND pid=1"
    And, what is the value of $max?

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_select_db is looking for a string as the arguement, try putting it in quotes mysql_select_db(xzazx');

    in your $max variable try putting () around it like this also: $max="(SELECT max_exp FROM exp1 WHERE pid='1')";

    in your if, you could also try comparing @mysql_num_rows($result) > 0 or something like that.

  4. #4
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm.... MySQL can't do subqueries. Also what rect said.
    Line should read:
    mysql_select_db ("xzazx");

  5. #5
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As far as I know, mysql can do sub queries...

    PHP Code:
    <? 
    $db 
    mysql_connect("localhost","xzazx","pass"); 

    mysql_select_db (xzazx); 

    $max"SELECT max_exp FROM exp1 WHERE pid='1'";

    $query="SELECT cur_exp FROM exp1 WHERE cur_exp > ('$max') AND pid='1'";
    $result=mysql_query($query);
    if(@
    mysql_num_rows($result))
    {
      echo 
    "<h1>You HAve Gaimned an LEVEL!!</h1>";
    }
    else
    {

    ?>
    That should work, as far as I know.. But then again, I'm a moron ;P
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  6. #6
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no thats not the pb,
    it does select the database, and connects to it, but just doesn't write the text I wan't..
    btw the $max = 100.
    _o_ OOP _o_

  7. #7
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yoz XzAzX!

    pardon me for asking a silly question but what exactly is the text that you want to be displayed?

  8. #8
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now that its morning and my mind is fresh, I'm wondering something. Why not change:
    PHP Code:
    $max"SELECT max_exp FROM exp1 WHERE pid='1'";
    $query="SELECT cur_exp FROM exp1 WHERE cur_exp > ('$max') AND pid='1'"
    To:
    PHP Code:
    $query="SELECT cur_exp FROM exp1 WHERE cur_exp > max_exp AND pid='1'"

  9. #9
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by redemption
    yoz XzAzX!

    pardon me for asking a silly question but what exactly is the text that you want to be displayed?
    it is there :
    you have gained an level!
    _o_ OOP _o_

  10. #10
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by CyberFuture
    Now that its morning and my mind is fresh, I'm wondering something. Why not change:
    PHP Code:
    $max"SELECT max_exp FROM exp1 WHERE pid='1'";
    $query="SELECT cur_exp FROM exp1 WHERE cur_exp > ('$max') AND pid='1'"
    To:
    PHP Code:
    $query="SELECT cur_exp FROM exp1 WHERE cur_exp > max_exp AND pid='1'"
    yes this works!
    thx m8ies!
    _o_ OOP _o_


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
  •