-
يامبرمج يارائد ياأهل سوالف:كيف أضيف شرط في جملة الـ While
في جملة الـ While كيف إضافة شرط آخر على هذه الجملة
كود:
while ($thread = mysql_fetch_array( $result )) {
والشرط الجديد الذي أريد أن أضيفه هو:
كود:
$thread = mysql_fetch_array( $result )
جربت هذا ولم يعمل
كود:
while ($thread = mysql_fetch_array( $result ) AND $post = mysql_fetch_array( $result ) ) {
لأني أريد استخدامها في:
http://swalif.net/softs/showthread.php?threadid=9311
وتحياتي للجميع
-
جرب هذه وستنجح بإذن الله
كود:
while (($thread == mysql_fetch_array($result)) AND ($post == mysql_fetch_array($result))) {
-
هلا عزيزي
إنت كتبت الجملة الشرطية بشكل صحيح .. بإستخدام AND
لكن المشكلة في جزء آخر .. ألا تلاحظ معي أنك تقوم بتمرير نفس القيمة الى المتغيرين ..
$post
$thread
$thread = mysql_fetch_array( $result ) AND $post = mysql_fetch_array( $result )
حيث أن عدد الدورات سيكون هو نفسه في حالة أضفت الشرط الآخر أم لم تضفه .. لتساوي قيمة المتغيرين .
أتمنى لو تراجع الكود مرة أخرى .. أو تبين الفكرة فلربما إستطعت مساعدتك ..
بالنسبة لرسالة سابقة أعتذر على التأخر في الرد .. لكني لاأدري إن كان أحد الأخوة قد أجاب أم لأ ..
لكن إذا أردت جديا تغيير إسم الصفحة وإسم المتغير ..
فكل ماعليك هو ( بعد تغيير المتغير في التيمبليتز كما ذكرت )
أن تقوم بحفظ نسخة أخرى من نفس الملف showthread بإسم آخر
وتعمل على النسخة الأولى ... قم بتغيير كل كلمة threadid الى أي إسم تريدة
ثم قم بمراجعة الصفحات
newreply
newpost
على حسب ذاكرتي إن لم تخني ... وكذا common
وقم بتغيير المتغير الى نفس القيمة ... لكن تأكد من أن القيمة الجديدة ليست مستخدمة من قبل كاتب السكريبت .. وإلا ستخلق الكثير من المشاكل ..
هذا في نبذة مصغرة .. والله ولي التوفيق .
-
ليش البرنامج مابشتغل
قمت بتعديل الـ while وأضفت الـ post و pagetext في جملة الـ select
كود:
<?
// The number of posts you want to see
$count = 5;
// url to the forum
$forum_url = 'http://localhost/vb/';
require("admin/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassword);
mysql_select_db($dbname);
$db_conn = mysql_connect( $dbserver, $dbuser, $dbpass );
$result = mysql_db_query($dbname, "SELECT post.pagetext AS pagetext,thread.threadid AS id,thread.title AS title,thread.replycount AS replycount,thread.forumid AS forumid,forum.title AS forumtitle FROM post,thread,forum WHERE forum.forumid = thread.forumid ORDER BY thread.lastpost DESC LIMIT $count" , $db_conn);
while (($thread == mysql_fetch_array($result)) AND ($post == mysql_fetch_array($result))) {
$text = $thread["title"] . " : " . $thread["threadindex"] . $post["pagetext"];
$text = strip_tags(substr( $text, 0, 51 ));
echo $text . " <a href='".$forum_url."showthread.php?threadid=".$thread["id"]."'>التفاصيل</a><br>";
}
mysql_close( $db_conn );
?>
وجزاكم الله خيراً
-
-
كود:
$thread = mysql_fetch_array($result)
لا تعادل
كود:
$thread == mysql_fetch_array($result)
فالاخير لن يقوم بوضع النتيجة في المتغير thread لكن سيقارن الناتج من الدالة مع المتغير thread
عموماً بما ان post و thread هي ناتجة من نفس الدالة فلا داع للمتغير post
فمثلاً اذا كنت تريد
$post["pagetext"]
بامكانك قرأتها باستخدام
$thread["pagetext"]
دون اضافة جملة لقرأة post
-
أخي لو نظرت إلى المخطط(schema)
كود:
Table forum
============
forumid title description active displayorder replycount lastpost lastposter threadcount categoryid allowposting daysprune forumtemplate headertemplate useadvheader footertemplate useadvfooter forumbittemplate threadtemplate threadbittemplate replytemplate newthreadtemplate edittemplate rulestemplate titleimage replyimage newthreadimage closedthreadimage newpostemail newthreademail moderatenew allowbbcode allowimages allowhtml allowsmilies
Table post
==========
postid threadid username userid title dateline pagetext allowsmilie email signature ipaddress iconid visible
Table tread
============
threadid title lastpost forumid open replycount postusername lastposter dateline views iconid notes visible subjectindex threadindex userindex
وما أريد استخدامه هو
forumid وهو موجدود في Table forum و Table tread
أما pagetext فهو موجود في Table post
============
ولو نظرت في البرنامج:
كود:
<?
// The number of posts you want to see
$count = 5;
// url to the forum
$forum_url = 'http://localhost/vb/';
require("admin/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassword);
mysql_select_db($dbname);
$db_conn = mysql_connect( $dbserver, $dbuser, $dbpass );
$result = mysql_db_query($dbname, "SELECT post.pagetext as pagetext,thread.threadid AS id,thread.title AS title,thread.replycount AS replycount,thread.forumid AS forumid,forum.title AS forumtitle FROM post,thread,forum WHERE forum.forumid = thread.forumid ORDER BY thread.lastpost DESC LIMIT $count" , $db_conn);
while ($thread = mysql_fetch_array( $result ) ) {
$text = $thread["title"] . " : " . $thread["threadindex"] ." : " . $post["pagetext"];
$text = strip_tags(substr( $text, 0, 160 ));
echo $text . " <a href='".$forum_url."showthread.php?threadid=".$thread["id"]."'>مزيد من التفاصيل</a><br>";
}
mysql_close( $db_conn );
?>
طيب ياليت تعدل لي البرنامج أعلاه وذلك بإضافة pagetext
ويشتغل
وشكراً
وأرجوك مراسلتي على إيميلي:
zalamah@yahoo.com
-
اذا كنت تستخدم yahoo messenger يكون افضل، بريدي هو:rayed@yahoo.com
-
أخوي رائد أضفت في الياهو مسنجر
متى تكون موجود
-
حاولت لمن قلت بس
ارجو من الإخوة الكرام المشاركة والمساعدة.
-
اعذرني اخي عندي ظروف هذه الايام تمنعني من التركيز في اي شي (صدق واللة) ، عموماَ لا اعلم مدى صحة جملة SQL لكن جرب تغير جملة while السابقة بما يلي:
كود:
while ($thread == mysql_fetch_array($result) {
$text = $thread["title"] . " : " . $thread["threadindex"] . $thread["pagetext"];
$text = strip_tags(substr( $text, 0, 51 ));
echo $text . " <a href='".$forum_url."showthread.php?threadid=".$thread["id"]."'>التفاصيل</a><br>";
}
ورجاءً اعذرني على عدم القدرة على الرد بشكل افضل في هذا الوقت وآسف مرة اخرى.