-
Posts
18 -
Joined
-
Last visited
About skurai
- Birthday 07/14/1986
Profile Information
-
Gender
Male
skurai's Achievements

Newbie (1/5)
0
Reputation
-
Look below that, the SQL is used in the Order Object lookup. $sql = "SELECT * FROM orders WHERE customerid = 4 ORDER BY {$order} {$order_by} "; $sql .= "LIMIT {$per_page} "; $sql .= "OFFSET {$pagination->offset()}"; $orders = Order::find_by_sql($sql); The SQL above that was for testing the $total_count. I have tried it the way it is, and using the commented $total_count = Order::count_by_cust(4); Just for clarification, here is the find_by_mysql function in the Order object. public static function find_by_sql($sql=""){ global $database; $result_set = $database->query($sql); $object_array = array(); while ($row = $database->fetch_array($result_set)){ $object_array[] = self::instantiate($row); }
-
I have a basic pagination class, I have used on several pages of a site I am working on. It works fine on 3 of the pages, but when I try to use it on any other pages, or even a new blank page I wrote, it does not work. class Pagination { public $current_page; public $per_page; public $total_count; public function __construct($page=1, $per_page=20, $total_count=0) { $this->current_page = (int)$page; $this->per_page = (int)$per_page; $this->total_count = (int)$total_count; } public function offset(){ return ($this->current_page - 1) * $this->per_page; } public function total_pages(){ return ceil($this->total_count/$this->per_page); } public function previous_page(){ return $this->current_page - 1; } public function next_page(){ return $this->current_page + 1; } public function has_prev_page(){ return $this->previous_page() >= 1 ? true : false; } public function has_next_page(){ return $this->next_page() <= $this->total_pages() ? true : false; } That is the pagination class, and this is the code I use to call it, along with some debugging information I am using. if(isset($_GET['order'])){ $order = $_GET['order']; } else { $order = "id"; } if(isset($_GET['orderby'])){ $order_by = $_GET['orderby']; } else { $order_by = "ASC"; } $page = !empty($_GET['page']) ? (int)$_GET['page'] : 1; $per_page = 2; $sql = mysql_query("SELECT * FROM orders WHERE customerid = 4"); $result = mysql_fetch_array($sql); $total_count = mysql_num_rows($sql); //$total_count = Order::count_by_cust(4); $pagination = new Pagination($page, $per_page, $total_count); $sql = "SELECT * FROM orders WHERE customerid = 4 ORDER BY {$order} {$order_by} "; $sql .= "LIMIT {$per_page} "; $sql .= "OFFSET {$pagination->offset()}"; $orders = Order::find_by_sql($sql); echo "Page:" . $page . "<br />PerPage:" . $per_page . "<br />Total:" . $total_count . "<br />Total Pages:" . $pagination->total_pages(); ?> SOME FOREACH INFORMATION HERE <?php echo "Has Prev Page:" . $pagination->has_prev_page() . "<br />"; echo "Total Pages:" . $pagination->total_pages() . "<br />"; echo "Has Next Page:" . $pagination->has_next_page() . "<br />"; ?> <div id="pagination" style="clear: both; text-align: center;"> <?php if ($pagination->total_pages() > 1){ if ($pagination->has_prev_page() == 1){ echo "<a href=\"orders.php?search&uid={$order->customerid}&order={$order}&orderby={$order_by}&page="; echo $pagination->previous_page(); echo "\">« Previous</a>"; } for($i=1; $i<=$pagination->total_pages(); $i++){ if($i == $page){ echo " <span class=\"selected\">{$i}</span> "; } else { echo " <a href=\"orders.php?search&uid={$order->customerid}&order={$order}&orderby={$order_by}&page={$i}\">{$i}</a> "; } } if ($pagination->has_next_page() == 1){ echo "<a href=\"orders.php?search&uid=" . $order->customerid . "&order=" . $order . "&orderby=" . $order_by . "&page="; echo $pagination->next_page(); echo "\">Next »</a>"; } } ?> </div> The customer ID is dynamic, but for debugging sake I am using the customer ID of 4. The output of the page has the following informaton: Page:1 PerPage:2 Total:15 Total Pages:8 Has Prev Page: Total Pages:8 Has Next Page:1 So i know all the variables are right, the problem is, it only prints a bold "1". Thats all, no numbers, or Next Page option. However i use the EXACT same code in another couple pages, and it works fine, but with this current page and a few others. It does not work. I have also tryed extracting just this information into a blank file to just get the page numbers, taking out all the pages other code, and it still only gives me "1". Any ideas?
-
If you even plan on having anywhere on the website where a user enters a credit card number, you need an SSL. Do you have one?
-
try making the folder lowercase C, and doing the same in the code.
-
Dstar, you can store images in the DB as well. if($_FILES['file']['size'] > 0) { $fileName = $_FILES['file']['name']; $tmpName = $_FILES['file']['tmp_name']; $fileSize = $_FILES['file']['size']; $fileType = $_FILES['file']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $query = "INSERT INTO pictures (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error: Upload pictures failed.'); } then view the picture with viewimage.php?id=1 if(isset($_GET['id'])) { $id=$_GET['id']; $query = "select content, type from pictures where id=$id"; $result = mysql_query($query); $row = mysql_fetch_array($result); $data = $row['content']; $type = $row['type']; if ($type=="image/jpeg") $type = "jpeg"; Header( "Content-type: $type"); echo $data; } and you would show the image with <img src="viewimage.php?id=1" alt="" width="250" height="250"> and put the relevent data next to that image
-
you would make it for example.... <img src="2ndfile.php?id=1" border="0" alt="" />
-
folder "." is go back 1 folder back, like u are at c:\windows\system32, it will go back to c:\windows folder ".." is go back to root, i think, so, u will be at c:\ after u clicked it most files has extensions, so, your way just strip many files out too I have used this method many different times on many different projects and it has never stripped out any proper files out of the count
-
how are you storing the files into the array? can you post more code?
-
Or you can strip out those files from being seen: if(is_dir($dir)){ $dir_array = scandir($dir); foreach($dir_array as $file) { if(stripos($file, '.') > 0) { echo "There are files in the folder"; } else { echo "There are no files"; } } }
-
haha, well right after i posted my response, it refreshed the page and I saw your edit. My bad
-
Beautiful! thank you. Guess i needed someone else to look at it after i stare at it for a while i would miss something like that. For anyone who has similar trouble, protected static $db_fields=array('id', 'photo_id', 'created', 'author', 'body'); public $id; public $photo_id; public $created; public $author; public $body; public $picture; public static function make($photo_id, $author="Anonymous", $body=""){ if(!empty($photo_id) && !empty($author) && !empty($body)){ $comment = new Comment(); $comment->photo_id = $photo_id; $comment->created = strftime("%Y-%m-%d %H:%M:%S", time()); $comment->author = $author; $comment->body = $body; return $comment; Thank you again.
-
$comment->photographid = 7; I changed the variable to 7 just for testing purposes, and it still does not add it. The query does not show it either.
-
I went ahead and edited for testing purposes another of the classes that uses create(), and put in a col in the table just for a number to reflect the photo_id, and submitted a random number the same way I am calling create() here, and it adds the number fine, so the attributes(), s_attributes() and create() seems to be working fine. where else should i look? PS. For reference, i am including the attributes() and s_attributes() protected function attributes(){ $attributes = array(); foreach(static::$db_fields as $field){ $attributes[$field] = $this->$field; } return $attributes; } protected function s_attributes(){ global $database; $clean_attributes = array(); foreach($this->attributes() as $key => $value){ $clean_attributes[$key] = $database->escape_value($value); } return $clean_attributes; }
-
INSERT INTO comments (id, photo_id, created, author, body) VALUES ('', '', '2010-03-19 13:18:38', 'ttt', 'ttt') that is the result of the $new_comment->create()
-
stupid me, i forgot to say which variable is not being stored. The photo_id is not being stored. the id is incrementing, the author, created, and body all work, but photo_id will not store.