pocobueno1388 Posted July 12, 2007 Share Posted July 12, 2007 Hello I am trying to use variables in my query, but I'm not having any luck. Here is the query: <?php $getEntries = mysql_query("SELECT (h.$stat1 + h.$stat2 + h.$stat3) AS total, s.showID, s.horseID FROM horses h, show_entries s WHERE s.showID = '{$show['showID']}' AND s.horseID = h.horseID")or die(mysql_error()); ?> The part I am having trouble with is: (h.$stat1 + h.$stat2 + h.$stat3) It is returning "24" for each row, and that isn't what it should be returning, I have no idea where it is getting that number from. I'm thinking that when I put h.$stat1 it is thinking I am wanting to concate, when I don't. I actually want it to display the dot as that is how to define which table I am selecting that value from. How can I do this and get the right results? Any help is greatly appreciated, thanks xD Link to comment https://forums.phpfreaks.com/topic/59582-solved-need-help-using-variables-in-query/ Share on other sites More sharing options...
Illusion Posted July 12, 2007 Share Posted July 12, 2007 try this h.'$stat1'+h.'$stat2'+h.'$stat3' Link to comment https://forums.phpfreaks.com/topic/59582-solved-need-help-using-variables-in-query/#findComment-296163 Share on other sites More sharing options...
pocobueno1388 Posted July 12, 2007 Author Share Posted July 12, 2007 Nope, that gave me a syntax error. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''conformation' + h.'intelligence' + h.'strength') AS total, s.showID, s.horseID ' at line 2 Link to comment https://forums.phpfreaks.com/topic/59582-solved-need-help-using-variables-in-query/#findComment-296432 Share on other sites More sharing options...
Illusion Posted July 12, 2007 Share Posted July 12, 2007 so ur variables are interpreted properly , and why don't u try a left join SELECT horseid,(h.$stat1 + h.$stat2 + h.$stat3) AS total from horses as h left join show_entries as s on h.horseid=s.horseid where s.showID = '{$show['showID']}' Link to comment https://forums.phpfreaks.com/topic/59582-solved-need-help-using-variables-in-query/#findComment-296470 Share on other sites More sharing options...
Illusion Posted July 12, 2007 Share Posted July 12, 2007 and one more thing u have used h.horseID in where condition which is not there in selected columns so it might be returning Cartesian product no of records. Link to comment https://forums.phpfreaks.com/topic/59582-solved-need-help-using-variables-in-query/#findComment-296486 Share on other sites More sharing options...
pocobueno1388 Posted July 12, 2007 Author Share Posted July 12, 2007 That is giving me the same result as I had before, it is returning "24" as total from all the rows...maybe this isn't a problem with the query, and I'm just making a mistake. Let me go check it out again to make sure. and one more thing u have used h.horseID in where condition which is not there in selected columns so it might be returning Cartesian product no of records. I added h.horseID to the select part and still got the same result. Link to comment https://forums.phpfreaks.com/topic/59582-solved-need-help-using-variables-in-query/#findComment-296494 Share on other sites More sharing options...
pocobueno1388 Posted July 12, 2007 Author Share Posted July 12, 2007 Ahhhh! The query has been working perfectly the entire time. I was adding EVERY row in the DB instead of just the 3 I selected. Also, the 3 that I selected just happened to all add up to 24 on each row...that was just a major coincidence. Thanks for your help xD Link to comment https://forums.phpfreaks.com/topic/59582-solved-need-help-using-variables-in-query/#findComment-296504 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.