Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

PHP question

Asked Modified Viewed 2,495 times
W
woodnotoil
W
  • Junior Member, joined since
  • Contributed 22 posts on the community forums.
  • Started 11 threads in the forums
  • Started this discussions
asked
Junior Member

I have a database with a table with products and a seperate table with reviews of the products. Each product has an id and each review has a field that contains a value assigning it to a product (the number matches the product id). I would like to be able to determine how many reviews there are for a product and assign that value to a string in order to display it. For this example assume:

$id is the "id" from the "product" table and the field in the "review" table is called "productid"

Thanks for the help!
0 replies

4 posts

G
googlebot
G
Visit the new home of the merge between Hacking Vs. Security and Security Override!
My copyright removal has been switched over from HvS to SecurityOverride.
  • Senior Member, joined since
  • Contributed 638 posts on the community forums.
  • Started 28 threads in the forums
answered
Senior Member

First make an array, add it to maincore.php

something along the lines of:

while ($reviews = mysql_array(mysql_query("SELECT * FROM reviews WHERE productid = ".$id.""))) {

echo $reviews['review'];

}

That should output the reviews, grabbing them all from the DB. Note you will have to edit the code..
0 replies
B
bite
B
bite 10
  • Member, joined since
  • Contributed 163 posts on the community forums.
  • Started 5 threads in the forums
answered
Member

This code will output number of reviews for product with specific id:
<?php
$id='1';//id of the product
$q=mysql_fetch_row(mysql_query('SELECT COUNT(*) FROM reviews WHERE productid = '.$id));
echo 'there are '.$q[0].' reviews';
?>
Edited by bite on 06-01-2010 13:21,
0 replies
W
woodnotoil
W
  • Junior Member, joined since
  • Contributed 22 posts on the community forums.
  • Started 11 threads in the forums
  • Started this discussions
answered
Junior Member

I used the code "bite" provided and it works! Thanks - WNO
0 replies
— 2 months later —
W
White women
W
  • Newbie, joined since
  • Contributed 2 posts on the community forums.
  • Started 1 thread in the forums
answered
Newbie

You may try to make php arrays. How it is work you may learn more detail at this article.

Mod; fixed link
Edited by HobbyMan on 19-03-2010 00:41,
0 replies

Category Forum

General Discussion

Labels

None yet

Statistics

  • Views 0 views
  • Posts 4 posts
  • Votes 0 votes
  • Topic users 4 members

4 participants

G
G
Visit the new home of the merge between Hacking Vs. Security and Security Override!
My copyright removal has been switched over from HvS to SecurityOverride.
  • Senior Member, joined since
  • Contributed 638 posts on the community forums.
  • Started 28 threads in the forums
B
B
bite 10
  • Member, joined since
  • Contributed 163 posts on the community forums.
  • Started 5 threads in the forums
W
W
  • Junior Member, joined since
  • Contributed 22 posts on the community forums.
  • Started 11 threads in the forums
  • Started this discussions
W
W
  • Newbie, joined since
  • Contributed 2 posts on the community forums.
  • Started 1 thread in the forums

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet