Jump to content


Photo

php and sql


  • Please log in to reply
3 replies to this topic

#1 khan kaka

khan kaka
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts
  • Locationaustralia

Posted 26 December 2004 - 06:19 AM

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 :unsure:

khan kaka

#2 rocking

rocking
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationScotland!

Posted 26 December 2004 - 06:11 PM

Try using the join command:

http://www.mysqlfrea...tatements/9.php

or

http://dev.mysql.com...ql/en/JOIN.html

Hope this helps :)
Wow! It's calling me a guru now!

Search Synchronizer

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 26 December 2004 - 08:59 PM

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  :unsure:

View Post


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!
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 khan kaka

khan kaka
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts
  • Locationaustralia

Posted 27 December 2004 - 03:05 AM

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!

View Post


===============================

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 :unsure:
khan kaka




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users