uha666 Posted June 13, 2006 Share Posted June 13, 2006 I have a simples code a wanted to implement that as been giving me some headachesI have this query:$result=mysql_query(" select * from char where ". getStat('name') ." = 1 ");< (char and name are table names) >In wich i'm trying to call out this function:function getStat($pname){ $query = "SELECT `data` FROM `char` WHERE `name`='$pname'"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $pdata = mysql_fetch_array($result); $pinfo = explode(" ", $pdata[0]); return $pinfo[34]; }The function works perfect in other sections of my site. I just can't seem to get the correct syntax on the query so that it does the compare with the value 1 correctly. Each time i run the query it never returns any valid rows although there are some. Is it because i do a function with a query inside another query? Is there any way i can make this work?Thanks in advance. =/ Quote Link to comment https://forums.phpfreaks.com/topic/11836-query-select-problem/ Share on other sites More sharing options...
fenway Posted June 13, 2006 Share Posted June 13, 2006 I guess the first question is why you're not doing the whole thing in MySQL -- no need to get PHP involved. Second question -- [34]? Are you sure that's what you mean -- you want the 33rd field? I'm very confused. Quote Link to comment https://forums.phpfreaks.com/topic/11836-query-select-problem/#findComment-44855 Share on other sites More sharing options...
uha666 Posted June 13, 2006 Author Share Posted June 13, 2006 Don't mind the function cause that's working fine. I'm using php cause this is part of a website so i need it to be displayed in a browser. my only problem is that i must have some error in the way i do the query cause it never returns values from the function, i think i might have the syntax wrong. =/ Quote Link to comment https://forums.phpfreaks.com/topic/11836-query-select-problem/#findComment-45015 Share on other sites More sharing options...
radalin Posted June 13, 2006 Share Posted June 13, 2006 What is the thing that works ok? I didn't get it because you mean that everything is fine with the code at other parts but there is problem with this one? So it's more then a variable problem than a syntax or anything else problem. Because syntax errors returns errors. put an echo command for your qeury just before sending them to the db. You will probably remark that a variable is missing somewhere. Probably you will see:SELECT `data` FROM `char` WHERE `name`=''but I'm not very sure. Quote Link to comment https://forums.phpfreaks.com/topic/11836-query-select-problem/#findComment-45069 Share on other sites More sharing options...
uha666 Posted June 15, 2006 Author Share Posted June 15, 2006 [!--quoteo(post=383316:date=Jun 13 2006, 10:22 AM:name=radalin)--][div class=\'quotetop\']QUOTE(radalin @ Jun 13 2006, 10:22 AM) [snapback]383316[/snapback][/div][div class=\'quotemain\'][!--quotec--]What is the thing that works ok? I didn't get it because you mean that everything is fine with the code at other parts but there is problem with this one? So it's more then a variable problem than a syntax or anything else problem. Because syntax errors returns errors. put an echo command for your qeury just before sending them to the db. You will probably remark that a variable is missing somewhere. Probably you will see:SELECT `data` FROM `char` WHERE `name`=''but I'm not very sure.[/quote]I just want to know what's the correct syntax to use a function inside a query so i can compare the return value of that function with the value 1. Quote Link to comment https://forums.phpfreaks.com/topic/11836-query-select-problem/#findComment-45971 Share on other sites More sharing options...
fenway Posted June 15, 2006 Share Posted June 15, 2006 [!--quoteo(post=384254:date=Jun 15 2006, 12:19 PM:name=Dex)--][div class=\'quotetop\']QUOTE(Dex @ Jun 15 2006, 12:19 PM) [snapback]384254[/snapback][/div][div class=\'quotemain\'][!--quotec--]I just want to know what's the correct syntax to use a function inside a query so i can compare the return value of that function with the value 1.[/quote]There's no "correct" syntax -- you're breaking out a string and concatenating the result of a PHP function, no different than in any other part of PHP. MySQL doesn't "know" how you're put the query together. I don't understand your question. Echo of values of both $query variables before you issue them, and you'll see the problem. Quote Link to comment https://forums.phpfreaks.com/topic/11836-query-select-problem/#findComment-46005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.