The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 16, 2019, 01:38:28 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: List creation help  (Read 2746 times)
rasputin
n00b
*
Offline Offline

Posts: 9


View Profile
« on: May 25, 2010, 01:58:26 PM »

I have a database of movie titles (id,title) that I want to create into pages. One page per movie title in my database.
The page creation process already works..

But on each page, I wish to create a list that links to the previous 15 and next 15 movie titles.

What I am trying to do is, in the While loop for creating movie title pages, I take the movie title id, say 25.

Then I get make two new values, like this:

Code:
    $titleid = $row['id'];
    $titleidmax = $titleid + 15;
    $titleidmin = $titleid - 15;

then I am attempting to

query the server something like this:

Code:
$query = "SELECT * FROM $table WHERE id >$titleidmin OR id >0 OR id <$titleidmax LIMIT 30";
$gettitles = mysql_query($query) or die(mysql_error());

i am thinking that $gettitles would have an array of 30 movie titles, the previous 15 and next 15 in it. Then I also added >0 incase the id is in the first 15 and there arent 15 previous titles to pull from...

gah I am probably not making any sense.

But basically this isnt working. Hopefully you get the concept of what I am trying to do and can point me in the write direction or tell me what im doing wrong.

Summary of what im trying to do:
In a array loop, I am trying to select titles within a range, that are not currently in the loop, so that I can add extra links to my pages.


Logged

No links in signatures please
rasputin
n00b
*
Offline Offline

Posts: 9


View Profile
« Reply #1 on: May 25, 2010, 02:02:32 PM »

When I var_dump($getnames) it returns:

resource(x) of type (mysql result)

replace x with

15, 30, 45, 60, 75, etc (divisible by 15.)
Logged

No links in signatures please
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #2 on: May 25, 2010, 02:33:42 PM »

lemme guess, your getting back ALL your records?
You have ORd yourself into ALL.
Code:
$query = "SELECT * FROM $table WHERE id >$titleidmin OR id >0 OR id <$titleidmax LIMIT 30";
should be
Code:
$query = "SELECT * FROM $table WHERE id >$titleidmin AND id <$titleidmax LIMIT 30";
You dont actually need the id>0 check, since I assume all your ids are greater than zero anyway.
1 is greater than -5 just the same.

Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
rasputin
n00b
*
Offline Offline

Posts: 9


View Profile
« Reply #3 on: May 25, 2010, 04:21:02 PM »

How would I output it correctly?

Say I wanted to use each one once...

currently im using: var_dump($gettitles);

and its giving me:




oh and all this code, is within of course the other array while loop
Logged

No links in signatures please
rasputin
n00b
*
Offline Offline

Posts: 9


View Profile
« Reply #4 on: May 25, 2010, 04:58:25 PM »

Bah, I figured it out. Its quite frustrating when you are trying to solve the problem but you are approaching it from the wrong direction...

I was trying to echo the links in cmd, to test, but thats what appeared instead.

When I actually output them into the pages, they showed up. Bah. im not going to think about this one.

A couple other fixes, errors and now my script works great.

Although what you told me Nutballs wasnt the solution I was looking for, it was a barrier towards me getting to that solution, so it would have been frustrating had I continued to try to fix it without that fix. Cheesy
Logged

No links in signatures please
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #5 on: May 31, 2010, 02:11:39 PM »

glad I could help in some roundabout way. i didnt notice your followup post, so sorry i left ya hangin.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!