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

إلى الجفري والخبراء ....

مغلق
بدأه web في 5 مارس 2002 · 3 رد · 443 مشاهدة · في منتدى تصميم صفحات الويب
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

أخواني دخلت إلى موقع أجنبي وهذا رابطه :

ووجدت هذا الأسكربت الجاهز بالـ asp ولكن بعدما نزلت الملفات الخاصة بهذا الأسكربت [ الكود موجود داخل ملف asp + قاعدة البيانات ] كتبت سؤالي هذا لأني عجزت في ربطه في السيرفر المحلي وكذلك في سيرفر شركة

http://www.brinkster.com/

هذا هو الموقع الذي سحبت منه الأسكربت :

http://www.asp101.com/samples/db_search.asp

طبعاً إذا زرتم الموقع ستشاهدون الكود المصدر وكذلك قاعدة البيانات :

الكود هو :

----------------------------------------------------------------- نص الكود ---------

<%
'*******************************************************
'*     ASP 101 Sample Code - http://www.asp101.com     *
'*                                                     *
'*   This code is made available as a service to our   *
'*      visitors and is provided strictly for the      *
'*               purpose of illustration.              *
'*                                                     *
'* Please direct all inquiries to webmaster@asp101.com *
'*******************************************************
%>

<%
' Declare our variables... always good practice!
Dim strURL     ' The URL of this page so the form will work
               ' no matter what this file is named.

Dim cnnSearch  ' ADO connection
Dim rstSearch  ' ADO recordset
Dim strDBPath  ' path to our Access database (*.mdb) file

Dim strSQL     ' The SQL Query we build on the fly
Dim strSearch  ' The text being looked for

' Retreive the URL of this page from Server Variables
strURL = Request.ServerVariables("URL")

' Retreive the term being searched for.  I'm doing it on
' the QS since that allows people to bookmark results.
' You could just as easily have used the form collection.
strSearch = Request.QueryString("search")

' Since I'm doing this all in one page I need to see if anyone
' has searched for something.  If they have we hit the DB.
' O/W I just show the search form and quit.

%>

[background=#FFFF00]بسم الله
الرحمن الرحيم


 


Search our sample db by first or last name. (% returns all)






[Try 'am' or 'er' for an example]


<%
If strSearch <> "" Then
' MapPath of virtual database file path to a physical path.
' If you want you could hard code a physical path here.
strDBPath = Server.MapPath("databasedatabase.mdb")


' Create an ADO Connection to connect to the sample database.
' We're using OLE DB but you could just as easily use ODBC or a DSN.
Set cnnSearch = Server.CreateObject("ADODB.Connection")

' This line is for the Access sample database:
'cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"

' We're actually using SQL Server so we use this line instead:
cnnSearch.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _
& "Initial Catalog=samples;User Id=samples;Password=password;" _
& "Connect Timeout=15;Network Library=dbmssocn;"

' Build our query based on the input.
strSQL = "SELECT last_name, first_name, sales " _
& "FROM sample " _
& "WHERE last_name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR first_name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "ORDER BY last_name;"

' Execute our query using the connection object. It automatically
' creates and returns a recordset which we store in our variable.
Set rstSearch = cnnSearch.Execute(strSQL)

' Display a table of the data in the recordset. We loop through the
' recordset displaying the fields from the table and using MoveNext
' to increment to the next record. We stop when we reach EOF.
' For fun I'm combining some fields and showwing you can do more then
' just spit out the data in the form it is in in the table.
%>

<%
' Close our recordset and connection and dispose of the objects
rstSearch.Close
Set rstSearch = Nothing
cnnSearch.Close
Set cnnSearch = Nothing
End If

' That's all folks! See it's really not all that hard.
%>

 


------------- نهاية الكود ---------------------

وإذا في حالة أضفت بعض الحقول في ملف قاعدة البيانات فأين سأضيف الكود في ملف الـ ASP

أشكركم كل الشكر ,,,, وتكفون ترى موضوعي مهم ..:D

#2

اولا بالنسبة للحقول المستحدمة في هذا المثال هيfirst_name و sale و last_name

strSQL = "SELECT last_name, first_name, sales " _
		& "FROM sample " _
		& "WHERE last_name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
		& "OR first_name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
		& "ORDER BY last_name;"

sample هو اسم الجدول المراد البحث فيه

ولربط قاعدة البيانات بالصفحة فاكتب التالي

strDBPath = Server.MapPath("dbdatabase.mdb")

مجلد db موجود في brinkster ولا يفترض تغييره نهائيا .

بالتوفيق (f)

#3

أخي أحمد الجفري .. والله جربت كثيراً في وضع هذا الكود في الصفحة :

strDBPath = Server.MapPath("dbdatabase.mdb")

ولكن الصفحة لم تعمل ...

أخي ممكن تعدل الكود الأصلي من أجلي إن أمكن ...

:o :o :( :o :o

- سؤال آخر : بالنسبة إذا أدخلت في خانة البحث [ قيمة غير موجودة بقاعدة البيانات ] فإن الذي يظهر هو جدول فارغ .. وأنا أريد أن يظهر للباحث في هذا المحرك مثلاً : [ عفواً المدخلات خاطئة .. نرجو المحاولة مرة أخرى ] ...

فكيف أستطيع عمل ذلك ...

مع وافر شكري وتقديري لشخصكم الكريم ..

#4

اخي الكريم اعتذر فقد نسيت انه يجب اضافة الاسم الذي اخترته لنفسك في الموقع

strDBPath =Server.MapPath("Usernamedbdatabase.mdb")

Username هو اسم المستخدم الذي تستخدمه للدخول على موقعك .

اما بالنسبة فعليك ان تستخدم if فإذا كانت

 if not rstSearch.EOF then

هذا الموضوع مغلق.

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