• 0

How to make PHP subpages with ID?


Question

Recommended Posts

  • 0

You could try something like this:

<?php

switch($_GET['id'])
{
case 1:
include 'mypage.html';
break;
case 2:
include 'mysecondpage.html';
break;
default:
include 'home.html';
}

?>

Just add more cases to the switch to include more files and IDs, or you could use a database with the IDs in it and page references to include.

Smctainsh

  • 0

?php

switch($_GET['id'])
{
case 1:
include 'mypage.php';
break;
case 2:
include 'mysecondpage.php';
break;
default:
include 'home.php';
}

?>

OK.. so i put this in index.php..

for the links to work..

<a href="mypage.php?id=1">My page</a>

<a href="mysecondpage.php?id=2">Second Page</a>

???

  • 0
  NYU_KID said:
?php

switch($_GET['id'])
{
case 1:
include 'mypage.php';
break;
case 2:
include 'mysecondpage.php';
break;
default:
include 'home.php';
}

?&gt;

OK.. so i put this in index.php..

for the links to work..

<a href="mypage.php?id=1">My page</a>

<a href="mysecondpage.php?id=2">Second Page</a>

???

if you pasted that code in your index.php file, all of the links should be:

index.php?id=1 (to call mypage.php)

index.php?id=2 (to call mysecondpage.php)

etc.

  • 0

This is how I'd do it:

1) index.php

&lt;?php
$query = $_GET['p'];

$query = strtolower($query);
$space = array(' ','%20');
$path = str_replace($space,'_',$query);

if (!file_exists('./content/'.$path.'.php')) {$path = '404'; $title = 'Error 404';}		// Error 404

require_once('./source/template.php');
?&gt;

template.php

&lt;!--html here--&gt;&lt;?php include './content/'.$path.'.php'; ?&gt;&lt;!-- more hml --&gt;

where the include is the middle section aka content portion of your page.

  • 0
  NYU_KID said:
?php

switch($_GET['id'])
{
case 1:
include 'mypage.php';
break;
case 2:
include 'mysecondpage.php';
break;
default:
include 'home.php';
}

?&gt;

OK.. so i put this in index.php..

for the links to work..

<a href="mypage.php?id=1">My page</a>

<a href="mysecondpage.php?id=2">Second Page</a>

???

OK, I got everything to work.. but somehow.. when i click on mypage.php?id=1.. it doesn't replace the content from mypage.php ... ???

post-141808-1169088981_thumb.jpg

  • 0

you should be clicking on a link for index.php?id=1, not mypage.php?id=1

also, in the index.php file that you're using for this, there should be no content, only structural objects. all of the content is stored inside of the separate php files like mypage.php, mysecondpage.php, and home.php.

i assume that you just copied and pasted the code we gave you after some content in your existing index.php file. you can't do that.

  • 0

I actually wanted to make it for my blog pages.. without using wordpress..

ex. blog.php?id=1 (for january 17, 2007), blog.php?id=2 (for january 18, 2007)..

so i should leave blog.php empty.. with the php code and structural objects?

Edited by NYU_KID
  • 0

here are the bare essentials what you should have in your blog.php file for it to retrieve a specific blog entry:

&lt;?php
// Define the id you want to retrieve from the url
$id = $_GET['id'];

// Build the mysql query and corresponding array of retrieved information
$query = mysql_query("SELECT * FROM blogTable WHERE id='$id'");
$entry = mysql_fetch_row($query);

/* Here's where you would escape out of php and back into it
in order to format things for you */
?&gt;

one thing i STRONGLY recommend is to create a function that has all of the formatting information in it that will take the different parts of the mysql row as arguments. this way, you can use a loop to call the function several times, once per row, and have a list of blog entries. trust me, this will help a lot later on as you develop your script.

  • 0
  CeruleanCowboy said:
here are the bare essentials what you should have in your blog.php file for it to retrieve a specific blog entry:

&lt;?php
// Define the id you want to retrieve from the url
$id = $_GET['id'];

// Build the mysql query and corresponding array of retrieved information
$query = mysql_query("SELECT * FROM blogTable WHERE id='$id'");
$entry = mysql_fetch_row($query);

/* Here's where you would escape out of php and back into it
in order to format things for you */
?&gt;

one thing i STRONGLY recommend is to create a function that has all of the formatting information in it that will take the different parts of the mysql row as arguments. this way, you can use a loop to call the function several times, once per row, and have a list of blog entries. trust me, this will help a lot later on as you develop your script.

I would love to create a function that has all the formatting information in it.. but that is also complex.. for me, a beginner working with php language. I don't even get the bare essential code for my blog.php :(

  • 0
  CeruleanCowboy said:
what parts of it don't you get? i'll see if i can't explain them.

OK, that code you gave me, I put it into my blog.php file.. without editing any parts of the code? and how do i retrieve past entries using that code? How do i set up a function and loop it?

the other code..

&lt;?php

switch($_GET['id'])
{
case 1:
include 'blog.php';
break;
case 2:
include 'blog2.php';
break;
default:
include 'index.php';
}

?&gt;

this seems easier?

also.. can someone give me different examples of scroll bar types? except from the regular ones?

..and last..

is there a different between ?page=blog and blog.php?id=1 ??

THANKS AGAIN guys.

  • 0
  CeruleanCowboy said:
here are the bare essentials what you should have in your blog.php file for it to retrieve a specific blog entry:

&lt;?php
// Define the id you want to retrieve from the url
$id = $_GET['id'];

// Build the mysql query and corresponding array of retrieved information
$query = mysql_query("SELECT * FROM blogTable WHERE id='$id'");
$entry = mysql_fetch_row($query);

/* Here's where you would escape out of php and back into it
in order to format things for you */
?&gt;

one thing i STRONGLY recommend is to create a function that has all of the formatting information in it that will take the different parts of the mysql row as arguments. this way, you can use a loop to call the function several times, once per row, and have a list of blog entries. trust me, this will help a lot later on as you develop your script.

  golfantastic said:
OK, that code you gave me, I put it into my blog.php file.. without editing any parts of the code? and how do i retrieve past entries using that code? How do i set up a function and loop it?

the other code..

&lt;?php

switch($_GET['id'])
{
case 1:
include 'blog.php';
break;
case 2:
include 'blog2.php';
break;
default:
include 'index.php';
}

?&gt;

this seems easier?

also.. can someone give me different examples of scroll bar types? except from the regular ones?

..and last..

is there a different between ?page=blog and blog.php?id=1 ??

THANKS AGAIN guys.

first, i'll dissect this:

&lt;?php
/* $_GET is a superglobal associative array that retrieves values from the url. So, let's say that the url is as follows:
http://www.yoursite.com/blog.php?entry=1&date=23

$_GET would have the following values:
$_GET['entry'] == 1
$_GET['date'] == 23

It retrieves all values from the url after the question mark. Each variable and it's value are separated by an =, and each set is separated by an &amp;.

$_POST is the same kind of associative superglobal, only it doesn't retrieve values from the url, only server-side sent information, like from an html form.
*/

// Define the id you want to retrieve from the url
$id = $_GET['id'];

/*
mysql_query() is a function that will generate a mysql query to manipulate your database. You'll need to look up stuff on mysql and all of the commands and syntax because it's too numerous to fit into any single post.

mysql_fetch_row() is a function that returns an array starting at index 0 with each column. Let's say that you have a table with the following columns: name, phone, age; and one row containing the information John, 1234567, 24.

By using mysql_query() to create a query to find the information, and mysql_fetch_row() to assign that data to an array, you would get this.

$query = mysql_query("SELECT name, phone, age FROM users");
$data = mysql_fetch_row($query);

$data[0] == "John";
$data[1] == 1234567;
$data[2] == 24;
*/

// Build the mysql query and corresponding array of retrieved information
$query = mysql_query("SELECT * FROM blogTable WHERE id='$id'");
$entry = mysql_fetch_row($query);

/* Here's where you would escape out of php and back into it
in order to format things for you */
?&gt;

for the function, you'd have something like this:

function blogEntryFormat(title, message){
  ?&gt;

&lt;div id="title"&gt;&lt;?php echo $title; ?&gt;&lt;/div&gt;
&lt;div id="message"&gt;&lt;?php echo $message; ?&gt;&lt;/div&gt;

  &lt;?php
}

to loop through all entries in the table and output all of the messages with that function, you'd do this:

$query = mysql_query("SELECT title, message FROM blog");
while($data = mysql_fetch_row($query)){
   blogEntryFormat($data[0], $data[1]);
}

the while loop will continue to retrieve individual rows and perform the operations inside of the loop until there are no more rows left to analyze based on the query you entered.

if you're looking ONLY for a way to use one template file to generate other pages for your site, like if you have a page for your portfolio, one for home, and one for links, and all have the same design and html structure, you would use the switch command from the other page. you'd just take whatever content is on each page and put it into a corresponding file. it would look like this:

&lt;div id="mainContent"&gt;
&lt;?php
$page = $_GET['page'];
switch($page){
   case "portfolio": include("portfolio.php"); break;
   case "links": include("links.php"); break;
   default: include("home.php"); break;
}
?&gt;
&lt;/div&gt;

if someone went to the url http://www.yourpage.com/index.php?page=links then whatever is in the links.php page would be output. but if someone went to just http://www.yourpage.com/index.php, then home.php would be output.

  • 0
  CeruleanCowboy said:
yes, you would, but you shouldn't have that many.

by the way, let me ask now, what are you actually trying to do?

on my blog.php, i want to be able to have only my most recent 2 entries displayed on blog.php file..and then older entries on blog.php?id=1,2,3 so i can click 'BACK" or "NEXT" to my older or newer entries..

such.. click on BACK.. to blog.php?id=2 .. or NEXT to blog.php?id=1 ...

i dont really need the subpages on my index.php or any other pages... just focusing on blog.php

i'm reading http://www.php-mysql-tutorial.com/index.php for help as of now..and still a bit confused.

post-141808-1169181058_thumb.jpg

  • 0

here's what your code should be.

&lt;?php
if(isset($_GET['id'])){

  // Get and output the entry of the id in the url
  $id = $_GET['id'];
  $query = mysql_query("SELECT * FROM blog WHERE id = '$id'");
  $data = mysql_fetch_assoc($query);
  blogFormat($data['title'], $data['message'], whatever other columns you want to output);

  // Check for first and last entries
  $query = mysql_query("SELECT id FROM blog ORDER BY id DESC LIMIT 1");
  $data= mysql_fetch_row($query);
  $last = $data[0];
  $query = mysql_query("SELECT id FROM blog ORDER BY id ASC LIMIT 1");
  $data= mysql_fetch_row($query);
  $first = $data[0];

  // Output Back and Next if the entry the user is looking at is less than the latest id and greater than the first
  if($id &gt; $first){ echo "&lt;a href=\"blog.php?id=".$id-1."\">Back</a>&lt; $last){ echo "&lt;a href=\"blog.php?id=".$id+1."\">Next</a>

// Output the latest two entries if no entry is specified in the url
$query = mysql_query("SELECT * FROM blog ORDER BY id DESC LIMIT 2");
while($data = mysql_fetch_assoc($query)){
  blogFormat($data['title'], $data['message'], whatever other columns you want to output);
}
?&gt;

  • 0

mine's just a short script to retrieve a blog entry based on an id in the url or the 2 latest entries.

the link you just provided is for an entire class that will process all of the blog entries and do quite a bit more. i wouldn't touch it since you're new to php.

  • 0
  CeruleanCowboy said:
did you just copy and paste the code verbatim?

things like this "whatever other columns you want to output" shouldn't be in there.

do you think you could paste the entire code of your blog.php file in this thread?

&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;
&lt;HEAD&gt;
&lt;title&gt;Blog&lt;/title&gt;
&lt;link rel="stylesheet" type="text/css" href="style.css">t;!--[if IE 7]&gt;
&lt;link rel="stylesheet" type="text/css" href="iestyle.css" media="screen" /&gt;
&lt;![endif]--&gt;

&lt;/HEAD&gt;

&lt;body id="home"&gt; 
&lt;div id="col1i"&gt;
&lt;img src="/header56.jpg" alt="header"&gt;
&lt;/div&gt;

&lt;div id="col2i"&gt;
&lt;img src="/navigation7.jpg" alt="navigation"&gt;
&lt;table bgcolor="#ffffcc" width=238px height=21px&gt;
  &lt;tbody&gt;
	&lt;tr&gt;
			&lt;td align=center&gt;
&lt;a href="/contact.php">Contact</a>;a href="/blog.php">Blog</a>;a href="/"&gt;Home&lt;/a&gt;

&lt;/td&gt;
	&lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;br&gt;
&lt;?php
if(isset($_GET['id'])){

  $id = $_GET['id'];
  $query = mysql_query("SELECT * FROM blog WHERE id = '$id'");
  $data = mysql_fetch_assoc($query);
  blogFormat($data['title'], $data['message'];

  $query = mysql_query("SELECT id FROM blog ORDER BY id DESC LIMIT 1");
  $data= mysql_fetch_row($query);
  $last = $data[0];
  $query = mysql_query("SELECT id FROM blog ORDER BY id ASC LIMIT 1");
  $data= mysql_fetch_row($query);
  $first = $data[0];

  if($id &gt; $first){ echo "&lt;a href=\"blog.php?id=".$id-1."\">Back</a>&lt; $last){ echo "&lt;a href=\"blog.php?id=".$id+1."\">Next</a>

$query = mysql_query("SELECT * FROM blog ORDER BY id DESC LIMIT 2");
while($data = mysql_fetch_assoc($query)){
  blogFormat($data['title'], $data['message'];
}
?&gt;

&lt;div id="blog"&gt;
&lt;table bgcolor=#ffffcc width=610px&gt;
  &lt;tbody&gt;
	&lt;tr&gt;
		  &lt;td&gt;
&lt;p&gt;dsa&lt;/p&gt;
&lt;ul id="navigation"&gt;
&lt;li class="left"&gt;&lt;a href="/"&gt; &lt;&lt; Back&lt;/a&gt;&lt;/li&gt;
&lt;li class="right"&gt;&lt;a href="#"&gt;Archives&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/td&gt;
	&lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • uBO works best in gecko based browsers. If you don't believe me, believe the developer of uBO:) He is a firefox user for a reason:) https://github.com/gorhill/uBl...rigin-works-best-on-Firefox
    • Kdenlive 25.04.2 by Razvan Serea Kdenlive is an acronym for KDE Non-Linear Video Editor. It works on GNU/Linux, Windows and BSD. Through the MLT framework, Kdenlive integrates many plugin effects for video and sound processing or creation. Furthermore Kdenlive brings a powerful titling tool, a DVD authoring (menus) solution, and can then be used as a complete studio for video creation. Kdenlive supports all of the formats supported by FFmpeg or libav (such as QuickTime, AVI, WMV, MPEG, and Flash Video, among others), and also supports 4:3 and 16:9 aspect ratios for both PAL, NTSC and various HD standards, including HDV and AVCHD. Video can also be exported to DV devices, or written to a DVD with chapters and a simple menu. Video editing features: Multi-track editing with a timeline and supports an unlimited number of video and audio tracks. A built-in title editor and tools to create, move, crop and delete video clips, audio clips, text clips and image clips. Ability to add custom effects and transitions. A wide range of effects and transitions. Audio signal processing capabilities include normalization, phase and pitch shifting, limiting, volume adjustment, reverb and equalization filters as well as others. Visual effects include options for masking, blue-screen, distortions, rotations, colour tools, blurring, obscuring and others. Configurable keyboard shortcuts and interface layouts. Rendering is done using a separate non-blocking process so it can be stopped, paused and restarted. Kdenlive also provides a script called the Kdenlive Builder Wizard (KBW) that compiles the latest developer version of the software and its main dependencies from source, to allow users to try to test new features and report problems on the bug tracker. Project files are stored in XML format. An archiving feature allows exporting a project among all assets into a single folder or compressed archive. Built-in audio mixer Highlights from the Kdenlive 25.04.2 update: Remember title editor window width Fix audio thumbnails have an offset in long files Fix OTIO import path on Windows Better feedback when auto mask fails Fix OTIO export tracks order and ensure .otio file extension is correctly added Full Changelog Fix moving subtitle with grab. Fix empty gradient in config causes crash. Snapcraft: Give more permissions for microphone access. Backport missing effects xml. Fix quick markers not taking clip crop into account in timeline. Fix marker dialog not allowing to add marker if only 1 category exists. Fix merge error causing freeze on exit. Fix crash in HistogramGenerator when running on a white color clip. Fix Whisper model directory not being created if asked to do so. Fix canceling quit on rendering leaves kdenlive in unstable state. Only clear undo stack when we delete a timeline sequence, not a standard bin clip. Fix misalignment of monitor tools CCBUG: 498337 CCBUG:461219. Fix OTIO path issue on import, related to #1998. Fix bin clip effects disappear after disabling a timeline clip. Fix keyframe in monitor not correctly reported on clip selection. Fix monitor scene not correcty activated on clip selection. Fix small error causing offset in long audio thumbnails. Fix guides list buttons not working on app opening. Fix built-in effects disabled state changes on cut. Fix render widget target file can have no extension or incorrect path. SAM2: show message and full log if the python script crashes, try to auto reinstall if the venv python exe is missing. Save and restore title editor window width. Download: Kdenlive 25.04.2 | 116.0 MB (Open Source) Download: Standalone Executable Links: Kdenlive Home page | Other Operating Systems Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I use Edge on my Mac. Edge is lightning fast and does everything. Never had an issue with it. It alsoi allows the use of the original uBlock Origin extension, which Chrome does not allow anymore. I hate ads.
    • AIMP 5.40 Build 2682 by Razvan Serea AIMP is a powerful audio player that allows you to listen to your favorite music with an outstanding sound quality. Its appearance resembles that of another classical audio player (Winamp). The program includes a 20-band equalizer, a visualization window to display rhythmic visual effects and a playlist editor to organize your audio files. A nice fading effect makes your list of songs look like an endless music loop and a handy volume normalizing feature avoids drastic volume changes between tracks. Also, the players main functions can be conveniently controlled by global hotkeys. Besides playing music, AIMP features three extra utilities which also enable you to record any sound on your computer, convert audio files from one format to another and view or edit tags. AIMP is based on the well-known audio engine BASS, so its easy to connect new plug-ins (from the plug-in library included in the program) and expand the players functionality. Main Features and Functions: Multi-Format Playback: Supports numerous audio formats, including CDA, AAC, AC3, APE, DTS, FLAC, IT, MIDI, MO3, MOD, M4A, M4B, MP1, MP2, MP3, MPC, MTM, OFR, OGG, OPUS, RMI, S3M, SPX, TAK, TTA, UMX, WAV, WMA, WV, XM, DSF, DFF, MKA, AA3, AT3, OMA, WebM, MDZ, ITZ, S3Z, XMZ, AIFF, and MPEG-DASH (YouTube). CUE Sheet Support: Enables the use of CUE sheets for managing audio tracks. Output Support: Compatible with DirectSound, ASIO, WASAPI, and WASAPI Exclusive output methods. 32-Bit Audio Processing: Utilizes 32-bit audio processing for optimal sound quality. Internet Radio: Allows listening to internet radio stations in OGG, WAV, MP3, AAC, and AAC+ formats, with the capability to capture streams in various formats. Bookmarks and Playback Queue: Facilitates creating bookmarks and managing a playback queue. Rating and Auto-Marks: Collects statistics on track listening and automatically calculates ratings and marks for listened tracks. Plugin Support: Allows the addition of new utilities or extensions to existing features through plugins. Built-in Scrobbler: Supports Last.fm, Libre.fm, and ListenBrainz services for scrobbling. Cloud Integration: Supports OneDrive, Google Drive, DropBox, Облако@mail.ru, Яндекс.Диск, and custom WebDAV clouds. Podcasts: Offers podcast support for subscribing and listening. Hotkeys: Allows configuration of local and global hotkeys. Multi-User Mode Support: Supports multiple users working on one computer. Multi-Language Interface: Provides a multi-language interface. 4K and High DPI Support: Supports scale factors of 125%, 150%, 175%, and 200% for high-resolution displays. Flexible Program Options: Offers customizable program settings. Flexible UI: Charm UI: A modern flat-style skin with 4K and High DPI support. Bliss 4K: A skin-transformer from AIMP4 included in the installation package. Pandemic: The classic skin from AIMP3 included in the installation package. User Skins: Access to a catalog of user-created skins. Sound Effects: 20-Band Equalizer and Built-in Sound Effects: Includes Reverb, Flanger, Chorus, Pitch, Tempo, Echo, Speed, Bass, Enhancer, and Voice Remover effects with flexible settings. Volume Normalization: Features peak-based normalization and Replay Gain, along with logarithmic and loudness-compensated volume control. Mixing Options: Offers Fade In/Fade Out, cross-mixing, and pause between tracks. Silence Remover: Removes silence from tracks for a seamless listening experience. Music Library: Music Library: Organizes music files, allows setting marks for listened tracks, and keeps playback statistics. Smart Playlist: Creates playlists based on content from the Music Library database, with filtering and grouping capabilities. Playlists: Multiple Playlists: Supports working with multiple playlists simultaneously. Powerful View Settings: Allows data display customization, track grouping, and separate settings for each playlist. Content Protection: Provides the ability to block content from changes. File Search: Enables searching files across all opened playlists. AIMP 5.40 Build 2682 changelog: Audio converter: support for relative paths Plugins: analog meter - installing skins using general approach to install addons Sound engine: resampler algorithm has been improved Player: AB part repeat - an ability to change milliseconds via dialog Skin engine: compatibility with the Start11 app Skin engine: memory consumption during skin loading has been reduced Fixed: Tags editor - data in tags with multiple values ​​​​may be duplicated in certain cases Fixed: tag editor - ID3v2.4 - multiple genre values ​​cannot be loaded Fixed: skin engine - minor issues has been fixed Fixed: issues from incoming crash-reports Download: AIMP 64-bit | AIMP 32-bit ~20.0 MB (Freeware) View: AIMP Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Can you point out where his walkthrough of Mozilla's finances are lies?
  • Recent Achievements

    • Reacting Well
      Alan- earned a badge
      Reacting Well
    • Week One Done
      IAMFLUXX earned a badge
      Week One Done
    • One Month Later
      Æhund earned a badge
      One Month Later
    • One Month Later
      CoolRaoul earned a badge
      One Month Later
    • First Post
      Kurotama earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      494
    2. 2
      ATLien_0
      267
    3. 3
      +FloatingFatMan
      223
    4. 4
      +Edouard
      199
    5. 5
      snowy owl
      141
  • Tell a friend

    Love Neowin? Tell a friend!