الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

أنت مبرمج Php أدخل حالا : وأكتشف الخطأ في الكود المكتوب

بدأه المحترف في 12 مارس 2008 · 3 رد · 1,045 مشاهدة · في منتدى تطوير المواقع بـ PHP
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركات

أرفق لكم كود تقسيم المواضيع على عدة صفحات

كما هو واضح من الكود يجب أن يظهر في كل صفحة 20 موضوع

المشكلة إذا زاد عدد المواضيع عن 20 موضوع مثلا 25 موضوع

من المفترض يعرض 20 في الصفحة الأولى و 5 في الصفحة الثانية

هذا الكود لايعرض الخمسة المتبقية في الصفحة الثانية إلا إذا أقترب من فتح صفحة ثالثة

ويفعل مع الثالثة والرابعة نفس ما فعل مع الأولى والثانية

من يكشف يثبت لنا أنه مبدع ويكتشف الخطأ

وأكون له جدا من الشاكرين

اتوقع الخطأ في الأسطر الأخيره من الكود

<?php

	$items = mysql_query("select * from ssubject where cat_id='$catid' and active='1' ");  //list of items	** change to the right table name

	$thispage = $PHP_SELF;
	$num = mysql_num_rows($items); // number of items in list

	$per_page = 20; // Number of items to show per page
	$per_pagecount= 0; //number fo items output from each query
	$showeachside = 7; //  Number of items to show either side of selected page

	if(empty($start))$start=0;  // Current start position

	$max_pages = ceil($num / $per_page); // Number of pages
	$cur = ceil($start / $per_page)+1; // Current page number

	//**********************************************
	if (!$start or $start == 0)	 //allocat the starting page number
	{
	$start=0;
	$from =$start *  $per_page;
	$to= ($start+1) * $per_page;
	}
	 else{
	$from =$start;
	$to= $per_page;}
	//**********************************************
   $today_date = date ("Y-n-j");
$f1=strtotime($today_date);

			$as1_select = mysql_query ("SELECT * from ssubject where cat_id='$catid' and active='1'");
 			while ($Row54=mysql_fetch_array($as1_select))
 			{
			  $ss_id = $Row54 [id];
			  $end_date = $Row54 [end_date];
			$count_read = $Row54 [count];

		$update=mysql_query("UPDATE ssubject SET count='$count_read'+1 where id='$ss_id'");

$f2=strtotime($end_date);

if ($f1 >= $f2){
		  $delete=mysql_query("DELETE from ssubject WHERE id='$ss_id'"); }
}


			$as1_select = mysql_query ("SELECT * from ssubject where cat_id='$catid' and active='1'");
			$count= mysql_num_rows($as1_select);

echo "<span style=\"font-size: 13px\"><center> عدد الإعلانات   ($count)</center></span>";
?>
| <a href="java script: funHideAll()"><span style="font-size: 13px">العناوين</a>
 | <a href="java script: funShowAll()"><span style="font-size: 13px">التفاصيل</span></a> |
<?
br(); br();
$a=0;
//*******************
		if($start == 0)
		{
			$as2_select = mysql_query ("SELECT * from ssubject where cat_id='$catid' and first_page='1' and active='1' ");
 			while ($Row4=mysql_fetch_array($as2_select))
 			{
			$s_id = $Row4 [id];
			  $cat_id = $Row4 [cat_id];
			  $mem_id = $Row4 [mem_id];
			  $sc = $Row4 [scountry];
			  $forum_id = $Row4 [forum_id];
			  $s_name = $Row4 [s_name];

			  $s_photo = $Row4 [s_photo];
			  $s_disc = $Row4 [s_disc];
			  $first_page = $Row4 [first_page];
			$count = $Row4 [count];

			$as52_select = mysql_query ("SELECT * from members where id='$mem_id'");
 			while ($Row128=mysql_fetch_array($as52_select))
 			{
			  $mem_name = $Row128 [name];
			$special = $Row128 [special];
			}
$ass11_select = mysql_query ("SELECT * from subject_replays where subject_id='$s_id' and active='1' order by id desc");
$countfs= mysql_num_rows($ass11_select);

while ($Row41=mysql_fetch_array($ass11_select))
 			{
			$re_id = $Row41 [id];
			$meme_id = $Row41 [mem_id];
			  $re_replay = $Row41 [replay];
			  $re_date = $Row41 [date];

			$as512_select = mysql_query ("SELECT * from members where id='$meme_id'");
 			while ($Row12=mysql_fetch_array($as512_select))
 			{
			  $re_name = $Row12 [name];
			}
			}
			$a=$a+1;
			?>
			<!--Optional Expand/ Contact All links. Remove if desired-->
			<table width=100% cellpadding=2 cellspacing=0 border=0 bordercolor=#F55EA3><tr><td ><? echo $a; ?> :.<img src=country_images/<? echo $sc; ?>.gif>

			 <?
			 if ($s_photo != ""){
				echo "<img src=uploads/imageon.gif>";}

			else {
			 echo "<img src=uploads/imageoff.gif>";
			}
			?>
			(الردود  : <? echo $countfs; ?>)
			<a href="java script: funHS('<? echo $a; ?>')" class="b1" onclick="java script:ajaxpage('pic.php?pic=<? echo $s_photo; ?>','DIV<? echo $s_id; ?>');"><b><font color="#0000FF"><span style="font-size: 11pt; font-weight: 700"> <? echo $s_name; ?></span></font></b></a></td></tr>
			<tr><td><div id="item<? echo $a; ?>" style="display: none;">
			<?
			br();
			include ("template/style1/subject_disc.htm");
			echo "</td></tr></table></center>";
			include ("template/style1/complete_sub.htm");

			 ?>
			</div></td></tr></table><br>
			<?
			$per_pagecount= $per_pagecount+1;
			}




//**********************


			$as_select = mysql_query ("SELECT * from ssubject where cat_id='$catid' and height_adv='1' and active='1' ");
 			while ($Row1=mysql_fetch_array($as_select))
 			{
			$as_id = $Row1 [id];
			  $acat_id = $Row1 [cat_id];
			  $amem_id = $Row1 [mem_id];
			  $asc = $Row1 [scountry];
			  $aforum_id = $Row1 [forum_id];
			  $as_name = $Row1 [s_name];
			  $as_photo = $Row1 [s_photo];
			  $as_disc = $Row1 [s_disc];
			  $height_adv = $Row1 [height_adv];
			$acount = $Row1 [count];

			$as7_select = mysql_query ("SELECT * from members where id='$amem_id' and active='1'");
 			while ($Row7=mysql_fetch_array($as7_select))
 			{			  $meme_name = $Row7 [name];
			$special = $Row7 [special];
			}

			$as_select = mysql_query ("SELECT * from subject_replays where subject_id='$as_id' and active='1' order by id desc");
			$countsfs= mysql_num_rows($as_select);
 			while ($Row4=mysql_fetch_array($as_select))
 			{
			$rre_id = $Row4 [id];
			$rmeme_id = $Row4 [mem_id];
			  $rre_replay = $Row4 [replay];
			  $rre_date = $Row4 [date];

			$as52_select = mysql_query ("SELECT * from members where id='$rmeme_id'");
 			while ($Row2=mysql_fetch_array($as52_select))
 			{
			  $rre_name = $Row2 [name];
			}
			}
			$a=$a+1;
			?>
			<!--Optional Expand/ Contact All links. Remove if desired-->
			<table width=100% cellpadding=2 cellspacing=0 border=0 bordercolor=#F55EA3><tr><td align=right><? echo $a; ?> :.<img src=country_images/<? echo $sc; ?>.gif>
			 <?
			 if ($s_photo != ""){
				echo "<img src=uploads/imageon.gif>";}
			else {
			 echo "<img src=uploads/imageoff.gif>";
			}
			?>
			(الردود  : <? echo $countfs; ?>)
			<a href="java script: funHS('<? echo $a; ?>')" class="b1" onclick="java script:ajaxpage('pic.php?pic=<? echo $as_photo; ?>','DIV<? echo $as_id; ?>');"><span style="font-size: 13px"><? echo $as_name; ?></span></a></td></tr>

			<tr><td><div id="item<? echo $a; ?>" style="display: none;">

			<?
			br();
			include ("template/style1/subject_disc_s2.htm");
			include ("template/style1/complete_sub1.htm");
			 ?>
			</div></td></tr></table>
			<?

			}

		  $to=$per_page-(mysql_num_rows($as_select)+ mysql_num_rows($as2_select));
		  $quer= 1;
	 }


//********************
$as2_select = mysql_query ("SELECT * from ssubject where cat_id='$catid' and first_page='1' and height_adv='0' and active='1' ");
$as_select = mysql_query ("SELECT * from ssubject where cat_id='$catid' and height_adv='1' and active='1' ");
   if((mysql_num_rows($as_select)+ mysql_num_rows($as2_select)) == $per_page)
	{		if(!$quer)
		{
		$from=$from-$per_page;
		}
	}
			$ass2_select = mysql_query ("SELECT * from ssubject where cat_id='$catid' and first_page='0' and height_adv='0' and active='1' order by id desc limit $from , $to");
 			while ($Row=mysql_fetch_array($ass2_select))
 			{
			$ss_id = $Row [id];
			  $scat_id = $Row [cat_id];
			  $smem_id = $Row [mem_id];
			  $ssc = $Row [scountry];
			  $sforum_id = $Row [forum_id];
			  $ss_name = $Row [s_name];
			  $ss_photo = $Row [s_photo];
			  $ss_disc = $Row [s_disc];
			  $sfirst_page = $Row [first_page];
			$scount = $Row [count];

			$as77_select = mysql_query ("SELECT * from members where id='$smem_id' and active='1'");
 			while ($Row77=mysql_fetch_array($as77_select))
 			{
			  $smem_name = $Row77 [name];
			$special = $Row77 [special];
			}

			$ass111_select = mysql_query ("SELECT * from subject_replays where subject_id='$ss_id' and active='1'");
			$countfss= mysql_num_rows($ass111_select);
$i=1; 			
while ($Row441=mysql_fetch_array($ass111_select))
 			{
			$sre_id = "$i";
			$smeme_id = $Row441 [mem_id];	
$sre_replay = $Row441 [replay];
			  $sre_date = $Row441 [date];
$i++;
			$as52_select = mysql_query ("SELECT * from members where id='$smeme_id'");
 			while ($Row122=mysql_fetch_array($as52_select))
 			{
			  $sre_name = $Row122 [name];
			}
			}
			$a=$a+1;
			?>

			<table width=100% cellpadding=2 cellspacing=0 border=0 bordercolor=#F55EA3><tr><td ><? echo $a; ?> :.<img src=country_images/<? echo $ssc; ?>.gif>

			 <?
			 if ($ss_photo != ""){
				echo "<img src=uploads/imageon.gif>";}

			else {
			 echo "<img src=uploads/imageoff.gif>";
			}

			?>
			(الردود  : <? echo $countfss; ?>) 
			<a href="java script: funHS('<? echo $a; ?>')" class="b1" onclick="java script:ajaxpage('pic.php?pic=<? echo $ss_photo; ?>','DIV<? echo $ss_id; ?>');"><span style="font-size: 13px"><? echo $ss_name; ?></span></a></td></tr>
			<tr><td><div id="item<? echo $a; ?>" style="display: none;">
			<?
			br();
			include ("template/style1/subject_disc_s1.htm");
			include ("template/style1/complete_sub2.htm");
			 ?>
			</div></td></tr></table><br>
			<?

			}
	//**********************
	br();
	//***************************************************************


?>
<style type="text/css">
<!--
.pageselected {
	color: #FF0000;
	font-weight: bold;
}
-->
</style>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0" class="PHPBODY">
<tr>
<td width="99" align="center" valign="middle">
<?php
if(($start-$per_page) >= 0)
{
	$next = $start-$per_page;
?>

<?php
}
?>
</td>
<td width="201" align="center" valign="middle" class="selected">


</td>
<td width="100" align="center" valign="middle">
<?php
if($start+$per_page<$num)
{
?>
<?php
}
?>
</td>
</tr>
<tr><td colspan="3" align="center" valign="middle"> </td></tr>
<tr>
<td colspan="3" align="center" valign="middle" class="selected">
<font face="Traditional Arabic" style="font-size: 15pt"><b>بقية الصفحات </b></font>
<?php
$eitherside = ($showeachside * $per_page);
if($start+1 > $eitherside)print (" .... ");
$pg=1;
for($y=0;$y<$num;$y+=$per_page)
{
	$class=($y==$start)?"pageselected":"";
	if(($y > ($start - $eitherside)) && ($y < ($start + $eitherside)))
	{

	?>

		<input type=button style="font-size: 10pt" value="<?php print($pg);?>" onclick= "window.location= '<?php print("$thispage?action=cat_disc&catid=$catid".($y>0?("&start=").$y:""));?>';" >

	<?php
	$start2=""; $start3="";
	}
	$pg++;
}
?>
<!-- input type=button style="font-size: 10pt" value="<?php print($max_pages-1);?>" onclick= "window.location= '<?php print("$thispage?action=cat_disc&catid=$catid".($y>0?("&start=").$y:""));?>';" -->
<?
if(($start+$eitherside)<$num)print (" .... ");
?>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<?php
//	for($x=$start;$x<min($num,($start+$per_page)+1);$x++)
// print($items[$x]."<br>");
?>
</td>
</tr>
</table>

تقبلوا خالص شكري وتحياتي

لي رجاء خاص لكل من يدخل الموضوع لاتخرج دون أن تكتب ولو حرف واحد دعاء لي بإيجاد الحل

و دعاء لمن يسارع لنا بالحل

#2

كتبت رد طويل لكن الحمد لله الجهاز علق.

ما علينا:

للأسف ليس عندي وقت لقرائة كل هذا الكود.

$id= $_GET['page'];
$more = $id+20;

بعدين تعمل الquery ده:

SELECT * FROM table limit $id,$more

و كل ما يزيد الآي دي تتغير النتائج.

أنصحك بمشاهدة هذا الكورس (من هنا) إن كنت تريد فعلا إحتراف البرمجة.

تم تعديل هذه المشاركة بواسطة croconile في 13 مارس 2008 في 06:42

rasool4k.gif

[وسط]mimetex.cgi?MSN:root@root-shell.net.

[/وسط]

#3

أشكرك أخي croconile

فعلا من ينظر للكود للمره الأولى يراه كبيرا ولكن كل المطلوب النظر للقسم الأول والأخير منه

اتوقع التعديل سيكون في احد القسمين فقط أما الجزء الداخلي فهو بحث في قاعدة البيانات سليم مافيه أخطاء

الجزء العلوي :

<?php

	$items = mysql_query("select * from ssubject where cat_id='$catid' and active='1' ");  //list of items	** change to the right table name

	$thispage = $PHP_SELF;
	$num = mysql_num_rows($items); // number of items in list

	$per_page = 20; // Number of items to show per page
	$per_pagecount= 0; //number fo items output from each query
	$showeachside = 7; //  Number of items to show either side of selected page

	if(empty($start))$start=0;  // Current start position

	$max_pages = ceil($num / $per_page); // Number of pages
	$cur = ceil($start / $per_page)+1; // Current page number

	//**********************************************
	if (!$start or $start == 0)	 //allocat the starting page number
	{
	$start=0;
	$from =$start *  $per_page;
	$to= ($start+1) * $per_page;
	}
	 else{
	$from =$start;
	$to= $per_page;}
	//**********************************************
   $today_date = date ("Y-n-j");
$f1=strtotime($today_date);

			$as1_select = mysql_query ("SELECT * from ssubject where cat_id='$catid' and active='1'");
			while ($Row54=mysql_fetch_array($as1_select))
			{
			  $ss_id = $Row54 [id];
			  $end_date = $Row54 [end_date];
			$count_read = $Row54 [count];

		$update=mysql_query("UPDATE ssubject SET count='$count_read'+1 where id='$ss_id'");

$f2=strtotime($end_date);

if ($f1 >= $f2){
		  $delete=mysql_query("DELETE from ssubject WHERE id='$ss_id'"); }
}


			$as1_select = mysql_query ("SELECT * from ssubject where cat_id='$catid' and active='1'");
			$count= mysql_num_rows($as1_select);

echo "<span style=\"font-size: 13px\"><center> عدد الإعلانات   ($count)</center></span>";
?>
| <a href="java script: funHideAll()"><span style="font-size: 13px">العناوين</a>
| <a href="java script: funShowAll()"><span style="font-size: 13px">التفاصيل</span></a> |
<?
br(); br();
$a=0;
//*******************

والجزء السفلي

?>
<style type="text/css">
<!--
.pageselected {
	color: #FF0000;
	font-weight: bold;
}
-->
</style>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0" class="PHPBODY">
<tr>
<td width="99" align="center" valign="middle">
<?php
if(($start-$per_page) >= 0)
{
	$next = $start-$per_page;
?>

<?php
}
?>
</td>
<td width="201" align="center" valign="middle" class="selected">


</td>
<td width="100" align="center" valign="middle">
<?php
if($start+$per_page<$num)
{
?>
<?php
}
?>
</td>
</tr>
<tr><td colspan="3" align="center" valign="middle"> </td></tr>
<tr>
<td colspan="3" align="center" valign="middle" class="selected">
<font face="Traditional Arabic" style="font-size: 15pt"><b>بقية الصفحات </b></font>
<?php
$eitherside = ($showeachside * $per_page);
if($start+1 > $eitherside)print (" .... ");
$pg=1;
for($y=0;$y<$num;$y+=$per_page)
{
	$class=($y==$start)?"pageselected":"";
	if(($y > ($start - $eitherside)) && ($y < ($start + $eitherside)))
	{

	?>

		<input type=button style="font-size: 10pt" value="<?php print($pg);?>" onclick= "window.location= '<?php print("$thispage?action=cat_disc&catid=$catid".($y>0?("&start=").$y:""));?>';" >

	<?php
	$start2=""; $start3="";
	}
	$pg++;
}
?>
<!-- input type=button style="font-size: 10pt" value="<?php print($max_pages-1);?>" onclick= "window.location= '<?php print("$thispage?action=cat_disc&catid=$catid".($y>0?("&start=").$y:""));?>';" -->
<?
if(($start+$eitherside)<$num)print (" .... ");
?>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<?php
//	for($x=$start;$x<min($num,($start+$per_page)+1);$x++)
// print($items[$x]."<br>");
?>
</td>
</tr>
</table>

أكوادك صحيحة ولكن لم احسن استخدامها ضمن ملفي

اتمنى التعديل على نفس الكود الذي أرفقته أنا مستخدما نفس المتغيرات إن أمكن

اشكرك لك ولك من يشاركنا الحل وادعوا لكم بالتوفيق

انتظر حلولكم على احر من الجمر

#4

الله يوفقك وتنحل مشكلتك ،،

تقبل اخلص امنياتي ،،

مبرمج PHP

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…