Jump to content

[SOLVED] Links not updating


zyrolasting

Recommended Posts

I'm trying to fuel a simple navigation system for a news section. It works fine when it comes to retrieving and displaying data, but if I click on a valid link in the following code, the content and links do not update like they should. All hrefs stay the same and the content does not change. Why is this?

 

require('../scripts/chron.php');

$con = openConnect();

// Get current entry ID, using -1 to mark an unavailable param.
$entry  = (isset($_GET['id'])) ? $_GET['id'] : -1;

// Query table for vital entry info
$type = 'news';
$count = getEntryCount($type);

// Go to latest entry if param is unavailable.
if ( $entry = -1 ) $entry = $count;

// Build links for navigation
$first  = $entry<=1 ? 'undef' : 0;
$prev	= $entry<=1 ? 'undef' : $entry-1;
$next	= $entry < $count ? $entry+1 : 'undef';
$last	= $entry < $count ? $count : 'undef';

echo '<div class="newsLinks"><p>';
echo ($first != 'undef') ? ('<a href="index.php?id='.$first.'">First</a> - ') 	: ('First - ');
echo ($prev  != 'undef') ? ('<a href="index.php?id='.$prev.'">Previous</a> - ') : ('Previous - ');
echo ($next  != 'undef') ? ('<a href="index.php?id='.$next.'">Next</a> - ') 	: ('Next - ');
echo ($last  != 'undef') ? ('<a href="index.php?id='.$last.'">Last</a>') 		: ('Last');
echo '</p></div>';

$row = getEntryRow($type,$entry);

// Display entry
echo '<h1 class="centerHead" id="Title">'			. $row['title']		. '</h1>';
echo '<h3 class="centerHead" id="DatePosted">'	. $row['datePosted']. '</h3>';
echo '<div class="newsBody" id="CurrentContent">'	. $row['content']	. '</div>';

Link to comment
Share on other sites

Bump.

 

Reason: I still need assistance on this issue, and I have gone about a week without updating my site because of it and similar ones, making it a fairly high priority as I do have content to share. I only ask you be patient with me, as I am still inexperienced. I rephrased my question below in hopes of getting replies.

 

I use a $_GET variable called id, which holds an integer I use to nab a row in a mySQL table. When the page is being parsed, I have 4 links on the page that link to the very same page, but just uses a modified id that is relative to the current one to navigate my database. If I load my page and get to the latest entry (index.php?id=2, for example), and to want to go to the "previous" page, I click on "previous" which links to (index.php?id=1). This was a bare bones system suggested to me on this forum recently.

 

Now, in the code block above you see I use isset and _GET to determine if I need to rely on _GET to choose my page, or if I should get the latest entry instead to start from. In my case I have 2 entries total so far. 'Previous' is clickable and the href I see in the status bar is as I expect... it links to the same page, changing 'id' to 1. FYI, the ids in my table are 1-based.

 

My problem out of all this is that when I click one of these links to fire off my request, nothing gets updated.

At all. I just do not understand why. The code block above has some functions not listed here, but they are working and need not be shared. All code in the OP is just a relevant subset.

 

Your assistance will be appreciated.

 

Thank you for your time.

Link to comment
Share on other sites

Thanks for the reply. You may, but I think it's fine considering I can get at least one entry from it.

 

function getEntryRow($type,$id)
{
$result  = mysql_query("SELECT * FROM " . $type . " WHERE id=" . $id );
if (!is_resource($result))
{
	die(mysql_error());
}

// Grab current entry row
$row = mysql_fetch_array( $result );
if ( !$row )
{
	die('Could not retrieve row: '.mysql_error());
}

return $row;
}

 

$type is literally a table name from the database selected in the openConnect function in OP. I know everything related to establishing a connection to and querying from mySQL is fine. It's just an issue of being unable to, ehrm, make these queries again.

 

Would the fact I'm on localhost have anything to do with this? I am on WAMPServer/Dreamweaver. I see other forum members have issues where they were suggested to get on a real server. FYI in that respect: My only real server access holds my site. I don't want to debug on my site itself!

 

Link to comment
Share on other sites

should be

 

if ( $entry == -1 ) $entry = $count;

 

 

besides that i dont see a problem

 

...As it turns out, that was the defining issue. It works now. Thank you for catching that!

Having the entry get forced back to $count in OP meant I could never leave the entry I was on. I feel stupid.  :-\

Damn one character errors ruin everything!

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.