Page 1 of 1

Efficient way of getting info

Posted: Mon Jun 06, 2011 2:44 pm
by EcazS
I'm working on a little page system and I was just wondering the best way of getting the info.
I have the regular stuff in my table, id, page_name, page_body but I also have two other fields, isHome and isBlog, so if either of those are true (they're bool) I only wanna get the info from those pages.

And just to minimize my query usage I use the same query to get the page_name for navigation links.

I was thinking I could pass a variable in the URL and then set up an if statement to check if the variable is set and if it is it will execute a query to get the specific info.

But I will end up with two queries then, is there someway I could do this in just one?
'Cause right now I need one query to get the navigation info and if I then wanna get the content of the specific page I need another one. It's not a terrible slow down, just asking if there is a more efficient way...

Re: Efficient way of getting info

Posted: Mon Jun 06, 2011 3:45 pm
by jacek
EcazS wrote:so if either of those are true (they're bool) I only wanna get the info from those pages.

Not really sure what you mean :?

EcazS wrote:But I will end up with two queries then, is there someway I could do this in just one?

you could use a JOIN or UNION if its appropriate. What is the content you are getting for the navigation, a list of pages ? Or full HTML ?

Re: Efficient way of getting info

Posted: Mon Jun 06, 2011 4:06 pm
by EcazS
I don't think a join would be good for this.

Right now I have it set up like this,
id name order body isHome isBlog

and then I'm getting the Name and echoing it like a navigation list. I currently have two rows,
1 Home 0 Homepage 1 0
2 Blog 10 0 1

And this is the query I'm using,
[syntax=sql]
SELECT
`name`,
`content`,
`isBlog`,
`isHome`
FROM `pageinfo` ORDER BY `order` ASC[/syntax]

But if I wanted to get the content of the active link (index.php?page=home) I would have to use WHERE in the query with the GET variable. So that would be two queries, right? But I also wanna check if the active link is the blog (isBlog = 1).

Two queries on a page isn't that much and it's not going to slow down very much. But still, wanna try and get it in one, is possible.

Re: Efficient way of getting info

Posted: Mon Jun 06, 2011 7:02 pm
by jacek
EcazS wrote:But if I wanted to get the content of the active link (index.php?page=home) I would have to use WHERE in the query with the GET variable. So that would be two queries, right? But I also wanna check if the active link is the blog (isBlog = 1).

So you want the `name` for all pages and the `content` for the one being viewed ? That will have to be two queries I think. It's good that you are trying to use as few as possible, but as you say 2 is not loads :D

Re: Efficient way of getting info

Posted: Mon Jun 06, 2011 7:06 pm
by EcazS
Alright, I'll go for two then :D