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 8432425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:07:24+00:00 2026-06-10T06:07:24+00:00

I want my page to display a button for next and previous paragraph, on

  • 0

I want my page to display a button for “next” and “previous” paragraph, on the condition that there is a “next” or “previous” paragraph.

Here’s what I have so far. I start from the paragraph id that I know and I look for the preceding and following paragraph, which I load into separate variables.

Then I check to make sure a preceding or next paragraph exists. I then tell the computer to show the link, only if the paragraph exists.

Currently everything is working except for the test for $nextPid. The test for $prevPid works fine. When I am at the first paragraph no link for for ‘previous paragraph’ shows up, but when I am at the last paragraph in the file a link for ‘new paragraph’ still shows up.

Any ideas what I could be doing wrong?

$xmldoc = simplexml_load_file('/tmp/lecture.xml');
$prevPid = $xmldoc->xpath("//p[@id='$refPid']/preceding::p[1]/@id"); 
$nextPid = $xmldoc->xpath("//p[@id='$refPid']/following::p[1]/@id");

if (sizeof($nextPid) > 0)
 {
  echo "<a id=\"adjParNxt_$nextPid[0]\" class='adjPara' data-refPid=\"$refPid\" data-    adjPid=\"$nextPid[0]\" data-refFs=\"$refFs\">Next Paragraph</a> ";
 } 
if (sizeof($prevPid) > 0)
 {
  echo "<a class='adjPara' data-refPid=\"$refPid\" data-adjPid=\"$prevPid[0]\" data-    refFs=\"$refFs\">Previous Paragraph</a>";
 }

The data I’m working with can be found here http://jeffreycwitt.com/xml_data.xml

  • 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-06-10T06:07:25+00:00Added an answer on June 10, 2026 at 6:07 am

    Your code is trying to do the right thing, but bumping into a minor issue. In old versions* of PHP, SimpleXMLElement::xpath() would wrongly return FALSE in some edge cases. In more recent, fixed, versions it returns an empty array.

    The PHP version that you’re running the code on must be one which is returning FALSE. The problem is that sizeof(FALSE) is 1, meaning that your condition is always true.

    What to do?

    Well, my first piece of advice is to upgrade PHP to something more recent!

    If you really must keep the old version of PHP, then you can change the if statements to be like the following, which will continue to work if/when you do upgrade.

    if (!empty(…)) 
    

    Notes

    • The wrong behaviour exists in versions PHP 5.2.0-13 and 5.3.0-2 and 5.3.7-8.
    • For why sizeof(FALSE) returns 1, read the count() manual page.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a php page to 'display' a pdf. Here is the code: <?php
I want to display images on a .net page which I load from database
I want to display a 404 Error if a user reaches a page that
I want to display all the project 's tasks in a page, given that
Basically I have a table that is being used to display data from an
On the previous page, the user is going to click a button from a
I would like to have 'Next' and 'Previous' buttons on my page but when
I have 10 images on a page which has 2 buttons: next and previous.
I have an html page. On that page I want to open popup window.
I have written a text inside h2 and next to that i want to

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.