khan kaka Posted December 26, 2004 Share Posted December 26, 2004 how can i ask the sql to display results from two diffrent tables. wich feedid is = to id from diffrentt able ============================== SELECT content.id, messeges.feedid FROM messeges, content WHERE messeges.feedid = content.id =========================== i have designed a web log and on each topic i want others to be able to gave thier feed back. soo when user clicks on post feed back button i pass the id of topic to form by url and soo the feed back table has a field named feedid wich is equal to id of the topic. on main page i want to be able to display how money responds have been saved for each topic. i used the code above but all the topics shows same amount of responds. i am going crazy wiht this problem. thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/2104-php-and-sql/ Share on other sites More sharing options...
rocking Posted December 26, 2004 Share Posted December 26, 2004 Try using the join command: http://www.mysqlfreaks.com/statements/9.php or http://dev.mysql.com/doc/mysql/en/JOIN.html Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/2104-php-and-sql/#findComment-6893 Share on other sites More sharing options...
obsidian Posted December 26, 2004 Share Posted December 26, 2004 how can i ask the sql to display results from two diffrent tables. wich feedid is = to id from diffrentt able ============================== SELECT content.id, messeges.feedid FROM messeges, content WHERE messeges.feedid = content.id =========================== i have designed a web log and on each topic i want others to be able to gave thier feed back. soo when user clicks on post feed back button i pass the id of topic to form by url and soo the feed back table has a field named feedid wich is equal to id of the topic. on main page i want to be able to display how money responds have been saved for each topic. i used the code above but all the topics shows same amount of responds. i am going crazy wiht this problem. thanks alot 186228[/snapback] in your query, you are only telling the database to give you every entry that has a matching id. that is going to return every entry every time. what you have to do to limit it is also provide the id of the content you want to get the number of results for. you need to do something like: SELECT content.id, messages.feedid FROM messages, content WHERE messages.feedid = content.id AND messages.feedid = '1'; you could also do something like this: SELECT COUNT(*) AS count, messages.feedid FROM message, content WHERE messages.feedid = content.id GROUP BY messages.feedid; this query will return you a table with two columns: count and id. then, you just need to loop through all your results to see how many entries you have in a given id. hope this helps! Quote Link to comment https://forums.phpfreaks.com/topic/2104-php-and-sql/#findComment-6896 Share on other sites More sharing options...
khan kaka Posted December 27, 2004 Author Share Posted December 27, 2004 in your query, you are only telling the database to give you every entry that has a matching id. that is going to return every entry every time. what you have to do to limit it is also provide the id of the content you want to get the number of results for. you need to do something like: SELECT content.id, messages.feedid FROM messages, content WHERE messages.feedid = content.id AND messages.feedid = '1'; you could also do something like this: SELECT COUNT(*) AS count, messages.feedid FROM message, content WHERE messages.feedid = content.id GROUP BY messages.feedid; this query will return you a table with two columns: count and id. then, you just need to loop through all your results to see how many entries you have in a given id. hope this helps! 186304[/snapback] =============================== hi there thanks very much for you respond but it seems to be working when i try the code in dreamweaver recordset window when i test the counting it works but on the page once agin it shows the frist count on all fields. i have used repeat region server on table soo when it repeats on fields it shows the same count for all rpeated fileds. any idea Quote Link to comment https://forums.phpfreaks.com/topic/2104-php-and-sql/#findComment-6899 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.