Jump to content

[SOLVED] Why am I having such trouble with this?! [WAMP]


zyrolasting

Recommended Posts

Hey guys.

 

EDIT: Sorry about the double post! I misclicked.

 

I'm trying to make a bare bones news section with 4 links to navigate: First, Previous, Next, Last. That's it. However, I could not get the thing to work for several days and I need to update my site!

 

I tried using AJAX and it failed on IE and FF. I called Brinkster asking about what several forums suggest: that AJAX can fail on a local host. The rep tells me that if it doesn't work for me, it probably won't work on the server, so... nuts.

 

What is the BARE MINIMUM I can do to set up a respectable chronological archive using WAMP?

I am an utter novice that honestly has no idea. Whether it's using a cookie to keep track of the current entry the user is on or AJAX, I failed somewhere and I don't have some debugging IDE that I know of to help me see why. I'm not asking for code or any sort of freebie. I just need to know where to start because it's apparent I have no clue what I'm doing. :'(

 

My experience with XHTML and JS is great. I know PHP's syntax and how/where the code runs, but it's server-side only execution is really awkward for me! I'm still taking my first steps. My site is already online, and I'm itching to update it.

Hey guys.

 

I'm trying to make a bare bones news section with 4 links to navigate: First, Previous, Next, Last. That's it. However, I could not get the thing to work for several days and I need to update my site!

 

I tried using AJAX and it failed on IE and FF. I called Brinkster asking about what several forums suggest: that AJAX can fail on a local host. The rep tells me that if it doesn't work for me, it probably won't work on the server, so... nuts.

 

What is the BARE MINIMUM I can do to set up a respectable chronological archive using WAMP?

I am an utter novice that honestly has no idea. Whether it's using a cookie to keep track of the current entry the user is on or AJAX, I failed somewhere and I don't have some debugging IDE that I know of to help me see why. I'm not asking for code or any sort of freebie. I just need to know where to start because it's apparent I have no clue what I'm doing. :'(

 

My experience with XHTML and JS is great. I know PHP's syntax and how/where the code runs, but it's server-side only execution is really awkward for me! I'm still taking my first steps. My site is already online, and I'm itching to update it.

One of the most common methods for tracking page in this situation is the url. For example...

 

http://www.mysite.com/news/?page=2

 

$cur_page = $_GET['page'];
$row = mysql_fetch_assoc(mysql_query("SELECT COUNT(id) as page_count FROM table"));
$page_count = $row['page_count'];
echo '<a href="/news/?page=1">First</a>';
echo '<a href="/news/?page="'.$cur_page-1.'">Prev</a>';
echo '<a href="/news/?page="'.$cur_page+1.'">Next</a>';
echo '<a href="/news/?page='.$page_count.'">Last</a>';

 

Disclaimer: There are lots of 'holes' in security here, it's just to give you an idea.

Disclaimer: There are lots of 'holes' in security here, it's just to give you an idea.

 

And that is indeed all I need. Thank you very much. I had something a little like this, but it was on the other side of the non-functioning AJAX layer. Hell, I'll refresh the page if I have to as long as I can get it to work at first. Just out of curiosity, what are the security holes? If this method is common, they can't be that bad, right?

They are more bugs than 'security holes' as the code stands at the moment. If $cur_page is equal to 1 or $page_count then the previous/next buttons will break. It doesn't validate what it's getting from $_GET['page'] so if the person types ?page=cheese in the url then it will mess up. This would turn into a security flaw if you used...

 

"SELECT * FROM table WHERE id = $cur_page"

 

etc. etc.

Wait, there is something else I don't understand. What kind of URL is this? It doesn't look complete.

/news/?page=X

 

I got your suggestion partially... What I did was have the PHP link to the same page I'm on with a different id param.

The first / takes you to your site root so in the users browser they would actually see http://www.example.com/news/?page=X the reason the end looks like that is because I think that's a darn site neater than http://www.example.com/news/index.php?page=X. Essentially speaking it is loading the DirectoryIndex of the news folder, this by default is index.php (or .html).

Ok then. I guess I need to force a refresh of the page in order for my content to update on this system though, right? I still am not able to go back to an older entry. Everything else seems fine at this point. Thank you thus far!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.