Jump to content

Loop wont produce results...


AlexMK92

Recommended Posts

Hey guys, I'm building an E-commerce store for a T-Shirt selling company, I've assembled the shopping cart etc correctly but I am having problems within building a forum based system for the site admin to post Bulletins and Notices to the homepage + a blogging page.

I am using a while loop which should iterate the results at the end of each cycle through my variable $postResult

 

Here is my code...

 

<?php

 

include_once "../scripts/db_connect.php"; // Connect to the database

// Get the section ID from the url variable coming in

$sqlout = mysql_query("SELECT * FROM blog_posts ORDER BY ordered ASC LIMIT 10");

 

if (isset($_GET['id']) && $_GET['id'] != "") {

$sid = preg_replace('#[^0-9]#i', '', $_GET['id']); // filter all characters except numbers for security

} else {

echo "ERROR: Variables to run this script have been removed from the URL.";

exit();

}

// Query the database for that section id, make sure it exists and get the section title

$sql = mysql_query("SELECT * FROM blog_category WHERE forum_id='$sid' LIMIT 1");

$numRows = mysql_num_rows($sql);

if ($numRows < 1) {

echo "ERROR: That section deos not exist you have tampered with our URLs.";

exit();

}

while($row = mysql_fetch_array($sql)){

$sectionTitle = $row["forum_title"];

}

// Use the section ID to query the "forum_posts" table in the database to get all the threads for this section

$sql = mysql_query("SELECT * FROM blog_posts WHERE type='a' AND section_id='$sid' ORDER BY date_time DESC LIMIT 10");

$postResult = '';

$numRows = mysql_num_rows($sql);

if ($numRows < 1) {

$postResult = "There are no threads in this section yet. You can be the first to post.";

} else {

while($row = mysql_fetch_array($sql)){

    $thread_id = $row["id"];

$post_author = $row["post_author"];

$post_author_id = $row["post_author_id"];

$date_time = $row["date_time"];

$convertedTime = ($myAgoObject -> convert_datetime($date_time));

        $whenPost = ($myAgoObject -> makeAgo($convertedTime));

$thread_title = $row["thread_title"];

$dynamicList .= '<img src="style/threadPic.jpg" width="26" height="18" alt="Topic" /> ' . $post_author . ' - <a href="view_thread.php?id=' . $thread_id . '">' . $thread_title . '</a> - ' . $whenPost . '<br />';

}

}

?>

 

And here is a snippet of where I echo the results in my HTML:

 

      <br /><br />

      <div style="margin-left:12px; "><?php echo $postResult; ?></div>

    <br /><br /><br /></td>

 

I have been slaving over this for hours now, the first $postResult variable will always iterate its text of "There are no threads in this section yet. You can be the first to post.", I can't see anything wrong in my SQL syntax as I have a similar set up to iterate my products to different pages and that has always worked fine

 

Any input on this would be great

 

Kind Regards

 

Alex.

 

:)

 

Link to comment
Share on other sites

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.