Jump to content

Recommended Posts

Hi All...like the subject says im new to sql and i need a some help...

 

I have on my website a comment script which is added to many pages for people to leave comments on certain restaurants in egypt.

 

I want to place on another page how many comments have been left for each restaurant, just a simple Comments left = ?

 

I have a table called c5t_comment, inside the table i have comment_id,  comment_identifier_id,  comment_identifier, comment_status plus more.

 

All im intrested in is getting from table c5t_comment how many times in comment_identifier is = to /restaurants/hamees.php BUT comment_status = 0

 

the comment status if its = 100 it means its not been approved = 0 means it has been approved.

 

Can anyone help ?

 

Thanks

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/71592-new-and-need-help-with-retrieving-data/
Share on other sites

On the comment script forum, where no-one as posted for a long time someone had already asked the question i asked above and got this code:-

 

<?php 
$sql = "SELECT count(*) as num FROM `c5t_comment` WHERE comment_identifier='/hotels/anglo.php"; 
$result = mysql_query($sql); 
$num_comments = mysql_result ($result,0,"num"); 
?> 


<a href="/your/page/">Click here to see all <? echo $num ?> comments</a>

 

however i get this error when i run it:-

 

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/fhlinux209/l/mysite.com/user/htdocs/restaurants/testc.php on line 13

Click here to see all comments

 

line 13 is:- $num_comments = mysql_result ($result,0,"num");

 

Thanks for any help

The Query is missing a ' after .php - so should read

 

$sql = "SELECT count(*) as num FROM `c5t_comment` WHERE comment_identifier='/hotels/anglo.php'"; 

 

But is also dependant on the naming conventions of your table and fields - I would test the query in PHP myadmin or whatever DB front end you have just to make sure it returns a result - before you run in code.

 

HTH

Dave

Thanks for your reply php_dave,

 

tried that in sql and it did not work:-

 

MySQL said: #1064 - 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 '$sql = "SELECT count(*) as num FROM `c5t_comment` WHERE comment_

 

i have MySQL 4.1.15-standard - phpMyAdmin 2.6.4-pl4

Thanks all but since im very new to this and just started reading on it, is it possible 1 of you members can spare just a few mins and post me the full code what would be needed to fetch how many comments are left ? ive already learned how to connect to the database so im ok with that :) - im sure i will have hundreds more questions when i get myself more into php and sql.

 

I need to get from table c5t_comment how many times in comment_identifier that /hotels/anglo.php is listed BUT comment_status must equal 0

 

i have MySQL 4.1.15-standard - phpMyAdmin 2.6.4-pl4

 

Thanks for your patience with me

 

Keefy

Thanks fenway but im trying to write this in a php to show on my website, i thought it needed the $sql in the line ????

 

Im so sorry but i just cant get my head round it, i think that once i have the full code so that it shows on my website, then i will be able to understand it better.

 

this is what i got from the comment script site which ive added to a php file to try and get it show the result on a webpage, but it does not work:-

 

<?php require '_connect.php'; ?> //connect to the database

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
  <title></title>
</head>
<body>
<?php 
$sql = SELECT count(*) as num FROM "c5t_comment" WHERE comment_identifier='/hotels/anglo.php'"; 
$result = mysql_query($sql); 
$num_comments = mysql_result ($result,0,`num`); 
?> 


<a href="/your/page/">Click here to see all <? echo $num_comments ?> comments</a>
</body>
</html>

 

I hope im not annoying anyone in my persistence to understand this...

 

Keefy

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.