Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7597921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:16:42+00:00 2026-05-30T22:16:42+00:00

When I try to enter in an ID field to tag my individual posts

  • 0

When I try to enter in an ID field to tag my individual posts (post-id:1932, etc.), the value always prints as 0, instead of the database’s value.

The query takes the $_REQUEST’s topic variable (generated from clicking a link).

Here is my code:

 <?php

 require_once 'connect.php';

 $topic = $_REQUEST['topic'];

 // Build the SELECT statement
 $select_posts =
 "SELECT p.topic, p.title, p.pic_id, p.snippet, p.content, p.author_id, p.date FROM posts p WHERE p.topic =  '" . $topic . "' OR p.topic='Admin' ORDER BY p.date DESC";

 // Run the Query
 $result = mysql_query($select_posts);

 ?>

 <?php
   $post_count=0;
   while ($post_count<10 && $posts = mysql_fetch_array($result)) {
       $posts_row = sprintf(
           '<entry>
               <headline>%s</headline>
                    <pic><img class=inlinepic src=/Sustenance/assets/post-pics/%d.jpg></pic>
                    <snippet class=on id="%d snippet">%s</snippet>
                    <readmore id="readmore%d" class=on onclick=readmore("%d")>Read More</readmore>
                    <content id="%d" class="less">%s
                        <readmore class=on onclick=readless(%d)>Show Less</readmore>
                    </content>
                    <byline>
                        <by>by</by>
                        <author>%s</author>
                    </byline>
            </entry>',
       $posts['topic'], $posts['title'], $posts['pic_id'], $posts['post_id'], $posts['snippet'], $posts['post_id'], $posts['post_id'], $posts['post_id'], $posts['content'], $posts['post_id'], $posts['author_id']);
       echo $posts_row;
       $post_count++;
  }
 ?>

What I find odd is the ‘pic_id’ prints properly and pulls in the correct picture, but even when I tried to reuse the pic_id in the $divid it doesn’t work. I’ve tried replacing the $divid with $posts[‘id’], using all the different integer type specifiers in the PHP Manual, and even using inline php.

Do I have a syntax error? Why does it keep printing out 0?

EDIT: I have posted the query as per requested

EDIT 2: Removed the $divid variable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:16:43+00:00Added an answer on May 30, 2026 at 10:16 pm

    You do have to put the line

    $divid=$posts['post_id'];
    

    inside your while loop. The way it is now it tries to get a value of $posts['post_id'] already before it is assigned for the first time in the loop head and therefore is 0 and never changes (since it’s never reassigned).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a field where people enter their IP. So I try to validate
I try to post the values from the input field with the jquery.ajax function
I have a repeating field (say size 10) in my Filemaker database and try
hi i'm trying to do some exception handling and intercept a repeated field value
I have just one text field where a user can enter there username or
I try to use all here in this combination: <SCRIPT LANGUAGE=JavaScript> function CountLeft(field, count,
I'm trying to update the value in a MYSQL enum field from PHP via
I have a database field of dateTime, I'm added a DateTimePicker Control into the
I have a custom control with a field where the user will enter a
A user enters URLs in a box like this: google.net google.com I then try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.