
ruler
Members-
Posts
11 -
Joined
-
Last visited
Everything posted by ruler
-
in the config file right after the connection are these two lines: //create PDO connection $db = new PDO("mysql:host=".DBHOST.";port=3306;dbname=".DBNAME, DBUSER, DBPASS); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); oddly enough i dont get any errors at all now after changing line 170 to: while($row = $stmt->fetch($result)) I am uncertain how to use the PDO ->query() method, i think ive tried every combination known to man from reference manuals online but none of them give any solid information, the demos are very limited and brief. php4 was so much easier, i hate that they changed it
-
that link above that you provided didnt help, it actually confused me lol Ive made no progress at all, still stuck on the very same piece of code that i was stuck on yesterday, the same line. I think a great breakthrough would be if i could get these 2 lines converted into PDO format. $query1 = "SELECT * FROM members LIMIT $start, $limit"; $result = mysql_query($query1); I know what the first line does but i am unsure about the 2nd line, its been a long time since ive done any code. its like being lost in space a simple conversion would be much preferrable, ive spent far too long reading up and learning nothing
-
this section below $stmt = $db->prepare("SELECT COUNT(*) as num FROM members"); $stmt->bindParam(':members', $q, PDO::PARAM_INT); $stmt->execute(); $total_pages = $stmt->fetchColumn(0); was originally like below $query = "SELECT COUNT(*) as num FROM $tableName"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages[num]; but with the help of another script i had(unrelated) i managed to figure out how to convert it. the only troubles i now have is with the other mysql_ parts, once i can get those converted i hope to see a working php5 pagination script. ive spent several days looking for a ready made one in php5 but strangely enough there are next to none floating about, the ones that are about are either simple ones or not very optimised. I have also tried asking for help on many forums but most of those forums are either dead or have people who assume you should already know all the answers, they forget what the forum is actually for i do know php4 but i am reall struggling with php5 that is why i am trying to get help so i can understand it better.
-
Hi I am trying to convert an old pagination script to work with php5 or higher. I believe this script or similar has been discussed before on this forum but I thought I'd start a new topic. Not all of the script needs converting, only a few lines which contain mysql_ ect This is the script i am working with but havnt included the config file but the info can be provided if needed. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Papermashup.com | PHP Pagination</title> <link href="../style.css" rel="stylesheet" type="text/css" /> <style> .paginate { font-family:Arial, Helvetica, sans-serif; padding: 3px; margin: 3px; } .paginate a { padding:2px 5px 2px 5px; margin:2px; border:1px solid #999; text-decoration:none; color: #666; } .paginate a:hover, .paginate a:active { border: 1px solid #999; color: #000; } .paginate span.current { margin: 2px; padding: 2px 5px 2px 5px; border: 1px solid #999; font-weight: bold; background-color: #999; color: #FFF; } .paginate span.disabled { padding:2px 5px 2px 5px; margin:2px; border:1px solid #eee; color:#DDD; } li{ padding:4px; margin-bottom:3px; background-color:#FCC; list-style:none;} ul{margin:6px; padding:0px;} </style> </head> <body> <?php require('includes/config.php'); $targetpage = 'pagination.php'; $limit = 10; $stmt = $db->prepare("SELECT COUNT(*) as num FROM members"); $stmt->bindParam(':members', $q, PDO::PARAM_INT); $stmt->execute(); $total_pages = $stmt->fetchColumn(0); $stages = 3; $page = (isset($_GET["page"])) ? (int)$_GET["page"] : 1; if($page){ $start = ($page - 1) * $limit; }else{ $start = 0; } // Get page data $query1 = "SELECT * FROM members LIMIT $start, $limit"; $result = mysql_query($query1); // Initial page num setup if ($page == 0){$page = 1;} $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total_pages/$limit); $LastPagem1 = $lastpage - 1; $paginate = ''; if($lastpage > 1) { $paginate .= '<div class="paginate">'; // Previous if ($page > 1){ $paginate.= '<a href="$targetpage?page=$prev">previous</a>'; }else{ $paginate.= '<span class="disabled">previous</span>'; } // Pages if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= '<span class="current">$counter</span>'; }else{ $paginate.= '<a href="$targetpage?page=$counter">$counter</a>';} } } elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few? { // Beginning only hide later pages if($page < 1 + ($stages * 2)) { for ($counter = 1; $counter < 4 + ($stages * 2); $counter++) { if ($counter == $page){ $paginate.= '<span class="current">$counter</span>'; }else{ $paginate.= '<a href="$targetpage?page=$counter">$counter</a>';} } $paginate.= '...'; $paginate.= '<a href="$targetpage?page=$LastPagem1">$LastPagem1</a>'; $paginate.= '<a href="$targetpage?page=$lastpage">$lastpage</a>'; } // Middle hide some front and some back elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2)) { $paginate.= '<a href="$targetpage?page=1">1</a>'; $paginate.= '<a href="$targetpage?page=2">2</a>'; $paginate.= '...'; for ($counter = $page - $stages; $counter <= $page + $stages; $counter++) { if ($counter == $page){ $paginate.= '<span class="current">$counter</span>'; }else{ $paginate.= '<a href="$targetpage?page=$counter">$counter</a>';} } $paginate.= '...'; $paginate.= '<a href="$targetpage?page=$LastPagem1">$LastPagem1</a>'; $paginate.= '<a href="$targetpage?page=$lastpage">$lastpage</a>'; } // End only hide early pages else { $paginate.= '<a href="$targetpage?page=1">1</a>'; $paginate.= '<a href="$targetpage?page=2">2</a>'; $paginate.= '...'; for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= '<span class="current">$counter</span>'; }else{ $paginate.= '<a href="$targetpage?page=$counter">$counter</a>';} } } } // Next if ($page < $counter - 1){ $paginate.= '<a href="$targetpage?page=$next">next</a>'; }else{ $paginate.= '<span class="disabled">next</span>'; } $paginate.= '</div>'; } echo $total_pages.' Results'; // pagination echo $paginate; ?> <ul> <?php while($row = mysql_fetch_array($result)) { echo '<li>'.$row['username'].'</li>'; } ?> </ul> </body> </html> The error I am getting is this: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\pagination.php on line 188 the url I am testing it on is this: http://www.finchkeeper.com/pagination.php I would appreciate what help I can get with this, it would be great to have this topic marked as [solved]. thanks
-
omg that code worked, i can't believe it ty ty ty im not sure of any other way to allow only 1 vote per person apart from using the IP method, if you know of another way that would be great. i know you can do it through cookies but it only takes someone to delete the cookies or use another browser or computer to get around it
-
ive been at this for weeks before i finally asked for help. i tried everything and run out of answers. it seems im very out of touch with php programming after a 8 year break. the idea of using an ip address was because i couldnt think of any other way to allow only one user to vote and people cant register to vote because it is just a simple voting system without user accounts. the main thing is everything is now working accept the ip matching issue. i still dont really know where to start or what code to use. maybe i have been looking at it too much
-
hi this is my first post here and really hoping to get some help with this. just left another php forum because i found them to be unfriendly and unhelpful. below i have a small script which is part of a photo voting system. when a person votes on a photo it is supposed to check their IP and then check the db to see if their IP is already listed and if it is listed then they can not vote again, only one vote per person. i really do not know how to get this thing working and i have tried everything i can, even google led me on a wild goose chase. in the script i have marked where the problem is and really hope someone can help thanks <?php include("config.php"); if(isset($_POST['id']) and !empty($_POST['id'])){ $id= intval($_POST['id']); $contest= htmlspecialchars($_POST['contest']); $ip = $_POST['fingerprint']; $ret = mysqli_query($bd, "select * from contests where contest = '$contest'"); if ($ret !== null){ $contest_settings = mysqli_fetch_object($ret); if ($contest_settings->voting_type == "contest"){ $ip_sql=mysqli_query($bd, "select ip_add from image_IP where contest = '$contest'"); }else{ $ip_sql=mysqli_query($bd, "select ip_add from image_IP where img_id_fk=$id and ip_add='$ip'"); } // next 2 lines need changing to search the db in collumn ip_add and compare if the connecting users ip is listed and if not then allow the vote. if the ip is found then deny the vote. $query = mysqli_query($bd,"SELECT ip_add FROM image_ip WHERE ip_add=$ip"); // the line above is my problem and the line below if($ip !== $query){ $sql = "UPDATE `images` SET love = love +1 WHERE img_id = ".$id; mysqli_query($bd, $sql); $sql_in = "insert into image_IP (ip_add,img_id_fk,contest) values ('$ip',$id,'$contest')"; mysqli_query($bd, $sql_in); $result=mysqli_query($bd, "select love from images where img_id=$id"); $row=mysqli_fetch_array($result); $love=$row['love']; ?> <span title="<?php echo _('I vote for this.'); ?>"><span class="fa fa-heart"></span> <?php echo $love; ?> </span> <?php }else{ echo _('You have already voted !'); } } } if (isset($_POST['action'])){ if ($_POST['action'] == 'login'){ $pwd = $_POST['pwd']; if ($pwd == PASSWD){ $ok = setcookie(COOKIE_NAME, sha1(PASSWD.HASH), 0, '/', '', FALSE, TRUE); if (!$ok){ echo '<div class="alert error">cookie failed !</div>'; } }else{ echo '<div class="alert error"><a class="alert-close" href="#" title="'._('Close').'">×</a>'._('Wrong password !').'</div>'; } } } ?> in the database the column ip_add is varchar(40)