Abdoulr
29-03-2003, 08:34 PM
السلام عليكم ممكن شباب شرح كيفيت عمل تصويت في موقعي
والسلام عليكم
شهاب4
29-03-2003, 09:41 PM
موقعك مدفوع..او مجاني
واي نوع من التصويت تريد؟؟؟؟؟
عموما هذا هو هاك التصويت
http://www.swalif.net/softs/attachment.php?postid=268824
بالتوفيق
Abdoulr
30-03-2003, 05:32 AM
مشكور اخي شهاب
انا اقصد ان اضع تصويت او استفتاء مثلا في موقع المشاغب وليس المنتدى هناك تصويت او استفاء عن المعلومات المتوافر على الانتنت
وشكرا
شهاب4
30-03-2003, 09:56 AM
خلك معاي اخوي
..
قبل العمل سنقوم بعمل صفحة connection.inc بها معلومات الإتصال و مسار قاعدة البيانات كالتالي
<%@codepage=1256%>
<%
Set cn = CreateObject("ADODB.Connection")
cn.Open("driver={Microsoft Access Driver (*.mdb)};dbq=" & _
Server.MapPath("/vote/vote.mdb"))
%>
----------
تكوين قاعدة بيانات باسم vote بها جدول لمواضيع التصويت voter به حقلين و هما voteId و title و الأخير يحمل موضوع التصويت . كما نحتاج لعمل جدول اخر به معلومات التصويت اسمه voteInfo به 4 حقول و هي id و هي رقم كل درجة تصويت و حقل voteDegree و هي وصف درجة التصويت كما نحتاج لحقل amounts و الذي يخزن عدد مرات التصويت و أخيرا و المهم حقل voteId و هو الحقل الذي يربط الجدولين ببعض ..
ثم نقوم بعمل الصفحة الأولى و التي تعرض مواضيع التصويت في جدول و لنسمها vote.asp و كودها هو التالي :
<html dir="rtl">
<!--#include file="connection.inc"-->
<%
// هذه الصفحة تحوي فقط على استعلام لمواضيع التصويت و يعرضها في جدول
set rs=cn.execute("select * from voter")
if rs.eof then
response.write "<canter><b>لا توجد قوائم استفتاء في الموقع</b></center>"
else
%>
<head>
****** http-*****="Content-Language" content="ar-sa">
****** name="GENERATOR" content="Microsoft FrontPage 5.0">
****** name="ProgId" content="FrontPage.Editor.Document">
****** http-*****="Content-Type" content="text/html; charset=windows-1256">
<title>New Page 1</title>
<style>
<!--
A:link {text-decoration: none; color:#FF9900;}
A:visited {text-decoration: none; color:#FF9900;}
A:active {text-decoration: none; color:#FF9900; }
A:hover {text-decoration: underline;color:#FF0000;}
//-->
</style>
</head>
<body>
<div align="center">
<center>
<table border="2" bordercolor="#123456" width="38%" height="52">
<tr>
<td width="100%" bgcolor="#FF9900" height="32">
<p align="center"><b><font face="Arial" color="#FFFFFF" size="3">قوائم
الإستفتاء</font></b></td>
</tr>
<%
while not rs.eof
%>
<tr>
<td width="100%" height="19">
<a href="addVote.asp?voteId=<%=rs("voteId")%>">
<p align="center"> <%=rs("title")%></td>
</tr>
<%
rs.moveNext
WEND
%>
</table>
</center>
</div>
</body>
<%end if%>
</html>
--------------------------
أرى أن الصفحة الأولى قمة في البساطة و الوضوح .. أما الصفحة الثانية و التي تقوم بعرض كل موضوع تصويت و درجاته مثل أن يكون الموضوع ما رأيك بالموقع و درجاته تكون ممتاز و جيد جدا و سيء و هكذا .. طبعا سنسميها الصفحة addVote.asp لأننا منها سنضيف الصوت .. كودها كالتالي :
<html dir="rtl">
<!-- #include File="connection.inc"-->
<%
// نأخذ رقم التصويت من الصفحة السابقة
voterId=request.QueryString("voteId")
// إذا لم يكن مساويا لقيمة فارغة أكمل التالي
if voterId<>"" then
set rs=createObject("ADODB.recordset")
sql="select * from voter where voteId="&voterId
rs.open sql,cn,3,3
set objrs=createObject("ADODB.recordset")
msql="select * from voteInfo where voteId="&voterId
objrs.open msql,cn,3,3
%>
<head>
****** name="GENERATOR" content="Microsoft FrontPage 5.0">
****** name="ProgId" content="FrontPage.Editor.Document">
****** http-*****="Content-Type" content="text/html; charset=windows-1256">
<title>New Page 1</title>
</head>
<body>
<form method="GET" action="sendVote.asp" name="addVote">
<table border="2" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#123456" width="38%" height="52">
<tr>
<td width="100%" bgcolor="#FF9900" height="32">
<b><font color="#FFFFFF"> <font face="Webdings">i </font><%=rs("title")%></font></b></td>
</tr>
<%
while not objrs.eof
%>
<tr>
<td width="100%" height="19">
<p align="right">
<input type="radio" value="<%=objrs("id")%>" name="value">
<%=objrs("voteDegree")%></td>
</tr>
<%
objrs.moveNext
WEND
%>
</table>
<p> <input type="submit" value="صوت" name="send"></p>
</form>
</body>
<%
// في حالة أن رقم التصويت فارغ بسبب الدخول المباشر للصفحة أو خلل ما
// سوف تعرض رسالة تنبيه ثم ينتقل المتصفح تلقائيا لصفحة التصويت الرئيسية
else
response.write _
"<center><b><font face=arial color=red>لم تقم بالتصويت .. انتظر لنعود بك للصفحة السابقة"
%>
****** http-*****="*******" content="3;url=vote.asp">
<%
end if
%>
</html>
------------------
كما نرى من الكود أن الصفحة تعرض الموضوع و درجاته و عند الضغط على الزر تقوم بنقل الاختيار إلى صفحة احتساب النقاط و ذلك باستخدام طريقة GET و التي تقوم بنقل معلومات التصويت .. و التي نراها في شريط العنوان بعد اسم صفحة احتساب النقاط .. لمزيد من التفاصيل الرجاء مراجعة اخر درس في ال ASP ..
أما صفحة sendVote.asp فهي تقوم بأخذ درجة التصويت نتيجة الطريقة GET في النموذج السابق .. و بالتالي تقوم بفتح قاعدة البيانات و عمل التعديل على درجة التصويت و ذلك بإضافة صوت للأصوات الموجودة .. و الكود كالتالي :
<!-- #include file="connection.inc")-->
<%
// تتأكد من أنه تمت عملية التصويت
id=request.QueryString("value")
if id <>"" then
set rs=createObject("ADODB.recordset")
sql="select * from voteInfo where Id="&Id
// يتم إضافة صوت للدرجة التي تم اختيارها
rs.open sql,cn,3,3
rs("amounts")=rs("amounts")+1
rs.update
// يتم عرض رسالة تنبيه بانتهاء عملية التصويت ثم الانتقال للخلف
response.write "<center><font color=red><b>لقد تمت إضافة صوتك .. انتظر لننقلك لصفحة مشاهدة التصويت"
pageId="voteResult.asp?voteId="& rs("voteId")
response.write "****** http-*****='*******' content='3;URL="&pageId&"'>"
end if
rs.close
set rs=nothing
cn.close
set cn=nothing
%>
--------------------------
كما تلاحظ في الصفحة السابقة أنني لم أستخدم أي كود HTML .. و هذه فكرة تطرقت إليها لأن الكثير يظنون للأسف أن صفحة الخادم النشطة يحوي خليطا من الأكواد .. أقصد احتوائها HTML لكن أنا أقول ليس شرطا ذلك أبدا فأنت باستخدام كائن response كتابة جميع أوسمة ال HTML ..
و صلنا الان آخر صفحة في هذا الموضوع و هي صفحة voteResult.asp و هي الأساس الذي جعلني أضع هذا الموضوع لأنها تحوي فكرة جميلة في استخدام الدوال بمرونة أكثر .. دعنا نرى الكود :
<html dir="rtl">
<!-- #include file="connection.inc"-->
<head>
****** http-*****="Content-Language" content="en-us">
****** name="GENERATOR" content="Microsoft FrontPage 5.0">
****** name="ProgId" content="FrontPage.Editor.Document">
****** http-*****="Content-Type" content="text/html; charset=windows-1256">
<title>نتائج التصويت</title>
<style>
<!--
A:link {text-decoration: none; color:#FF9900;}
A:visited {text-decoration: none; color:#FF9900;}
A:active {text-decoration: none; color:#FF9900; }
A:hover {text-decoration: underline;color:#FF0000;}
//-->
</style>
</head>
<%
data=request("voteId")
////////////////////////////////////////////////////////////////////////////////
////// دالة لرسم نتيجة التصويت تأخذ مجوع الأصوات الكلية
////// و عدد الأصوات لكل درجة تصويت ثم يحسب عدد الأعمدة عن طريق
//////المعادلة الرياضية و التي تحسب النسبة إلى عشرة و ترسم
//////عددا من الخلايا الملونة حسب نسبة التصويت ..
function draw(total,n)
if n<>0 then
columns=CInt((n/total)*10)
response.write "<table><tr>"
for i=1 to columns
response.write "<td bgcolor=FF9900> </td>"
next
response.write "</tr></table>"
end if
end function
//////////////////////////////////////////////////////////////////////////////
// استعلام للحصول على صفحات التصويت
set rs=CreateObject("ADODB.recordset")
sql="select * from voter where voteId="&data
rs.open sql,cn,3,3
// استعلام للحصول على معلومات كل تصويت حسب رقم التصويت التلقائي
set objrs=cn.execute("select * from voteInfo where voteId="& request("voteId"))
// استعلام لحساب عدد الأصوات الكلية لكل تصويت كلا على حدة
set xrs=cn.execute("select sum(amounts)as total from voteInfo where voteId="& request("voteId"))
total=xrs("total")
///////////////////////////////////////////////////////////////////////////////
%>
<base target="_self">
<body>
<p align="center"><b><font face="Arial" color="#123456"><span lang="ar-sa">
<a href="vote.asp">صفحة التصويت الرئيسية</a></span></font></b></p>
<div align="center">
<center>
<table border="2" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#FFFFFF" width="26%" height="67">
<tr>
<td width="100%" bgcolor="#FF9900" height="34" colspan="2"><b>
<font color="#FFFFFF" face="Arial"> <%=rs("title")%></font></b></td>
</tr>
<% while not objrs.eof %>
<tr>
<td width="51%" align=center bgcolor="#CCCCCC" height="32">
<font face=arial color=123456><b>
<%=objrs("voteDegree")%></td>
<td width="49%" bgcolor="#CCCCCC" height="32"><% draw total,objrs("amounts")%></td>
</tr>
<%
objrs.movenext
wend
%>
</table>
</center>
</div>
<p align="center"><b><font face="Arial" size="2" color="#123456">
<span lang="ar-sa">عدد المصوتين لهذا الموضوع :</span> </font><font color=FF0000>
<%response.write total%>
</b></p>
</body>
</html>
******************************
هذا كل شي
بشرني بالنتائج
بالتوفيق اخوي
Abdoulr
30-03-2003, 10:20 AM
مشكور اخوي على هل مساعدة
وانشاء اله سوف ابدل جهدي اني اقوم بعمل كل ما قمة بشرحة مع انه الباين صعب
مشكور
;)