PHP question concerning the ID variable

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

PHP question concerning the ID variable

Postby thegametb » Tue Jan 03, 2006 3:54 am

I'm trying to learn how to successfully create the "id" variable in MYSQL and then manipulate the effect to show up uniquely. In other words, the thing I was thinking about doing is this:

To relieve much stress and heavy coding, I wanted to create a system in PHP for my archives (multipage feature). Instead of having the multiple pages being like archives1.php, archives2.php, and so on. I wanted something similar to archives.php?page=1, archives.php?page=2, etc. (I could do archives.php?id=page1, archives.php?id=1).

The funny thing is this PHP book I have does not discuss the "id" variable in MYSQL. I created the usual default address book with MYSQL and PHP and it didn't help much, because I couldn't figure out how to include the "ID" tag. Granted the book had me do it a little odd... It had me create a PHP page which would create the database and fields (w/o using PHPMyAdmin). Anyways, I wanted to do something as above and incorporate the multipage and have the "include" parameter in PHP include the TXT multipages.

I wanted to create the system that I could also parse usual pages like instead of having multiple pages for a certain section like say the legal portion of a corporate website. Instead of having multiple webpages like copy.php, faq.php, terms.php, policy.php, etc. I want something to parse those active pages to a single webpage such as corp.php?id=faq.

I could go either way on renaming the ID variable or use it. I just thought I'd throw this out to see how difficult it would be. I don't think I well solve this issue as easy as I figured out the previous PHP issue I had for Coranto.

Best example I could find to help what I want things the end result to look like is... http://www.thewrestlingchannel.tv/promotions.php?id=tna

Let me know if you want me to ellaborate or anything above. I tend to ramble on sometimes. Things that may seem clear to me, may not always seem clear for others.
User avatar
thegametb
 
Posts: 109
Joined: Mon Jul 05, 2004 11:38 am

Postby bozoka45 » Tue Jan 03, 2006 4:43 am

First off, let me recommend devshed for PHP questions. I literally got 10 replies to a thread within an hour when I had a few questions.

Secondly, the "id" variable is just a name to use within your script. It could be whatever you want, it could be "coranto","frog", or "football" (ie: page.php?coranto=1).

Variables within the url are accessed through the $_GET variable. For example, you grab the ID number with $_GET['id']. That would return the value of "id" from the url, 1, 2, 3, etc.

Now, what you do with that is no telling.

I'm not sure exactly what you mean, but when you say you want to create the "id variable in MySQL," are you refering to an index (an index is a unique key that points to a certain row, Coranto's newsid for example).

As for a quick example for how you could use page number and an SQL database for archives, this should be pretty simple.

Let say you have 20 news items, and you want 5 news items per page. Well, the id can tell you which number to use.

Code: Select all
$start_id = ($_GET['id']-1) * 5;

SELECT * FROM database WHERE ... LIMIT $start_id,5;


The five after the comma in the LIMIT clause tells it to display 5 items from the database. The first number, the variable, we can change so we change the starting point to extract from.

If the ID is 1, then we start at 0 (SQL is like an array, the first index is 0). If the ID is 2, then we start at entry 5, if the id is 3, we start at 10, etc.
User avatar
bozoka45
 
Posts: 1159
Joined: Sun Mar 23, 2003 8:38 pm
Location: New Orleans

Postby thegametb » Tue Jan 03, 2006 5:02 am

I personally would much rather not even have to use MySQL and the id field in it, but I'm unsure if I could create the same effect just within a PHP file.

I would just like to create something simple and not too complicated, which I'm thinking might be hard with something of this nature. I want it to instead of input data, create the variable either via phpmyadmin (if I need mysql) or within the PHP file. Most people use this method to input data in a form field and then have it output the generated page.

Exactly how Coranto does this in Perl. I want to do this slightly different, however, with the same logic somewhat intacted. Use PHP or a mysql inputted data to basically parse a TXT or some other external file on the server.

An example would be, terms.php (terms of use) and corp.php that would have a link leading to this file. I would have corp.php?id=terms. In turn it would be the same exact file, but websites seems more sophisticated to a novice when it has the id variable or some piacular string after the ususal URL. It's just cosemetics stuff, but I personally think it looks cool.

I've done something similar to what the wrestling website I linked in the first post. It was the end result to my last PHP project... http://www.pwfzone.com/tb/roleplay.php . It does something close to this effect using coranto profile TXT files. I want to do the same, but with the multipage addon and have the TXT files parse thru the id variable in the URL string... if that made any sense LoL.
User avatar
thegametb
 
Posts: 109
Joined: Mon Jul 05, 2004 11:38 am

RESOLVED!

Postby thegametb » Tue Jan 03, 2006 8:16 am

This is the code they responded with and is exactly as I wanted. Oddly enough it's extremely short and doesn't have to work with mysql and the other headaches that come along with setting it up.

Code: Select all
<?php

 if($_GET['id']  == 'copy'){

//load the copyright webpage
include "copy.php";

} elseif ($_GET['id'] == 'main'){

//loads main webpage
include "main.php";

}

?>
User avatar
thegametb
 
Posts: 109
Joined: Mon Jul 05, 2004 11:38 am

Postby bozoka45 » Tue Jan 03, 2006 9:32 am

That example will work, althought it will be quite messy if you have alot of pages to load. There's a few ways of doing it, but, if you have alot of pages, and array would work nicely.

Code: Select all
$file = array('copy' => 'copy.php',
                  'main' => 'main.php');

include($file[$_GET['id']]);
User avatar
bozoka45
 
Posts: 1159
Joined: Sun Mar 23, 2003 8:38 pm
Location: New Orleans

Postby thegametb » Wed Jan 04, 2006 1:59 am

Exactly. I've already found that myself testing the potiential of the code he sent me. I personally don't have an extreme amount for this, but I have a roster that is somewheres around of 30+ and it could make things lengthy.

Right now I have this SSIed in to my header.php file. The only problem is this error I kept receiving when I try to initiate your code:
Code: Select all
Warning: main(): Failed opening '' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/USER/public_html/wee2.php on line 6


This is what I put in as wee2.php:
Code: Select all
<?php

$file = array('copy' => 'corporate/copy.php',
                  'prototype' => 'stars/prototype.php');

include($file[$_GET['id']]);

?>


I tried a few different ways of cleaning up the include portion, but it doesn't like it for some odd reason. Other than this minor problem, you've been awesome help on this matter. Thanks.
User avatar
thegametb
 
Posts: 109
Joined: Mon Jul 05, 2004 11:38 am

Postby bozoka45 » Wed Jan 04, 2006 4:04 am

It means it can't find the file to include, your paths are wrong. Try putting the entire path in the include statement, or a relative path, ie "./corporate/"
User avatar
bozoka45
 
Posts: 1159
Joined: Sun Mar 23, 2003 8:38 pm
Location: New Orleans

Postby thegametb » Wed Jan 04, 2006 4:48 am

Oh yeah. It originally they have the complete URL to the files. I just didn't want them all shown here.
User avatar
thegametb
 
Posts: 109
Joined: Mon Jul 05, 2004 11:38 am

Postby bozoka45 » Wed Jan 04, 2006 6:07 am

thegametb wrote:Oh yeah. It originally they have the complete URL to the files. I just didn't want them all shown here.


Don't use the URL, use the path (do an echo on $_SERVER['DOCUMENT_ROOT']).
User avatar
bozoka45
 
Posts: 1159
Joined: Sun Mar 23, 2003 8:38 pm
Location: New Orleans


Return to Customization

Who is online

Users browsing this forum: No registered users and 2 guests

cron