Pereiti prie turinio

PHP, puslapiavimas!


Rekomenduojami pranešimai

Sveiki sveiki, pradejau programuoti savo puslapy, nesu profesionalas :cool_xmas: pirma syki bandau, iskilo beda. Bandziau ideti puslapiavima, padariau administruojamas naujienas, idedu naujienas ir pagrindiniame puslapyje noriu puslapiavima padaryti. Tai va, bedos tokios ir toksai kodas:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>websitename</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="wrapper">

<div id="top" class="clear">
	<h1><a href="www.websitename.eu">Websitename</a></h1>
</div>

<div id="core">
	<div id="nav" class="clear">
		<ul>
			<li class="selected"><a href="index.php">home</a></li>
			<li><a href="tutorials.php">tutorials</a></li>
			<li><a href="downloads.php">downloads</a></li>
			<li><a href="about.php">About</a></li>
			<li><a href="contacts.php">contact</a></li>
		</ul>
	</div>

	<div id="body" class="clear">
		<div id="sidebar" class="column-right">
			<ul>	
				<li>

					<h4><span>Categories</span></h4>
					<ul>
					  <li><a href="/news/photoshop/">Photoshop Files</a></li>
					  <li><a href="/news/php_scripts/">PHP Scripts</a></li>
					  <li><a href="/news/templates/">Templates</a></li>
					  <li><a href="/news/cms_mods/">CMS mods</a></li>
					  <li><a href="/news/other/">Other</a></li>
					</ul>
				</li>
				<li>
					<h4><span>Partners</span></h4>

					<ul>

						<li><a href="/advertisement.php" title="title">Your Name Here</a> - some rondom info or describtion about your fabolous website!</li>
						<li><a href="/advertisement.php" title="title">Your Name Here</a> - some rondom info or describtion about your fabolous website!</li>
						<li><a href="/advertisement.php" title="title">Your Name Here</a> - some rondom info or describtion about your fabolous website!</li>
						<li><a href="/advertisement.php" title="title">Your Name Here</a> - some rondom info or describtion about your fabolous website!</li>
						<li><a href="/advertisement.php" title="title">Your Name Here</a> - some rondom info or describtion about your fabolous website!</li>
						<li><a href="/advertisement.php" title="title">Your Name Here</a> - some rondom info or describtion about your fabolous website!</li>

					</ul>
				</li>

			</ul>
		</div>
		<div id="content" class="column-left">
			<?php
			//The following PHP script queries and displays the contents of the MySQL table.

//Connecting to the MySQL database
require('dbconnect.php'); 

//Should we show a single item or a list?
if($_GET['action'] == "view") {
//Display a single result.
$id = $_GET['id'];

//The MySQL query. Select all from the table news where the ID equals the id sent in URL.
$query = "SELECT * FROM news WHERE ID='$id'";
//Executing the query.
$result = mysql_query($query) or die(mysql_error());
//Displaying the results of the query.
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);
//nl2br() translates all newlines ('n') as HTML tags.
$content = nl2br($content);
echo "<h2>$title</h2><br>
<small>Written by $author on $date</small><br>

$content";
}
} else {
//Since we're not displaying a single result,
//we're going to display a list of results.
//The MySQl query. Selects all from the table news with a limit of 5 results.

$query = "SELECT * FROM news ORDER BY ID DESC LIMIT 10";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.
extract($row);

//nl2br() translates all newlines ('n') as HTML tags.
$content = nl2br($content);
echo "<h3><a href='view.php?action=view&id=$ID'>$title</a></h3>
  <small>Written by $author on $date</small></br>
  $content";

}
}
if($_GET['page']) // Is page defined?
{
	$page = $_GET['page']; // Set to the page defined
}else{
	$page = 1; // Set to default page 1
}
$max = 10; // Set maximum to 10
$cur = (($page * $max) - $max); // Work out what results to show
$getdata = mysql_query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT $cur, $max") or die(mysql_error()); // select the results
$data = mysql_fetch_array($getdata); // get the data
$counttotal = mysql_query("SELECT * FROM `news` ") or die(mysql_error()); // select all records		
$counttotal = mysql_num_rows($counttotal); // count records
$total_pages = ceil($counttotal / $max); // dive the total, by the maximum results to show 
if($page > 1){ // is the page number more than 1?
			$prev = ($page - 1); // if so, do the following. take 1 away from the current page number
			echo '<center><a href="?page=" . $prev . ""><br><br>« Previous</a></center>'; // echo a previous page link
			}
for($i = 1; $i <= $total_pages; $i++) // for each page number
			{
				if($page == $i) // if this page were about to echo = the current page
					{
						echo '<center><br><br><b>' . $i . '</b> '; // echo the page number bold
							} else {
						echo '<a href="?page=' . $i . '>' . $i . '</a> </center>'; // echo a link to the page
					}
			} 
if($page < $total_pages){ // is there a next page?
				$next = ($page + 1); // if so, add 1 to the current
			echo '<a href="?page=' . $next . '">Next »</a>'; // echo the next page link
				} 
//Close the connection.
mysql_close($connection);
?>

			<br /><br />
		</div>
	</div>

	<div id="footer" class="clear">
		<div class="ul">
			<ul class="clear">
				<li><a href="index.php">Home</a></li>
				<li><a href="services.php">Services</a></li>
				<li><a href="advertisement.php">Advertisement</a></li>
				<li><a href="sitemap.php">Site Map</a></li>
				<li><a href="contacts.php">Contact</a></li>
			</ul>
		</div>
	</div>
</div>
<p class="footer-links">
	© 2010 ******. Design by <a href="http://www.spyka.net">Free CSS Templates</a> and <a href="http://www.justfreetemplates.com">Free Web Templates</a> | Programming by: <a href="services.php">4ren Studio</a>
</p>
</div>
</body>
</html>

 

Stai kaip atrodo pagrindinio puslapio apacia:

http://img709.imageshack.us/img709/7365/originalas.jpg

 

 

O dabar problema, paspaudes Next >> ismeta keista adresa virsuje:

index2.php?page=2>2</a>%20</center><a%20href=

 

Naujienos tokios pacios, as idejas 15 berods, 1 unikalia kad galeciau atskirti ar veikia puslapiavimas, o kitas tokias pat. Tai va, paspaudes next ismeta tas pacias naujienas, IR visas footeris pasikeicia.

http://img684.imageshack.us/img684/5776/14567324.jpg

 

 

 

Buciau labai dekingas, jei kas nors sutvarkytu koda! :laugh_xmas:

Nuoroda į pranešimą
Dalintis kituose puslapiuose

Na pabandziau, ishmete errora:

Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\prop\index2.php on line 119

 

O ta 119 eilute dabar yra:

echo '<center><a href='?page=' . $prev . ''><br><br>« Previous</a></center>';
Nuoroda į pranešimą
Dalintis kituose puslapiuose

Prisijunkite prie diskusijos

Jūs galite rašyti dabar, o registruotis vėliau. Jeigu turite paskyrą, prisijunkite dabar, kad rašytumėte iš savo paskyros.

Svečias
Parašykite atsakymą...

×   Įdėta kaip raiškusis tekstas.   Atkurti formatavimą

  Only 75 emoji are allowed.

×   Nuorodos turinys įdėtas automatiškai.   Rodyti kaip įprastą nuorodą

×   Jūsų anksčiau įrašytas turinys buvo atkurtas.   Išvalyti redaktorių

×   You cannot paste images directly. Upload or insert images from URL.

Įkraunama...
  • Dabar naršo   0 narių

    Nei vienas registruotas narys šiuo metu nežiūri šio puslapio.

  • Prisijunk prie bendruomenės dabar!

    Uždarbis.lt nariai domisi verslo, IT ir asmeninio tobulėjimo temomis, kartu sprendžia problemas, dalinasi žiniomis ir idėjomis, sutinka būsimus verslo partnerius ir dalyvauja gyvuose susitikimuose.

    Užsiregistruok dabar ir galėsi:

    ✔️ Dalyvauti diskusijose;

    ✔️ Kurti naujas temas;

    ✔️ Rašyti atsakymus;

    ✔️ Vertinti kitų žmonių pranešimus;

    ✔️ Susisiekti su bet kuriuo nariu asmeniškai;

    ✔️ Naudotis tamsia dizaino versija;

    ir dar daugiau.

    Registracija trunka ~30 sek. ir yra visiškai nemokama.

  • Naujausios temos

  • Karštos temos

×
×
  • Pasirinkite naujai kuriamo turinio tipą...