הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   [PHP] בעיה מוזרה בפונקציה לשליפת נתונים מהמסד (https://hosts.co.il/forums/showthread.php?t=40904)

ShoQER 04-03-07 15:30

[PHP] בעיה מוזרה בפונקציה לשליפת נתונים מהמסד
 
היי.

יש לי פונקציה ששולפת נתונים מהמסד.
היא מאוד פשוטה וזה...

PHP קוד:

function select($tbl FALSE,$where FALSE,$order FALSE,$limit FALSE) {
 if(
$where) {
  
$where_do " WHERE $where";
 } else {
  
$where_do "";
 }
 if(
$limit) {
  
$limit_do " LIMIT $limit";
 } else {
  
$limit_do "";
 }
 if(
$order) {
  if(
$order != "rand()") {
   
$order explode(",",$order);
   
$order_do " ORDER BY $order[0] $order[1]";
  } else {
   
$order_do " ORDER BY rand()";
  }
 } else {
  
$order_do "";
 }
 if(!
$tbl) {
  
db::set_error("You didn't set a table name.");
 }
 
$query db::query("SELECT * FROM `{$tbl}`{$where_do}{$order_do}{$limit_do}");
 return 
$query;


עכשיו...הכל עבד מצויין עד שקראתי לה ככה:
PHP קוד:

 $where "`srLogged`='1'";
 
$order '`srID` DESC';
 
$select db::select('users'$where$order); 

מה ששונה זה החלק של הORDER...הוספתי DESC... וזה יצר לי בעיה.

השגיאה:
Notice: Undefined index: 1 in C:\Program Files\EasyPHP 2.0b1\www\dreamy\source\db.php on line 56

אני כבר שעתיים שובר תראש...מנסה להבין מה השגיאה הזאת רוצה ממני...

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

בניה 04-03-07 15:39

תביא את כל הדף.

ShoQER 04-03-07 15:43

זה הDB :
PHP קוד:

<?php
class db {
function 
connect($host,$user,$pass,$db_name) {
 @
mysql_connect($host,$user,$pass) or db::set_error("Could Not Connect to the MySQL Database!");
 @
mysql_select_db($db_name) or db::set_error("Could Not Select the MySQL Database!");
}
function 
query_error($sql_query) {
 die(
'<div style="width: 500px; font-family: arial;">
 <span style="font-size: 24px"><span style="color: red">Fatal Error:</span>There is a problem with the query !</span>
 <hr style="color: red; height: 1px;">
 <span style="font-size: 15px">The Query Was:</span>
 <textarea style="width: 100%; height: 100px">'
.$sql_query.'</textarea>
 <hr style="color: red; height: 1px">
 <span style="font-size: 15px">MySQL Says:</span>
 '
.mysql_error().'
 </div>'
);
}
function 
set_error($error) {
 die(
'<div style="width: 500px; font-family: arial;">
 <span style="font-size: 24px; color: red">Fatal Error!</span>
 <hr style="color: red; height: 1px;">
 '
.$error.'
 </div>'
);
}
function 
query($sql_query) {
 
$query mysql_query($sql_query) or db::query_error($sql_query);
 return 
$query;
}
function 
fetch($query) {
 
$return mysql_fetch_array($query);
 return 
$return;
}
function 
select($tbl FALSE,$where FALSE,$order FALSE,$limit FALSE) {
 if(
$where) {
  
$where_do " WHERE $where";
 } else {
  
$where_do "";
 }
 if(
$limit) {
  
$limit_do " LIMIT $limit";
 } else {
  
$limit_do "";
 }
 if(
$order) {
  if(
$order != "rand()") {
   
$order explode(",",$order);
   
$order_do " ORDER BY $order[0] $order[1]";
  } else {
   
$order_do " ORDER BY rand()";
  }
 } else {
  
$order_do "";
 }
 if(!
$tbl) {
  
db::set_error("You didn't set a table name.");
 }
 
$query db::query("SELECT * FROM `{$tbl}`{$where_do}{$order_do}{$limit_do}");
 return 
$query;
}
function 
delete($tbl FALSE,$where FALSE) {
 if(!
$tbl) {
  
db::set_error("You didn't set a table name to delete from.");
 }
 if(!
$where) {
  
db::set_error('You didn\'t set the "WHERE" method.');
 }
 
db::query("DELETE FROM $tbl WHERE $where");
}
function 
insert($tbl FALSE,$values FALSE){
 if(!
$tbl) {
  
db::set_error("You didn't set a table name to insert to.");
 }
 if(!
$values) {
  
db::set_error("You didn't set which values to insert.");
 }
 
db::query("INSERT INTO $tbl VALUES($values)");
}
function 
update($tbl FALSE,$values FALSE,$where FALSE) {
 if(!
$tbl) {
  
db::set_error("You didn't set the table name to update.");
 }
 if(!
$values) {
  
db::set_error("You didn't set which values to update.");
 }
 
$values explode(",",$values);
 
$i 0;
 foreach(
$values as $key) {
  
$i++;
  if(
$i == 1) {
   
$comma "";
  } else {
   
$comma ",";
  }
  
$key explode("#",$key);
  for(
$i=1;$i count($key);$i++) {
   if(
$i == count($key) - 1) {
    
$telephone "";
   } else {
    
$telephone "#";
   }
   
$all_key .= "$key[$i]{$telephone}";
  }
  
$values_do .= "{$comma} $key[0] = '$all_key'";
 }
 if(
$where) {
  
$where_do " WHERE {$where}";
 }
 
db::query("UPDATE $tbl SET $values_do{$where_do}");
}
function 
secure($text) {
 
$text mysql_real_escape_string($text);
 return 
$text;
}
function 
count($text) {
 
$text mysql_num_rows($text);
 return 
$text;
}
}
$db = new db;
?>

וזו הפונקציה המלאה שקוראת לשליפה:
PHP קוד:

function badmins() {
 
$where "`srLogged`='1'";
 
$order '`srID` DESC';
 
$select db::select('users'$where$order);
 
$lis null;
 while(
$row db::fetch($select)) {
  
$name $row['srFName'];
  
$location null;
  
$id $row['srID'];
  
$lis .= '<li><span class="span1">'.$name.'</span><span class="span2">'.$location.'</span><a href="?op=badmin&do=logout&id='.$id.'"><img src="images/X.png" alt="נתק מנהל" /></a></li>';
 }
 return 
skin::logmanage($lis);



RS324 04-03-07 21:27

בתוך הפונקציה אתה עושה

PHP קוד:

$order explode(",",$order); 

ספליט לפסיק

ואתה מכניס כנתון
PHP קוד:

 $order '`srID` DESC'

חסר לך פסיק באמצע

ככה :

PHP קוד:

 $order '`srID`, DESC'



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

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