Hey I got some thinking problem with this code here bear with me I'm new to php i use this script and want the comments that i use atm mysq_num_rows
just to see if a can get the relevant data out. But I don't really have a clue to get it out so the relevant comment number is in the right ID like blogg id 700 for example i want it to show 34 comments and so on to the next $data
of blog. now i just get 0 0 0 0 34 comments on each blogg post showing.
Any tips or hints how I would proccide woud be great I have googled everything i could think of but my lack of experience in MYSQL
, PHP
is what holding me back i think.
COMMENTS: In comments i got ID and i got BID and the BID is where the blogg ID is fetched.
BLOG:Fetching the ID from it to the function test()
Here is some of my code
function test()
{
$resultblogs = mysql_query("SELECT * FROM blog");
while($rowblogs = mysql_fetch_array( $resultblogs )) {
$blogid = $rowblogs['id'];
$blog_comment=mysql_query("Select * from comments WHERE bid='$blogid' AND verify='1' ");
$blog_comment_count=mysql_num_rows($blog_comment);
echo $blog_comment_count;
}
}
Here is the rest of the code for you to inspect
<?php if (!isset($_GET["bid"])) { ?>
<!-- Blog Post -->
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$mysql_host = "localhost";
$mysql_database = "database";
$mysql_user = "root";
$mysql_password = "****";
$link = mysql_connect("$mysql_host", "$mysql_user", "$mysql_password") or die("Database is down, Please try again.");
mysql_select_db($mysql_database) or die("database not found!");
/*
set the pagination settings
$sql - Your sql query
$num_results_per_page - Number of results per page
$num_page_links_per_page - Number of visible page links per page
*/
$sql = "SELECT * FROM blog ORDER BY date DESC";
$num_results_per_page = 3;
$num_page_links_per_page = 5;
$pg_param = "#news"; // Ex: &q=value
pagination($sql, $num_results_per_page, $num_page_links_per_page, $pg_param);
/*
Pass 4 values to the pagination function.
No return values,
instead You can use 3 global variables set by the function.
$pg_result - mysql result id variable
$pagination_output - variable containing html pagination output
$pg_error - display any errors
*/
?>
<?php
if($pg_error == '')
{
if(mysql_num_rows($pg_result) > 0)
{
while($data = mysql_fetch_assoc($pg_result))
{
?>
<div class="type-date">
<div class="blog-type"><img src="images/blog-text.png" alt=""></div>
<div class="blog-date"><h5><?php echo $data["day"]?></h5><h5><?php echo $data["month"]?></h5></div>
</div>
<h2><a href="?bid=<?php echo $data["id"].'#news'?>"><?php echo $data["title"] ?></a></h2>
<?php
echo test();
$blogcontent = substr
($data["body"],0,600).'....<div style="margin-top:20px"><br><a class="newave-button medium color" href="?bid='.$data["id"].'#news">Läs vidare!</a></div>';
echo '<div style="margin-left:80px;">'.$blogcontent.'</div>';
echo '<hr>';
}
/*
display the pagination
you can echo $pagination_output anywhere you want
*/
echo $pagination_output;
}
else
{
echo 'No results found!';
}
}
else
{
echo $pg_error; //display any errors, you can remove this if you want.
}
?>