Jump to content

Recommended Posts

I have a simples code a wanted to implement that as been giving me some headaches

I 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. =/
Link to comment
https://forums.phpfreaks.com/topic/11836-query-select-problem/
Share on other sites

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. =/
Link to comment
https://forums.phpfreaks.com/topic/11836-query-select-problem/#findComment-45015
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/11836-query-select-problem/#findComment-45069
Share on other sites

[!--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.
Link to comment
https://forums.phpfreaks.com/topic/11836-query-select-problem/#findComment-45971
Share on other sites

[!--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.
Link to comment
https://forums.phpfreaks.com/topic/11836-query-select-problem/#findComment-46005
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.