Caffeinenyx Posted May 3, 2011 Share Posted May 3, 2011 $query ="SELECT oneID FROM table WHERE table.PersonID = 'game.PlayerA'" ; $result = mysql_query($query); $row = mysql_fetch_array($result); $oneID = $row[0]; [code] If I then echo "$oneID" why does it not print anything? $result echos resource7 Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/ Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2011 Share Posted May 3, 2011 what does print_r($row); give you? Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209846 Share on other sites More sharing options...
Caffeinenyx Posted May 3, 2011 Author Share Posted May 3, 2011 nothing Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209847 Share on other sites More sharing options...
fugix Posted May 3, 2011 Share Posted May 3, 2011 try puting this in to see if you receive any errors in your query $result = mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209848 Share on other sites More sharing options...
salathe Posted May 3, 2011 Share Posted May 3, 2011 SELECT oneID FROM table WHERE table.PersonID = 'game.PlayerA' Â Do you really have a table named table and a row with the PersonID column containing the literal characters game.PlayerA? Should game.PlayerA reference a column from a game database? Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209852 Share on other sites More sharing options...
Caffeinenyx Posted May 3, 2011 Author Share Posted May 3, 2011 yes, although the names are not the same as the ones im using, but as this is part of an assignment I remained the tables to post here. Player A is a column name in game. Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209855 Share on other sites More sharing options...
Caffeinenyx Posted May 3, 2011 Author Share Posted May 3, 2011 no errors Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209857 Share on other sites More sharing options...
PFMaBiSmAd Posted May 3, 2011 Share Posted May 3, 2011 Are you getting a completely blank page when you tried the suggestions? If so, what does a 'view source' of the page in your browser show? Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209859 Share on other sites More sharing options...
fugix Posted May 3, 2011 Share Posted May 3, 2011 i think that it might be because you are referencing the table "game" without selecting the fields from it. Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209861 Share on other sites More sharing options...
Caffeinenyx Posted May 3, 2011 Author Share Posted May 3, 2011 SELECT oneID FROM table WHERE table.PersonID = game.PlayerA Â returns unknown column game.PlayerA Â but it does exist. Â Not a blank page, just this value missing, but it may have been the double quotes. Im fairly new to php and have never used table.anything (its a good idea) Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209862 Share on other sites More sharing options...
cyberRobot Posted May 3, 2011 Share Posted May 3, 2011 To use column names from another table, you'll need to use a MySQL Join. http://dev.mysql.com/doc/refman/5.0/en/join.html   You need to join "table" and "game". Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209864 Share on other sites More sharing options...
fugix Posted May 3, 2011 Share Posted May 3, 2011 yeah, you cant reference a column that is not in the table you specified without joining the tables Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209867 Share on other sites More sharing options...
fugix Posted May 3, 2011 Share Posted May 3, 2011 SELECT column_name(s) FROM table_name1 FULL JOIN table_name2 ON table_name1.column_name=table_name2.column_name Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209868 Share on other sites More sharing options...
fugix Posted May 3, 2011 Share Posted May 3, 2011 so you would have $query ="SELECT oneID FROM table FULL JOIN games ON table.PersonID = game.PlayerA" ; Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209870 Share on other sites More sharing options...
Caffeinenyx Posted May 3, 2011 Author Share Posted May 3, 2011 Unknown column 'table.PersonID' in 'on clause' Â ?? It is correct i can view the table Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209877 Share on other sites More sharing options...
fugix Posted May 3, 2011 Share Posted May 3, 2011 try $query ="SELECT oneID FROM table FULL JOIN game ON t.PersonID = g.PlayerA" ; Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209895 Share on other sites More sharing options...
cyberRobot Posted May 3, 2011 Share Posted May 3, 2011 You need to define the table aliases before using them. So "t." and "g." won't work as the query is currently set up. Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1209897 Share on other sites More sharing options...
Caffeinenyx Posted May 3, 2011 Author Share Posted May 3, 2011 I have got it now, i did need to define them as well, Thanks everyone! Quote Link to comment https://forums.phpfreaks.com/topic/235421-why-does-this-not-print-anything/#findComment-1210034 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.