Странициране Къде бъркам

talevtehnology

Registered
Нуждая се от странициране(да се страницират обявите от всяка категория), това е кода от урока система уроци на Sand Pince http://web-tourist.net/login/login/view.php?st=1352 , която искам да използвам за система за обяви.
Ето това е кода:
Код:
<?php 
//------------------------------------------ 
//database connection 
mysql_connect("localhost", "talevteh_talev", "******i") or die(mysql_error()); 
mysql_select_db("obqvi") or die(mysql_error()); 
//end database connection 
//------------------------------------------ 

//------------------------------------------ 
//echo out a navigation panel 
echo " 
<center><a href='tutorials.php'>Виж категории</a> | <a href='tutorials.php?action=addtutorial'>Добави обява</a></center> 
"; 
//------------------------------------------ 

//------------------------------------------ 
//begin main navigation (tutorials.php?action=) 

switch($_GET['action']) 
{ 
//------------------------------------------ 
//this case adds a tutorial. 
//pretty self-explanitory 
//------------------------------------------ 
case "addtutorial": 
//if the form to enter a new 
//tutorial hasn't been submitted, 
//show it 
if(!isset($_POST['add_tutorial'])) 
{ 
echo " 
<table border='0' cellpadding='0' cellspacing='0' width='500'> 
<form action='$self?action=addtutorial' method='post'> 
<tr> 
<td>Име:</td> 
<td><input type='text' name='name'></td> 
</tr> 
<tr> 
<td>Заглавие:</td> 
<td><input type='text' name='title'></td> 
</tr> 
<tr> 
<td>Категория:</td> 
<td> 
<select name='category'> 
"; 
//now what we are doing here is looping through 
//the categorys table and getting all the 
//categorys and putting them into a select 
//so the user can select which category 
//the tutorial is on 
$query = mysql_query("SELECT * FROM tutorials_categorys ORDER BY id ASC") or die(mysql_error()); 
while($row = mysql_fetch_array($query)) 
{ 
echo "<option value='$row[id]'>$row[category]"; 
} 
echo " 
</select> 
</td> 
</tr> 
<tr> 
<td>Обяви:</td> 
<td><textarea name='tutorial' cols='40' rows='10'></textarea></td> 
</tr> 
</tr> 
<tr> 
<td>Кратко описание:</td> 
<td><textarea name='short_description' cols='40' rows='2'></textarea></td> 
</tr> 
<tr> 
<td>Email:</td> 
<td><input type='text' name='email' maxlength='50'></td> 
</tr> 
<tr> 
<td>Показване на Email?</td> 
<td><input type='checkbox' name='show_email' value='1' checked></td> 
</tr> 
<tr> 
<td colspan='2'><center><input type='submit' name='add_tutorial' value='Добави нова обява'></center></td> 
</tr> 
</form> 
</table> 
"; 
} 
//else, error check, enter it 
elseif(isset($_POST['add_tutorial'])) 
{ 
$name = mysql_real_escape_string(strip_tags($_POST['name'])); 
$title = mysql_real_escape_string(strip_tags($_POST['title'])); 
$category = mysql_real_escape_string(strip_tags($_POST['category'])); 
$tutorial = mysql_real_escape_string(strip_tags($_POST['tutorial'])); 
$short_description = mysql_real_escape_string(strip_tags($_POST['short_description'])); 
$email = mysql_real_escape_string(strip_tags($_POST['email'])); 
$show_email = mysql_real_escape_string($_POST['show_email']); 
$date = date("m/d/Y"); 
$time = time(); 

//we begin error checking.... 
$error_msg = array(); 
if(empty($name)) 
{ 
$error_msg[] = "Моля поставете име!<br />"; 
} 
if(empty($title)) 
{ 
$error_msg[] = "Моля поставете заглавие!<br />"; 
} 
if(empty($category)) 
{ 
$error_msg[] = "Моля изберете категория<br />"; 
} 
if(empty($tutorial)) 
{ 
$error_msg[] = "Моля поставета текст на вашата обява!<br />"; 
} 
if(empty($short_description)) 
{ 
$error_msg[] = "Моля поставете кратко описание!<br />"; 
} 
if(empty($email)) 
{ 
$error_msg[] = "Моля поставете email!<br />"; 
} 
//print the errors, if any 
if(count($error_msg)>0) 
{ 
echo "<strong>ERROR:</strong><br>n"; 
foreach($error_msg as $err) 
echo "$err"; 
} 
//everythings ok, insert it to the DB 
else 
{ 
$sql = "INSERT INTO tutorials (submitter, text, short_description, title, cat_id, date_submitted, time_submitted, show_email, email, is_validated) VALUES ('$name', '$tutorial', '$short_description', '$title', '$category', '$date', '$time', '$show_email', '$email', '0')"; 
mysql_query($sql) or die(mysql_error()); 
echo "Tutorial added for review!"; 
} 
} 
break; 

//------------------------------------------ 
//this case gets the specified [ID] in the url 
//(tutorials.php?action=viewcategory&id=[ID] 
//and gets all the tutorials listed under that 
//category ID (cat_id) 
//------------------------------------------ 
case "viewcategory": 
//if there is an ID given... 
if($_GET['id']) 
{ 
//get the id, put it into a variable, cast to an INT 
//(for security purposes) 
$id = (int)$_GET['id']; 
$query = mysql_query("SELECT * FROM tutorials WHERE cat_id = '$id' AND is_validated = '1'") or die(mysql_error()); 

//if no results, show that there are no tutorials 
//for that category 
if(mysql_num_rows($query) == 0) 
{ 
echo "No tutorials for this category yet!"; 
} 
//else, there is..show em 
else 
{ 
echo "<h1>Обяви</h1>"; 
//loop through the tutorials 
//show all tutorials 
echo "<table border='0' cellpadding='0' cellspacing='0' width='500'>"; 
while($row = mysql_fetch_array($query)) 
{ 
echo " 
<tr> 
<td>Загалвие:</td> 
<td><b>$row[title]</b></td> 
</tr> 
<tr> 
<td>Дата на побликуване:</td> 
<td><b>$row[date_submitted]</b></td> 
</tr> 
<tr> 
<td>Видяна:</td> 
<td>$row[views]</td> 
</tr> 
<tr> 
<td>Кратко описание:</td> 
<td>$row[short_description]</td> 
</tr> 
<tr> 
<td>Добавил:</td> 
<td>$row[submitter]</td> 
</tr> 
<tr> 
<td colspan='2'><center><b><a href='$self?action=viewtutorial&id=$row[id]'>Виж</a></b></center></td> 
</tr> 
<tr> 
<td colspan='2'><hr /></td> 
</tr> 
"; 
} 
echo "</table>"; 
} 
} 
else 
{ 
echo "Please give me a category ID!"; 
} 
break; 

//------------------------------------------ 
//this case gets the given [ID] 
//action=viewtutorial&id=[ID] 
//and gets that tutorial ID from the database 
//and displays it! 
//------------------------------------------ 
case "viewtutorial": 
//if there is an ID given.. 
if($_GET['id']) 
{ 
//set $id to the URL id, cast to an INT 
//for security purposes 
$id = (int)$_GET['id']; 

//query the database 
$query = mysql_query("SELECT * FROM tutorials WHERE id = '$id' LIMIT 1") or die (mysql_error()); 

//if no rows returned... 
if(mysql_num_rows($query) == 0) 
{ 
echo "That ID is not in the database!"; 
} 
//else, show it! 
else 
{ 
//update the views for this tutorial! 
$update_views = mysql_query("UPDATE tutorials SET views = views + 1 WHERE id = '$id'") or die(mysql_error()); 

//loop through the database 
while($row = mysql_fetch_array($query)) 
{ 
echo " 
<table border='0' cellpadding='0' cellspacing='0' width='500' style='border: 1px solid black; padding: 3px;'> 
<tr> 
<td colspan='2'>Обяви: <b>$row[title]</b></td> 
</tr> 
<tr> 
<td colspan='2' style='border: 1px solid black;'><center><b>Обяви</b></center><br />$row[text]</td> 
</tr> 
<tr> 
"; 
//---------------------------- 
//this part of the code 
//checks to see if the submitter 
//wants an email left for support 
//---------------------------- 
if($row['show_email'] == 1) 
{ 
echo " 
<td colspan='2'>Тази обява е добавена от <b>$row[submitter]</b> За въпроси към подателя <a href='mailto:$row[email]'>Тук</a></td> 
"; 
} 
echo " 
</tr> 
<tr> 
<td><hr /></td> 
</tr> 
"; 
} 
//-------------------------------- 
//this is where we loop through the 
//comments table to show all the 
//comments for this tutorial 
//-------------------------------- 
$comments = mysql_query("SELECT * FROM tutorials_comments WHERE tut_id = '$id' ORDER BY id DESC") or die (mysql_error()); 

//if there are no comments.. 
if(mysql_num_rows($comments) == 0) 
{ 
echo " 
<tr> 
<td colspan='2'>Няма коментари за тази обява!</td> 
</tr> 
"; 
} 
//else, show them! 
else 
{ 
//loop through them 
while($row = mysql_fetch_array($comments)) 
{ 
echo " 
<tr> 
<td colspan='2'>Коментар от: <b>$row[submitter]</b></td> 
</tr> 
<tr> 
<td colspan='2' style='border: 1px solid black; padding: 2px;' vAlign='top'>$row[text]</td> 
</tr> 
"; 
} 
} 
//show the form to enter comments 
echo " 
<tr> 
<td colspan='2'><hr /></td> 
</tr> 
<form action='$self' method='post'> 
<tr> 
<td>Име:</td> 
<td><input type='text' name='name' maxlength='25'></td> 
</tr> 
<tr> 
<td>Коментар:</td> 
<td><textarea name='message' cols='40' rows='10'></textarea></td> 
</tr> 
<tr> 
<td colspan='2'><center><input type='submit' name='add_comment' value='Add Comment'></center></td> 
</tr> 
</form> 
"; 
//----------------------------- 
//if the comment submit form 
//HAS been submitted, enter info 
//to the database. 
//----------------------------- 
if(isset($_POST['add_comment'])) 
{ 
//strip all HTML tags 
//and get rid of any quotes to prevent 
//SQL injection 
$message = mysql_real_escape_string(strip_tags($_POST['message'])); 
$name = mysql_real_escape_string(strip_tags($_POST['name'])); 
$time = time(); 

//use an array to store all error messages 
$error_msg = array(); 
if(empty($message)) 
{ 
$error_msg[] = "Моля добавете съобщение!<br />"; 
} 
if(empty($name)) 
{ 
$error_msg[] = "Моля добавете име!<br />"; 
} 
//print the errors 
if(count($error_msg)>0) 
{ 
echo "<strong>ERROR:</strong><br>n"; 
foreach($error_msg as $err) 
echo "$err"; 
} 
//else, everything is ok, enter it in the DB 
else 
{ 
$query = mysql_query("INSERT INTO tutorials_comments VALUES (NULL,'$id','$name', '$message', '$time')") or die(mysql_error()); 
} 
} 
echo "</table>"; 
} 
} 
//if not.. 
else 
{ 
echo "No ID specified!"; 
} 
break; 

//------------------------------------------ 
//default case, this is shown default 
//in this instance, we are going to make the default case show 
//all the categories that you can view tutorials on 
//------------------------------------------ 
default: 
$query = mysql_query("SELECT * FROM tutorials_categorys") or die(mysql_error()); 

//if the number of rows returned is 0, then say, no categories 
if(mysql_num_rows($query) == 0) 
{ 
echo "No tutorial categories currently!"; 
} 
//if anything else, then there has to be categories. show em. 
else 
{ 
echo "<h1>Категории обяви:</h1> "; 
//while loop to loop through the database and display results! 
while($row = mysql_fetch_array($query)) 
{ 
echo " 
<table border='0' cellpadding = '0' cellspacing='0' width='500'> 
<tr> 
<td>Име на категорията:</td> 
<td>$row[category]</td> 
</tr> 
<tr> 
<td>Описание:</td> 
<td>$row[description]</td> 
</tr> 
<tr> 
<td><a href='$self?action=viewcategory&id=$row[id]'>Посети тази категория</a></td> 
</tr> 
<tr> 
<td><hr /></td> 
</tr> 
</table> 
"; 
} 
} 
break; 
} 
//end navigation 
//------------------------------------------ 
?>

Ето и Демо: http://talevtehnology.com/tutorials.php?action=viewcategory&id=9
Благодаря ви предварително :)

Кажете ми къде бъркам ето на тези снимки се вижда кода който съм добавил,но не страницира, ако искате ще посна тук и кода със който се опитвам да страницирам . :?
code1.png

code2.png
 
Моляви помагайте
Ето и кода с който се опитвам да страницирам:

Код:
echo ('
<div id="rightbar">
<table width="97%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="border1" valign="top">');
//$ns - номер страница
//$br - брой страница
//$one - първа
//$sl - следваща
//$pl - последна
//$pr - предишна
$br = 15;
$pageNum = 1;
if(isset($_GET['page'])) {
$pageNum = $_GET['page'];
}
$redove = ($pageNum - 1) * $br;
$query = " SELECT * FROM users "." LIMIT $redove, $br";
$result = mysql_query($query) or die('Не си избрал страница!');
и другата част:
Код:
echo ("</tr>
</table>
<br /><center>");
$query = "SELECT COUNT(id) AS numrows FROM users";
$result = mysql_query($query) or die('Не си избрал страница!');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$br);
$self = $_SERVER['PHP_SELF'];
$ns = '';
for($page = 1; $page <= $maxPage; $page++) {
if ($page == $pageNum) {
$ns .= " $page ";
}
else {
$ns .= " <a href=\"$self?page=$page\">$page</a> ";
}}
if ($pageNum > 1) {
$page = $pageNum - 1;
$pr = " <a href=\"$self?page=$page\"> [<] </a> ";
$one = " <a href=\"$self?page=1\">[първа]</a> ";
}
else {
$pr = ' ';
$one = ' ';
}
if ($pageNum < $maxPage) {
$page = $pageNum + 1;
$sl = (" <a href=\"$self?page=$page\"> [>] </a> ");
$pl = (" <a href=\"$self?page=$maxPage\">[последна]</a> ");
}
else {
$sl = '';
$pl = '';
}
echo $one . $pr . $ns . $sl . $pl;
 
Код:
махни старото странициране над заглавието Обяви слагаш това

$page = (int)$_GET['page'];
	if($page == 0 || $page == NULL || $page < 0)
	{
	$page = 1;
	}
	$pp = 1;
	$start = ($page*$pp) - $pp;
	
                     //името на таблицата
	$query = mysql_query("SELECT * FROM таблица ");
	$broi = mysql_num_rows($query);
	$total = ceil($broi/$pp);
	//името на таблицата
    $result = mysql_query("SELECT * FROM `таблица` ORDER BY `id` DESC LIMIT $start,$pp");


долу където свършваш с добавянето на обявите слагаш това
стиловете можеш да си ги смениш


echo "<div id = 'STR' style = 'margin-top:-20px; margin-bottom:20px;'>";	

	if ($page > 1) { 
$prev = ($page - 1); 
echo "<a href=\"?page=$prev\"><font face=\"Trebuchet MS\">Предишна </font></a> "; 
} 
else echo "<font face=\"Trebuchet MS\">Предишна </font> "; 

if (!$page or ($page > $total)) { 
$page="1"; 
} 

if ($total < 10) { 
for($i=1 ; $i<=$total ; $i++) { 
if ( ($page)==$i ) { 
echo "<b style='background:#dbdaae; padding-left:8px; padding-right:8px; padding-bottom:1px;border:1px solid #fff;'>$i</b> "; 
} 
else { 
echo "<a style='  background:#f0f6d4; padding-left:8px; padding-right:8px; padding-bottom:0px; border:1px solid #fff;' href=\"?page=".$i."\"><b>".$i."</b></a> "; 
} 
} 
} 
else { 
for($i=1 ; $i<=3 ; $i++) { 
if ( ($page)==$i ) { 
echo "<b style='background:#dbdaae; padding-left:8px; padding-right:8px; padding-bottom:1px;border:1px solid #fff;'>$i</b> "; 
} 
else { 
echo "<a style='  background:#f0f6d4; padding-left:8px; padding-right:8px; padding-bottom:0px; border:1px solid #fff;' href=\"?page=".$i."\">".$i."</a> "; 
} 
} 

if ($page <= 3) { 
if ($page == 3) echo "<a style='  background:#f0f6d4; padding-left:8px; padding-right:8px; padding-bottom:0px; border:1px solid #fff;' href=\"?page=4\">4</a> "; 
echo "... "; 
for ($i=$total-2; $i<=$total; $i++) 
echo "<a style='  background:#f0f6d4; padding-left:8px; padding-right:8px; padding-bottom:0px; border:1px solid #fff;' href=\"?page=".$i."\">".$i."</a> "; 
} 
if ($page == 5) $parva.= "<a style='  background:#f0f6d4; padding-left:8px; padding-right:8px; padding-bottom:0px; border:1px solid #fff;' href=\"?page=4\">4</a> "; 

if ( ($page == 4) or ($page == 5) ) { 
for ($i=$page; $i<=$page+1; $i++) { 
if ($page == $i) echo "<b style='background:#dbdaae; padding-left:8px; padding-right:8px; padding-bottom:1px;border:1px solid #fff;'>$i</b> "; 
else echo "<a style=' background:#f0f6d4; padding-left:8px; padding-right:8px; padding-bottom:0px; border:1px solid #fff;' href=\"?page=".$i."\">".$i."</a> "; 
} 
echo "... "; 
for ($i=$total-2; $i<=$total; $i++) 
echo "<a style=' background:#f0f6d4; padding-left:8px; padding-right:8px; padding-bottom:0px; border:1px solid #fff;' href=\"?page=".$i."\">".$i."</a> "; 
} 

if ( ($page > 5) and ($page < ($total - 4)) ) { 
echo "... "; 
for ($i=$page-1; $i<=$page+1; $i++) { 
if ($page == $i) echo "<b style='background: #dbdaae; padding-left:8px; padding-right:8px; padding-bottom:1px;border:1px solid #fff;'>$i</b> "; 
else echo "<a style=' background:#f0f6d4; padding-left:8px; padding-right:8px; padding-bottom:0px; border:1px solid #fff;' href=\"?page=".$i."\">".$i."</a> "; 
} 
echo "... "; 
for ($i=$total-2; $i<=$total; $i++) 
echo "<a style=' background:#f0f6d4;padding-left:8px; padding-right:8px; padding-bottom:0px; border:1px solid #fff;' href=\"?page=".$i."\">".$i."</a> "; 
} 

if ( $page > ($total - 5) ) { 
echo "... "; 
for ($i=$total-5; $i<=$total; $i++) { 
if ($page == $i) echo "<b style='background: #dbdaae; padding-left:8px; padding-right:8px; padding-bottom:1px;border:1px solid #fff;'>$i</b> "; 
else echo "<a style='  background:#f0f6d4; padding-left:8px; padding-right:8px; padding-bottom:0px; border:1px solid #fff;' href=\"?page=".$i."\">".$i."</a> "; 
} 
} 
} 

if ($page < $total) { 
$next = ($page + 1); 
echo "<a href=\"?page=$next\"><font face=\"Trebuchet MS\">Следваща </font></a> "; 
} 
else echo "<font face=\"Trebuchet MS\">Следваща </font>"; 

	echo"</div>";
 
не знам каква ти е логиката но аз примерно ако вадя резултати по район слагам

$raion = $_GET['raion'];

и в заявките

WHERE raion = '$raion'
 
Значи така по отделно трябва да изброя
$row[title]
$row[date_submitted]
$row[views]
$row[short_description]
$row[submitter]

за да може да ми се показват (това са редовете които ми трябват)
 
не това са ти редовете в цикъла те нямат общо

над $page = (int)$_GET['page'];

слагаш това по което си викаш заявката в твоя случай май id
 
И аз мисля че трябва да е ID ама не мога да го наглася
пробвай и ти ,че на ен или ми вади грешка или страницирането не работи
 
Код:
case "viewcategory": 
//if there is an ID given... 
if($_GET['id']) 
{ 
//get the id, put it into a variable, cast to an INT 
//(for security purposes) 
$id = (int)$_GET['id']; 

$page = (int)$_GET['page'];

	if($page == 0 || $page == NULL || $page < 0)
	{
	$page = 1;
	}
	$pp = 1;
	$start = ($page*$pp) - $pp;
	
	$query = mysql_query("SELECT * FROM tutorials WHERE cat_id = '$id' AND is_validated = '1'") or die(mysql_error()); 
	$broi = mysql_num_rows($query);
	$total = ceil($broi/$pp);

$result = mysql_query("SELECT * FROM `tutorials `   WHERE cat_id = '$id' AND is_validated = '1'  ORDER BY `id` DESC LIMIT $start,$pp");



//if no results, show that there are no tutorials 
//for that category 
if(mysql_num_rows($result) == 0) 
{ 
echo "No tutorials for this category yet!"; 
} 
//else, there is..show em 
else 
{ 
echo "<h1>Обяви</h1>"; 
//loop through the tutorials 
//show all tutorials 
echo "<table border='0' cellpadding='0' cellspacing='0' width='500'>"; 
while($row = mysql_fetch_array($result))
{




//Tuka ti po4va cicula 
// $pp ti e kolko rezultata na stranica da izlizat az sum go napravil na 1 ti mojesh da go napravish na 10 primerno
 
долу в останалия код от страницирането нищо няма да сменяш

и я кажи как изкарваш кода тука във форума заграден изключваш BBCode ли че не знам :)
 
Оффф пален ужас пак не се получава вади някаква грешка
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/talevteh/public_html/tutorials.php on line 175
No tutorials for this category yet!
Предишна 1 2 3 ... 13 14 15 Следваща
 
Аз ли някаде бъркам незнам, но пак не се получава
Не съм сигурн дали слагам id='$id' на правилното място
 

Back
Горе