הרשם שאלות ותשובות רשימת חברים לוח שנה הודעות מהיום

חזור   הוסטס - פורום אחסון האתרים הגדול בישראל > עיצוב גראפי, תכנות על כל שפותיו וקידום ושיווק אתרים > פורום תיכנות

   
|!|

השב
 
כלים לאשכול תצורת הצגה
ישן 13-08-06, 12:10   # 1
Elad-A
הוסטסניון
 
מיני פרופיל
תאריך הצטרפות: May 2006
הודעות: 1,987

Elad-A לא מחובר  

[PHP] צריך עזרה בשאילתה

שלום,

יש לי את הקוד הבא:
PHP קוד:
<? 
class db{  

var 
$db;  

function 
connect($host$username$password$db_name){  

    
$this->db mysql_connect($host,$username,$password)  
        or die(
"שגיאה");  
      
    
mysql_select_db($db_name,$this->db)  
    or die(
"שגיאה");  
      
    }  
function 
query($query
    { 
        
$res mysql_query("blabla"); 
    return 
$res
    } 
function 
fetch_rows() 
    { 
        return 
mysql_fetch_array($res); 
    } 
function 
num_rows() 
    { 
        return 
mysql_num_rows($res); 
    } 

}   
$db = new db;  
$db->connect("localhost","root","","ea2"); 
$db->query("SELECT * FROM ibf_thanks"); 
$rows $db->num_rows(); 
if(
$rows == 0

echo 
"no"

else 

$users=$db->fetch_rows(); 
echo 
$users 

?>
ההתחברות למסד עובדת אך יש בעיה עם השאילתה. תודה לעוזרים.
  Reply With Quote
ישן 13-08-06, 12:14   # 2
drowkid
חבר בקהילה
 
מיני פרופיל
תאריך הצטרפות: Apr 2006
מיקום: מרכז - איזור כפ"ס
הודעות: 138

drowkid לא מחובר  

תעשה מה שאמרתי לך...
PHP קוד:
global $res
אמממ
PHP קוד:
function fetch_rows() 
    { 
global 
$res;
        return 
mysql_fetch_array($res); 
    } 
function 
num_rows() 
    { 
global 
$res;
        return 
mysql_num_rows($res); 
    } 
הסבר:
גלובל עושה שתוכל להישתמש במישתנים שהוגדרו מחוץ לפונקציה...
__________________

Last edited by drowkid; 13-08-06 at 12:16..
  Reply With Quote
ישן 13-08-06, 12:30   # 3
Elad-A
הוסטסניון
 
מיני פרופיל
תאריך הצטרפות: May 2006
הודעות: 1,987

Elad-A לא מחובר  

ניסתי לעשות ככה:
PHP קוד:
class db

var 
$db

function 
connect($host$username$password$db_name){ 

    
$this->db mysql_connect($host,$username,$password
        or die(
"שגיאה"); 
     
    
mysql_select_db($db_name,$this->db
    or die(
"שגיאה"); 
     
    } 
function 
query($query)
    {
        
$res mysql_query("blabla");
    return 
$res;
    }
function 
fetch_rows() 
    { 
global 
$res;
        return 
mysql_fetch_array($res); 
    } 
function 
num_rows() 
    { 
global 
$res;
        return 
mysql_num_rows($res); 
    }

}  

$db = new db;  
$db->connect("localhost","root","","ea2");
$db->query("select * from ibf_thanks");
$db->fetch_rows();
$db->num_rows();
while(
$row $db->fetch_rows()) 
{
@
$ida$row['user_id'];
@
$namea $row['user_name'];
@
$datea $row['thank_date'];
echo <<<END
, <a href="index.php?showuser=$ida">$namea</a>
END;

זה השגיאה..
PHP קוד:
Warningmysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:program fileseasyphp1-8wwwtestindex.php on line 52

Warning
mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:program fileseasyphp1-8wwwtestindex.php on line 57

Warning
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:program fileseasyphp1-8wwwtestindex.php on line 52 
  Reply With Quote
ישן 13-08-06, 12:44   # 4
amirs_5
הוסטסניון
 
amirs_5's Avatar
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
מיקום: ת"א
גיל: 34
הודעות: 2,168
שלח הודעה באמצעות ICO אל amirs_5 Send a message via Skype™ to amirs_5

amirs_5 לא מחובר  

שניה עורך טעות..

עריכה :
HTML קוד:
function query($query) 
    { 
global $res;
        $res = mysql_query("blabla"); 
    return $res; 
    }
צריך גם בפונקציה הזאתי להכיר אותו כ global.
__________________
אימיל \ מסן : amirs91 [at] gmail.com

Last edited by amirs_5; 13-08-06 at 12:46..
  Reply With Quote
ישן 13-08-06, 12:45   # 5
lalamen
חבר פורום
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
גיל: 34
הודעות: 328

lalamen לא מחובר  

מצאתי לך מחלקה של DATEBASE תסתכל איך הם עשו

PHP קוד:
class mysql {

  function 
Connect($host$name$pass$db){

  
$connection mysql_connect("$host",
  
"$name",
  
"$pass");
  
mysql_select_db("$db"$connection);

  }
//ends the connection function

  
function Close(){

  
mysql_close($this->connection);

  }
//ends the close function

  
function FetchRow($query){
  
$rows mysql_fetch_row($query);
  return 
$rows;
  }

  function 
FetchArray($query){
  
$array mysql_fetch_array($query);
  return 
$array;
  }

  function 
FetchNum($query){
  
$num mysql_num_rows($query);
  return 
$num;
  }

  function 
Query($sql){
  
$query mysql_query($sql) or die(mysql_error());
  return 
$query;
  }
//ends the query function

  
}//ends the class 
דוגמא לשימוש במחלקה

PHP קוד:
 include("mysql_class.php");

  
$DB = new mysql();

  
$host "localhost";
  
$name "username";
  
$pass "password";
  
$db "dbname";

  
$connection $DB->Connect($host$name$pass$db);

  
//define an SQL statement and execute it
  
$sql "SELECT title,author FROM news";
  
$query $DB->Query($sql);

  
//fetch a single row and output it
  
$newsrow $DB->FetchRow($query);
  
$title $newsrow[0];
  
$author $newsrow[1];
  echo 
"<b>Single Row</b><br /><br />Title: $title<br>
  Author: $author<br><br>"
;

  
//output all rows from the statement
  
while($array $DB->FetchArray($query)){
  
extract($array);
  echo 
"<b>All rows</b><br /><br />Title: $title<b>
  Author: $author<br />"
;
  }

  
//find the number of rows
  
$num $DB->FetchNum($query);
  echo 
"Number of rows: $num";

  
//close the connection
  
$DB->Close(); 
  Reply With Quote
ישן 13-08-06, 12:58   # 6
Elad-A
הוסטסניון
 
מיני פרופיל
תאריך הצטרפות: May 2006
הודעות: 1,987

Elad-A לא מחובר  

תודה עכשיו עוד בעיה קטנה עם זה. זה שולף את הנתונים אבל מציג שגיאה:
PHP קוד:
NoticeUndefined propertyconnection in c:program fileseasyphp1-8wwwtestindex.php on line 44

Warning
mysql_close(): supplied argument is not a valid MySQL-Link resource in c:program fileseasyphp1-8wwwtestindex.php on line 44 
  Reply With Quote
ישן 13-08-06, 13:10   # 7
amirs_5
הוסטסניון
 
amirs_5's Avatar
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
מיקום: ת"א
גיל: 34
הודעות: 2,168
שלח הודעה באמצעות ICO אל amirs_5 Send a message via Skype™ to amirs_5

amirs_5 לא מחובר  

טוב הסתכלתי בקוד ובשגיאה ואיו בקוד mysql_close ככה שהשגיאה קצת מוזרה..
השגיאה בשורה 44...
להלן :
PHP קוד:
echo <<<END 
, <a href="index.php?showuser=$ida">$namea</a
END
אני לא מכיר את END , וגם אני לא חושב שמה שאני יגיד יעזור אבל תוכל לנסות לרשום שניה
PHP קוד:
echo ", <a href=\"index.php?showuser=$ida\">$namea</a>"
תנסה ותגיד לי אם עזר לך אם לא אני ינסה את המחלקה אצלי בשרת ונראה מה הבעיה בה כבר..
__________________
אימיל \ מסן : amirs91 [at] gmail.com

Last edited by amirs_5; 13-08-06 at 13:18..
  Reply With Quote
ישן 13-08-06, 13:38   # 8
Elad-A
הוסטסניון
 
מיני פרופיל
תאריך הצטרפות: May 2006
הודעות: 1,987

Elad-A לא מחובר  

שיניתי כבר לפני זה את החלק הזה ועדיין השגיאה אותו דבר.
  Reply With Quote
ישן 13-08-06, 18:30   # 9
RS324
תודה על תרומתך.
 
מיני פרופיל
תאריך הצטרפות: May 2006
הודעות: 3,173

RS324 לא מחובר  

טוב מספיק עם השטויות שמדברים פה, בכללי בגלל שזה CLASS זה עובד קצת אחרת

קודם כל תגדיר משתנה שנקרא לדוגמא CON ואז
mysql_query($query,$this->con)

ופה נגמר הסיפור .

אין שום קשר ל GLOBAL או לשטויות אחרות שנאמרו פה
  Reply With Quote
השב

חברים פעילים הצופים באשכול זה: 1 (0 חברים ו- 1 אורחים)
 


חוקי פירסום
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is מופעל
סמיילים הם מופעל
[IMG] קוד מופעל
קוד HTML מכובה

קפיצה לפורום


כל הזמנים הם GMT +2. הזמן כעת הוא 01:51.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ