PHP - Adding Pagination To Existing Product Pages
Hi there, I've been trying to implement pagination to an existing script that displays products, but at present only displays next and back buttons. The number of products is now increasing and we would like to show the number of pages of results but the tutorials I've been going through seem to use a very different way of displaying the results to the script we currently have. Does anyone have any suggestions how I could add pagination to this form.....
// Build Pagination $ByPage = ($prod_rows * $prod_cols); $qnav = "SELECT devbg_products.*, devbg_categories.*, devbg_subcategories.* FROM devbg_products LEFT JOIN devbg_categories ON devbg_products.ItemCategory = devbg_categories.CategoryID LEFT JOIN devbg_subcategories ON devbg_products.ItemSubcategory = devbg_subcategories.SubcategoryID WHERE devbg_products.ItemCategory = " . sql($cgid); $rnav = mysql_query($qnav) or die(mysql_error()); $rows = mysql_num_rows($rnav); if($rows > $ByPage) { $pages = ceil ($rows / $ByPage); echo "<br>\n"; echo "<table align='center'>\n"; echo "<tr>\n"; echo "<td align=center><font face=verdana size=2>"; echo "<form method='POST' action='ShowCategory.php'>\n"; echo "<input type='hidden' name='Start' value='" . ($Start - $ByPage) . "'>\n"; echo "<input type='hidden' name='CategoryID' value='" . $_REQUEST["CategoryID"] . "'>\n"; echo "<input type='hidden' name='SubcategoryID' value='" . $_REQUEST["SubcategoryID"] . "'>\n"; if (($Start - $ByPage) <> -$ByPage) { echo "<input class='sub' type='submit' value='<<< Back' name='btnBack'>\n"; echo "</form>\n"; echo "</td>\n"; } echo "<td>\n"; echo "<form method='POST' action='ShowCategory.php'>\n"; echo "<input type='hidden' name='Start' value='" . ($Start + $ByPage) . "'>\n"; echo "<input type='hidden' name='CategoryID' value='" . $_REQUEST["CategoryID"] . "'>\n"; echo "<input type='hidden' name='SubcategoryID' value='" . $_REQUEST["SubcategoryID"] . "'>\n"; if ($Start + $ByPage < $pages * $ByPage) { echo "<input class='sub' type='submit' value='Next >>>' name='btnNext'>"; } echo "</form>\n"; echo "</td>\n"; echo "</tr>\n"; echo "</table><br><br>\n"; } Similar TutorialsHello,
First time asking technical question in a forum so I beg pardon for errors.
I have a third party blog module installed on opencart. The original coder helped me to fix some bugs, but he is not answering anymore to emails.
I would like to add a simple pagination to the "latest articles" part, because at the moment the website display the exact number declared in "article limit" and does not show pagination if articles shown are less than the total.
the code from "article_by_type.php" line 85 is the following:
/*recent_article*/ if ($setting['article_type']=='recent_article') { $data = array( 'sort' => 'p.date_added', 'order' => 'DESC', 'start' => 0, 'limit' => $article_limit ); $articles = $this->model_news_article->getArticles($data); }another file "article_list.php" at line 88 and 214 already have pagination: $this->data['article_ajax_load'] = $this->getArticle($article_category_id,$page,$limit,$description_limit);can anyone help add pagination to "article_by_type.php" or adapt the existing pagination code to it ? Attached Files article_by_type.php 6.23KB 0 downloads article_list.php 10.2KB 0 downloads Hello All! I was hoping one of you phpFreaks could help me out I have the following code that produces links from a database. Certain sets of results have over 3000 links. I can currently set the amount of links to display per page but that's it. I would like to be able to truncate the links to all the pages using pagination. Any help would be greatly appreciated! Here is the code: <?php echo "Results<br><HR WIDTH=100% SIZE=1><br>"; mysql_connect("mysite.com", "mysite_mysite", "mysitepassword") or die(mysql_error()); mysql_select_db("user_database") or die(mysql_error()); if (isset($_GET['pagenum'])) { $pagenum = $_GET['pagenum']; } else { $pagenum = 1; } $rpg = $pagenum; $data = mysql_query("SELECT * FROM mydb WHERE mfg='golf'") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 80; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM mydb WHERE mfg='golf' $max") or die(mysql_error()); while($info = mysql_fetch_array( $data_p )) { $page=$info['link']; echo "<a href='$page' class='blue1'>". $info['title'] . "</a><br>"; } echo "<p>"; if ($pagenum > $last) {$pagenum=1;} else { echo "<HR WIDTH=100% SIZE=1><br>"; $pagenum = 1; while ($pagenum <= $last) { $next = $pagenum; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next' class='g5'>$pagenum</a> "; $pagenum = $pagenum+1; } Echo "<br><br>Page $rpg of $last <br>"; } ?> Simple insertion of pagination would be GREAT! Thanks guys.... The web application should allow the user to view the items in a catalogue, add items to a shopping cart, remove items from the shopping cart, and to view the contents of the shopping cart. Hey guys. Right ill try explain as best i can. Basicly we were told to write a php script that can view a shopping cart. The items in the catalogue should be stored as an array of objects. (The next assignment will require you to store this list of objects in a database). There should also be pages to allow the user to add, edit and delete items in the catalogue. Thats taken from a brief.Ive spent the most of the week getting it to view a catalog and now it can add items.view the cart its added them to and remove them from the cart and return. What im having trouble with is making the add function for the the other users or admin* to add/edit/delete.i reckoned adding and deleting wouldnt be so bad considering ive alrready done so.But im kinda stumped on how to do it.i think what the brief wanted was a seprate product add that would actully let u add another product to the cart list on the same page and then u can add that to the shopping basket etc. Yea real stumped.if only it was through sql it would be so much handier. ill post the code below.if anyone can help at all in the slightest id be so grateful.Thank you.
Hello! I found this code from github. https://github.com/gburtini/Learning-Library-for-PHP and I want to know if its possible to add variables to it and what changes needed to be done to the whole script. $xs and $ys I want replace them and add two more. The whole code is he <?php require_once 'function.php'; function ll_nn_predict($xs, $ys, $row, $k) { $distances = ll_nearestNeighbors($xs, $row); $distances = array_slice($distances, 0, $k); $predictions = array(); foreach($distances as $neighbor=>$distance) { $predictions[$ys[$neighbor]]++; } asort($predictions); return $predictions; } function ll_nearestNeighbors($xs, $row) { $testPoint = $xs[$row]; $distances = _ll_distances_to_point($xs, $testPoint); return $distances; } function _ll_distances_to_point($xs, $x) { $distances = array(); foreach($xs as $index=>$xi) { $distances[$index] = ll_euclidean_distance($xi, $x); } asort($distances); array_shift($distances); return $distances; } and the function.php that is required is this: <?php function ll_transpose($rows) { $columns = array(); for($i=0;$i<count($rows);$i++) { for($k = 0; $k<count($rows[$i]); $k++) { $columns[$k][$i] = $rows[$i][$k]; } } return $columns; } function ll_mean($array) { return array_sum($array)/($array); } function ll_variance($array) { $mean = ll_mean($array); $sum_difference = 0; $n = count($array); for($i=0; $i<$n; $i++) { $sum_difference += pow(($array[$i] - $mean),2); } $variance = $sum_difference / $n; return $variance; } function ll_euclidean_distance($a, $b) { if(count($a) != count($b)) return false; $distance = 0; for($i=0;$i<count($a);$i++) { $distance += pow($a[$i] - $b[$i], 2); } return sqrt($distance); } I just want to know where is the variables in those 2 scripts and add more as I'm not well versed in using PHP. Thank you! I need some guidance in regards to adding Login with Facebook.
Is this something which is easily done? Currently, I'm using UserCake:
http://usercake.com/
How much testing and QA is necessary for this type of work?
This is the code that I'm using for a shopping cart in order to update the quantity if the same product id is chosen. $cart_items is a two-dimensional session array composed of the id session array and the quantity session array. While looping through $cart_items, I create a temporary array $temp_array so that I can execute some logic on the array without changing the normal output. $temp_array is the $cart_items array without the last items which would be the $_REQUEST id and the $_REQUEST quantity. So the two $_REQUESTs are popped off with array_pop and then the remaining $_SESSIONs are compared to the $_REQUEST id with
$j = array_search($_REQUEST["element_id_$i"], $temp_array); if( $j==$temp_array[$i]) If $j is the key of the item in $temp_array, then the $_REQUEST is unset and the quantities for the item are added together.
There are two problems with this code. First of all the var_dump of the $temp_array is always an empty array but I am expecting to get an array with just the last element popped off. Secondly, foreach($cart_items as $item) { foreach($item["id"] as $key => $val) { foreach($item["quantity"] as $i => $value) { if ($key == $i){ $temp_array = $cart_items; $array = array_pop($temp_array); var_dump($temp_array); if (isset($_REQUEST["element_id_$i"]) && isset($_REQUEST["quantity_$i"])&& isset($value)){ $j = array_search($_REQUEST["element_id_$i"], $temp_array); if( $j==$temp_array[$i]) { echo "<b>SAME PRODUCT ADDED</b>"; $value += $_REQUEST["quantity_$i"]; unset($_REQUEST["element_id_$i"]); }}}}}}
Hi, I have a basic form that lets people enter details Code: [Select] <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Second name: <input type="text" name="sname" /> <input type="submit" /> </form> And the standard insert in sql command. Im now looking to add a image uplad field the the same form. I have tried several methods off the internet but i cant get any to work. I would like the form to upload the image into the directory '../images' and then save the path to the file in the database, e.g. 'images/picture.jpg'. Can anyone point me in the right direction please. Im guessing i will have to use the file input type but i cant get any of it to work. Thanks Hello and good day to all of you I have passed my midterms project(Online Shopping) with a score of 94 in PHP ( Click here to see file ) ( Sorry if the design is too ugly, I'm just new in programming XD ) Now our finals project will be a PHP site again but now with a database in it.. So instead of making a new project/design for a site, why not just add a database to my existing midterms? I would like to ask for some help here in helping me on connecting to the database, adding a database/tables and anything that would be of help like suggesting Databases would be like, - Users ( Admin and Members ) - Upper Clothing ( Shirts, Jackets, Long Sleeves, Raglan and etc ) - Lower Clothing ( Pants, Shorts, Boxers and etc ) - Stock on a current item - Single member's Transaction History - All user's Transaction History Is there a way that I could add those database named above to my project? Thank you in advance! This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358003.0 Im not much of a coder, and I obviously did this wrong since it is not working. Im trying to bring a new field value in to an existing php file. I created a new table, and an admin page to control that field. I cant, however, figure out how to use that value in a different php file. Actually, there are 2 files. Each using a different field from that new table. I will post what my current code is below with the additions I tried to add. I bolded the lines that contain the tags Im trying to use. Any and help you can give in fixing this to make it work is greatly appreciated. Code: [Select] <?php # INCLUDE ALL NECESSARY FILES. include_once("Constants.php"); include_once("Database.php"); include_once("SiteSetting.php"); [b]$query = "SELECT arcade_multiplier FROM tbl_point_rewards"; mysql_query($query) or die("Invalid query". mysql_error() ); $result = mysql_fetch_array($result); $arcade_multiplier = $result["arcade_multiplier"];[/b] $dbObj = new database(); # SAVE ARCADE GAME POINTS INTO THE DATABASE function saveGamePoints( $game_id, $user_id, $game_score, $calculate_score_flag, $play_date ){ global $dbObj; $user_max_plays = getUserMaxPlaysLimit( $user_id, $game_id ); //$_SESSION["arcade_game"]["save_score"] = ($user_max_plays < $_SESSION["arcade_game"]["max_plays"]) ? "yes" : "no" ; if($user_max_plays < $_SESSION["arcade_game"][$_SESSION["url_gameid"]]["max_plays"]){ $total_points = calculatePointRatio($game_id, $game_score); //$total_points = $game_score; $x_gameid = md5($game_id); if($_SESSION["arcade_game"][$x_gameid]["play_time"] > 0){ $playTime['start'] = $_SESSION["arcade_game"][$x_gameid]["play_time"]; $playTime['end'] = time(); $playTime = ($playTime['end'] - $playTime['start']); } else { $playTime = 0; } # update total points into main score [b] $update_sql = "update tbl_users set points_gained = (points_gained+(".ceil($total_points)." * $arcade_multiplier)) where usrid={$user_id}";[/b] $rs = mysql_query($update_sql) or die("Invalid query: {$update_sql} - ". mysql_error()); $table = "tbl_arcade_game_score"; $fields = array("game_id", "user_id", "game_score", "calculate_score_flag", "play_date", "game_time"); $values = array($game_id, $user_id, $game_score, $calculate_score_flag, $play_date, $playTime); // return $dbObj->cgi( $table, $fields, $values, 1 ); $insertid = $dbObj->cgi( $table, $fields, $values, "" ); $ceiling_point = getCeiling($game_id); if($game_score >= $ceiling_point) { $chk_authourity = isAlreadyTrophyOwner($user_id, $game_id); //if($chk_authority < 1) if($chk_authourity < 1) { # store award details into the database (tbl_trophy_award) //$trophy_id = getTrophy( $game_id ); $trophy = getTrophyDetails($game_id); $trophy_id = $trophy['ctoon_id']; $tbl_fields = array('userid', 'game_id', 'award_date', 'trophy' ); $tbl_values = array($user_id, $game_id, $play_date, $trophy_id ); $insert_tbl_trophy_award_id = $dbObj->cgi('tbl_trophy_award', $tbl_fields, $tbl_values , "" ); # award trophy to user (tbl_users_ctoons) $table = "tbl_users_ctoons"; $fl = array("usrid", "ctoon_id", "del_status", "ctoons_auction", "auction_id", "location", "batpts"); $vl = array($user_id, $trophy_id, '0', '', 0, 1, 0); $dbObj->cgi($table, $fl, $vl , "" ); # send a pm to the user about the trophy include_once("send_pm_message.php"); $game = getGameDetails($game_id); $msgSub = "Grats! You just got a trophy!"; $message = "Grats! You got the ".$trophy["toon_name"]." trophy for the ".$game["game_name"]." game!<br> <img src=\"{$game['path']}\">"; //echo $message; //echo "<br><hr><br>"; sendMessage($user_id, 0, 0, $msgSub, $message, 1); sendMessage(2034, $user_id, 0, $msgSub, $message, 1); } } return $insertid; } }//end function function getCeiling($game_id) { $sql = "SELECT ceiling FROM tbl_game WHERE game_id = '".$game_id."'"; $rs = mysql_query($sql); $result = mysql_fetch_assoc($rs); return $result['ceiling']; } function isAlreadyTrophyOwner($user_id, $game_id) { $sql = "SELECT * FROM tbl_trophy_award WHERE game_id = {$game_id} and userid = {$user_id}"; $rs = mysql_query($sql); $num_rows = 0; $num_rows = mysql_num_rows($rs); if($num_rows > 0) { return $num_rows; } else { return $num_rows; } } # calculate game ratio function calculatePointRatio($game_id, $game_score){ //return $game_score; $sql = "select gs.* from arcade_game_setting as gs where gs.game_id={$game_id}"; $rs = mysql_query($sql) or die( "Invalid query". mysql_error() ); if($rs){ $row = mysql_fetch_array($rs); switch($row["calculation_type"]){ case "divide": $x_score = round($game_score / $row["r_no"]); break; case "multiply": $x_score = round($game_score * $row["r_no"]); break; default : $x_score = ceil($game_score); break; }//switch $row["r_no"]; if($row["game_cap"] > 0){ if($x_score > $row["game_cap"]){ $x_score = $row["game_cap"]; } } return $x_score; }//if }// end function # get user total plays function getUserMaxPlaysLimit($user_id, $game_id){ global $d_start_time, $d_end_time; $sql = "select * from tbl_arcade_game_score where user_id={$user_id} and game_id={$game_id} and play_date between {$d_start_time} and {$d_end_time}"; $rs = mysql_query($sql) or die("Invalid query :". mysql_error() ); if($rs){ return mysql_num_rows($rs); }//if } # get game details function getGameDetails($game_id){ $sql = "select g.game_id, g.game_name, g.award_ctoonid, c.toon_name, c.toon_cat, c.toon_subcat, c.toon_small_img from tbl_game as g, tbl_ctoon as c where g.game_id = {$game_id} and g.award_ctoonid=c.ctoon_id"; $rs = mysql_query($sql); if($rs){ $row = mysql_fetch_array($rs); if($row['toon_cat']!="" && $row['toon_subcat']!=0) $tpth="imgtoon/".$row['toon_cat']."/".$row['toon_subcat']."/thumb"; elseif($row['toon_cat']!="" && $row['toon_subcat']==0) $tpth="imgtoon/".$row['toon_cat']."/thumb"; $game["game_name"] = $row["game_name"]; $game["award_ctoon_id"] = $row["award_ctoonid"]; $game["toon_name"] = $row["toon_name"]; $game["path"] = SITEROOT ."/" . $tpth ."/" . $row["toon_small_img"]; return $game; } else { return false; } } # send pm message to winner function sendPMToWinner($user_id, $game_id, $game_score){ include_once("send_pm_message.php"); $g = $game_id; //$point_prize = calculatePointRatio($game_id, $game_score); $point_prize = $game_score; $game = getGameDetails($game_id); //# select ctoon //$sql = "select award_ctoonid from tbl_game where game_id=".$g; //$rsctoon = mysql_query($sql) or die("Invalid query: {$sql} - ". mysql_error()); //$row_ctoon = mysql_fetch_array($rsctoon); //$ctoon_id = $row_ctoon["award_ctoonid"]; //# award ctoon //$insert_user_ctoon = "insert into tbl_users_ctoons (usrid, ctoon_id, del_status, ctoons_auction, auction_id, location, batpts) //values('{$user_id}', '{$ctoon_id}', '0', '', '', '1', '0')"; //mysql_query($insert_user_ctoon) or die("Invalid insert query:".mysql_error() ); //# update points $update_points_sql = "update tbl_users set points_gained = (points_gained+1500) where usrid={$user_id}"; mysql_query($update_points_sql) or die("Invalid updates points query". mysql_error() ); $dbObj = new database(); $msgSub = "Grats! You got a Top Score for ".$game["game_name"]." !"; $message = "Grats! You had one of the Top 10 scores in the ".$game["game_name"]." game last month, and got a 1500 point bonus!<br>"; //<img src=\"{$game['path']}\">"; // echo $message; // echo "<br><hr><br>"; sendMessage($user_id, 0, 0, $msgSub, $message, 1); } /** * function getTrophy( $game_id ) * @param $game_id */ function getTrophy( $game_id ){ $sql = "select award_ctoonid from tbl_game where game_id=".$game_id; $rs = mysql_query( $sql ) or die( mysql_error() ); if( $rs ){ $row = mysql_fetch_assoc( $rs ); } return $row["award_ctoonid"]; } // Updated function from above // Will get more information about the trophy function getTrophyDetails($game_id) { $sql = "select b.ctoon_id,b.toon_name,b.toon_small_img from tbl_game as a,tbl_ctoon as b where a.game_id = '$game_id' and b.ctoon_id = a.award_ctoonid LIMIT 1"; $rs = mysql_query( $sql ) or die( mysql_error() ); if( $rs ){ $row = mysql_fetch_assoc( $rs ); } return $row; } ?> Code: [Select] <?php include_once("Constants.php"); include_once("Database.php"); include_once("SiteSetting.php"); /**************************************************/ # SAVE DONETION IN DATABASE # @param $uid # @param $donation_amt /**************************************************/ function saveDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type){ if($transaction_id != "") { $flag = checkExist($uid); if($flag > 0){ updateDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type); }else{ addDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type); } } } /**************************************************/ /**************************************************/ # CHECK IS RECORD EXITS IN DONETION TABLE # @param $uid /**************************************************/ function checkExist($uid){ $dbObj = new database(); $sql = "select user_id from tbl_donation where user_id={$uid}"; $dbObj->myquery($sql); if($dbObj->row_count > 0){ return $dbObj->f_user_id; }else{ return 0; } } /**************************************************/ /**************************************************/ # INSERT DONETION RECORD IN tbl_donation # @param $uid # @param $donation_amt /**************************************************/ [b]$query = "SELECT arcade_multiplier FROM tbl_point_rewards"; mysql_query($query) or die("Invalid query". mysql_error() ); $result = mysql_fetch_array($result); $arcade_multiplier = $result["arcade_multiplier"];[/b] function addDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type){ $dbObj = new database(); $months = floor($donation_amt / 5); $exp_time = mktime(date("H"),date("i"),date("s"),date("m") + $months,date("d"),date("Y")); $fields = array("transaction_id", "subscr_id", "user_id", "donation_amt", "donation_date", "exp_date", "donation_type", "transaction_details"); $values = array($transaction_id, $subscr_id, $uid, $donation_amt, time(), $exp_time, $type, serialize($_SESSION["recurring_td"])); # update points [b]$update_points_sql = "update tbl_users set points_gained = (points_gained+(($donation_amt / 5) * $donation_pts)) where usrid={$uid}";/[b] mysql_query($update_points_sql) or die("Invalid updates points query". mysql_error() ); if($donation_amt < 5){ // The user donated less than $5 }else{ upgradeAccount($uid); } return $dbObj->cgi("tbl_donation", $fields, $values, false); } /**************************************************/ /**************************************************/ # UPDATE EXISTING DONETION RECORD # @param $uid # @param $donation_amt /**************************************************/ function updateDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type){ if(strlen($subscr_id) > 0){ $cd = " AND subscr_id='".$subscr_id."'"; } $sql_select = "select exp_date, donation_amt from tbl_donation where user_id=".$uid; //$sql_select = "select exp_date, donation_amt from tbl_donation where user_id=".$uid." and donation_type like '%recurring%'"; $rs_select = mysql_query($sql_select) or die("Invalid query".mysql_error()); if($rs_select){ $row = mysql_fetch_array($rs_select); $expdt = $row["exp_date"]; $damt = ($row["donation_amt"] + $donation_amt); $months = floor($donation_amt / 5); $exp_time = mktime(23, 59, 59, date("m",$row["exp_date"]) + $months, date("d", $row["exp_date"]), date("Y", $row["exp_date"])); } $dbObj = new database(); $sql = "update tbl_donation set transaction_id='".$transaction_id."', donation_amt=(donation_amt + {$donation_amt}), donation_date = ".time().", exp_date=".$exp_time.", donation_type='".$type."', transaction_details='".serialize($_SESSION["recurring_td"])."' where user_id={$uid}"; # update points [b]$update_points_sql = "update tbl_users set points_gained = (points_gained+(($donation_amt / 5) * $donation_pts)) where usrid={$uid}";[/b] mysql_query($update_points_sql) or die("Invalid updates points query". mysql_error() ); $dbObj->myquery($sql, 1); if($donation_amt < 5){ // The user donated less than $5 }else{ upgradeAccount($uid); } } /**************************************************/ /**************************************************/ # UPDATE EXISTING RECURRING DONETION RECORD # @param $uid # @param $donation_amt /**************************************************/ function updateRecurringDonetion($subscr_id, $transaction_amt){ $sql_subscr = "select donation_id, transaction_id, user_id from tbl_donation where subscr_id = '".$subscr_id."'"; $rs_subscr = mysql_query($sql_subscr) or die("Invalid query".mysql_error()); if(strlen($rs_subscr) > 0){ $row_subscr = mysql_fetch_assoc($rs_subscr); $uid = $row_subscr["user_id"]; $donation_amt = $transaction_amt; $transaction_id = $row_subscr["transaction_id"]; $subscr_id = $subscr_id; $type = "Recurring"; updateDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type); } } /**************************************************/ /**************************************************/ # UPDATE USER STATUS FROM STANDERED TO PREMIUM # @param $uid /**************************************************/ function upgradeAccount($uid){ $dbObj = new database(); $sql = "UPDATE tbl_users SET acc_type = 'P' WHERE usrid={$uid} LIMIT 1 "; # update points $update_points_sql = "update tbl_users set points_gained = (points_gained+0) where usrid={$uid}"; mysql_query($update_points_sql) or die("Invalid updates points query". mysql_error() ); $dbObj->myquery($sql, 1); }//function upgradeDonation($uid) ?> When I asked about adding a watermark to a video, this was suggested: "when scaling it, I'd do h/5:w/5 (of the source video), then position would be w/20 (5% from the left) and h-h/3 (75% of the way down) When I asked about adding a watermark to a video, this was suggested: "when scaling it, I'd do h/5:w/5 (of the source video), then position would be w/20 (5% from the left) and h-h/3 (75% of the way down)" I'd like to try that, but I don't know how to integrate that into my existing working code: $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "scale=426:-2, overlay=10:10, " -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1'; I've looked at the ffmpeg documentation, but need additional assistance. any help is appreciated
Im trying to add some info to an existing cell in a mysql database. The cell currently reads: This is a piece of information. I would like to update the cell to read: This is a piece of information. a great piece of info. I have a variable with the following; $info = a great piece of info. Is it possible to add $info to the existing cell via php eg. <?php mysql_query("UPDATE mytable SET info = '$info' WHERE row = '$row'"); ?> all fine except I dont want to SET the info to $info I simply want to add $info onto the end of the existing data in the info record. Is this possible and how do i change the above query and go about it? Many thanks Hi, my page is currently up at brewhas.org/transactions.php. When I retrieve a set of results > the defined # per page (such as entering 'WI' for last name), I see the first page correctly, and see the links to next pages, but when I go to the next page there are no results displayed. Same for p.3, etc. So I've looked around enough to know that I need to pass a variable to the subsequent pages, either via a session variable or the URL. I have 2 fields input on the form, as well as a limit and offset. My questions are 1) do I need to pass all 4 and if so then should I use a session variable so the URL does not get too long, and 2) can anyone provide any help with setting session variables and including them to be passed? I'm a newbie and have grabbed some code where I can but this is where i'm stuck. thanks in advance. Code: [Select] <?php include 'config.php'; include 'opendb.php'; $rows_per_page = 20; //Get the values from the text boxes $fnamesearch = $_POST["fnamesearch"]; $lnamesearch = $_POST["lnamesearch"]; //These trim and convert the name fields to upper case. $fnamesearch=strtoupper($fnamesearch); $lnamesearch=strtoupper($lnamesearch); $fnamesearch=trim($fnamesearch); $lnamesearch=trim($lnamesearch); // Count how many rows are coming back for the query //This checks to see if there are at least 2 chars in the last name. if (strlen($lnamesearch)<2) { echo "<p class='style7'>Please enter at least 2 letters of the last name.</p>"; exit; } else //sets the query to get the number of rows { $query = "SELECT COUNT(*) FROM BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%'))"; } $result = mysql_query($query) or die ("Could not execute the query"); //executes the get count query $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; echo "count: ".$numrows; $lastpage = ceil($numrows/$rows_per_page); //determines how many pages based on rows divided by rows per page echo "pages: ".$lastpage; // Get required page number. If not present, default to 1. if (isset($_GET['pageno']) && is_numeric($_GET['pageno'])) {$pageno = $_GET['pageno']; } else {$pageno = 1; } //Checks that the value of $pageno is an integer between 1 and $lastpage. $pageno = (int)$pageno; if ($pageno > $lastpage) {$pageno = $lastpage; } if ($pageno < 1) {$pageno = 1; } //constructs OFFSET for the sql SELECT statement $offset = ($pageno - 1) * $rows_per_page; //This checks to see if there are at least 2 chars in the last name. if (strlen($lnamesearch)<2) { echo "<p class='style7'>Please enter at least 2 letters of the last name.</p>"; exit; } else //sets the query to get the number of rows { $query = "SELECT * FROM BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%')) LIMIT $offset, $rows_per_page"; } $result = mysql_query($query) or die ("Could not execute the query"); //executes the query //Count the number of results $numrows=mysql_num_rows($result); echo "<p class='style7'>Your search: "".$fnamesearch." ".$lnamesearch."" returned <b>".$numrows."</b> results.</p>"; if ($numrows == 0) //if no matches, don't display the table exit; else //build the table and insert rows { echo "<table border=1 cellspacing=0 cellpadding=1 width='77%' align=left bordercolor=#666666>"; echo "<tr bgcolor=#cccc99 class='style5'><th width='10%' class='style5'>Date</th>"; echo "<th width='10%' class='style5'>Action</th>"; echo "<th width='12%' class='style5'>From</th>"; echo "<th width='12%' class='style5'>To</th>"; echo "<th width='5%' class='style5'>Pos</th>"; echo "<th width='18%' class='style5'>Name</th>"; echo "<th width='5%' class='style5'>Round</th></tr>"; while ($row = mysql_fetch_array($result)) { echo "<tr><td width='10%' class='style6'>".$row['TRANS_DT']."</td>"; echo "<td width='10%' class='style6'>".$row['TRANS_ACTION']."</td>"; echo "<td width='12%' class='style6'>".$row['FROM_OWNER']."</td>"; echo "<td width='12%' class='style6'>".$row['TO_OWNER']."</td>"; echo "<td width='5%' class='style6'>".$row['POSITION']."</td>"; echo "<td width='18%' class='style6'>".$row['PLAYER_FNAME']." ".$row['PLAYER_LNAME']."</td>"; echo "<td width='5%' class='style6'>".$row['DRAFT_RND']."</td></tr>"; } /****** build the pagination links ******/ // if not on page 1, don't show back links if ($pageno > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'><<</a> "; // get previous page num $prevpage = $pageno - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'><</a> "; } // range of num links to show $range = 3; // loop to show links to range of pages around current page for ($x = ($pageno - $range); $x < (($pageno + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $lastpage)) { // if we're on current page... if ($x == $pageno) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$x'>$x</a> "; } // end else } // end if } // if not on last page, show forward and last page links if ($pageno != $lastpage) { // get next page $nextpage = $pageno + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>>></a> "; } // end if /****** end build pagination links ******/ echo "</table>"; } mysql_free_result($result); //release the result set from the table mysql_close($conn); //close the connection to the db ?> MOD EDIT: [code] . . . [/code] tags added. Need help to correct my cording! I want to limited search results by 5 items on one page.
Don't know how correctly to add limit: "limit $page1,5".
When I add it: $sql = "SELECT * FROM data GROUP BY city ORDER BY city limit $page1,5";
it doesn't limit searching result by pages.
Attached Files
search3.php 1.67KB
5 downloads soory guys .. actually i am trying to add pagination in script.. but its not pagging.
but when i tried without isset($_get the code worked fine and then i tried to doing with isset($_get for a perticular cat
but its not working. can someone see my code and tell me whats worng i have done.
<!DOCTYPE HTML> <html> <head> </head> <body> <?php // include database connection include 'libs/db_connect.php'; // page is the current page, if there's nothing set, default is page 1 $page = isset($_GET['page']) ? $_GET['page'] : 1; // set records or rows of data per page $recordsPerPage = 1; // calculate for the query LIMIT clause $fromRecordNum = ($recordsPerPage * $page) - $recordsPerPage; // select all data $query = "SELECT * FROM posts ORDER BY post_id desc LIMIT {$fromRecordNum}, {$recordsPerPage}"; /* page and its LIMIT clause looks like: 1 = 0, 5 2 = 5,10 3 = 10,15 4 = 15, 20 5 = 20, 25 */ $stmt = $con->prepare( $query ); $stmt->execute(); //this is how to get number of rows returned $num = $stmt->rowCount(); //check if more than 0 record found if($num>0){ $cat=1; if(isset($_GET['cat'])){ $cat_id = $_GET['cat']; $get_posts = "select * from posts where category_id = '$cat_id'"; $run_posts = mysql_query($get_posts); while($row_posts = mysql_fetch_array($run_posts)){ $post_id = $row_posts['post_id']; $post_title = $row_posts['post_title']; $post_date = $row_posts['post_date']; $post_author = $row_posts['post_author']; $post_image = $row_posts['image']; $post_content = substr($row_posts['post_content'],0,80); echo " <div class='post_area'> <h4> <a href = 'details.php?post=$post_id'>$post_title</a> </h4> <div class='date'><div id='com'> Date</div>$post_date</div><span style='font-size:12px'><i style='color:grey;font-size:10px'>Posted By</i> </b>$post_author</span> <content><img src = '123dondadatest/news_images/$post_image' width = '100' height='100'/> <div>$post_content <br/><a id='rmlink' href = 'details.php?post=$post_id'> Read More...</a></div><br /><br/><br/><br/> </div> "; } } // *************** <PAGING_SECTION> *************** echo "<div id='paging'>"; // ***** for 'first' and 'previous' pages if($page>1){ // ********** show the first page echo "<a href='" . $_SERVER['PHP_SELF'] . "' title='Go to the first page.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> << </span>"; echo "</a>"; // ********** show the previous page $prev_page = $page - 1; echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$prev_page}' title='Previous page is {$prev_page}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> < </span>"; echo "</a>"; } // ********** show the number paging // find out total pages $query = "SELECT COUNT(*) as total_rows FROM posts"; $stmt = $con->prepare( $query ); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $total_rows = $row['total_rows']; $total_pages = ceil($total_rows / $recordsPerPage); // range of num links to show $range = 2; // display links to 'range of pages' around 'current page' $initial_num = $page - $range; $condition_limit_num = ($page + $range) + 1; for ($x=$initial_num; $x<$condition_limit_num; $x++) { // be sure '$x is greater than 0' AND 'less than or equal to the $total_pages' if (($x > 0) && ($x <= $total_pages)) { // current page if ($x == $page) { echo "<span class='customBtn' style='background:red;'>$x</span>"; } // not current page else { echo " <a href='{$_SERVER['PHP_SELF']}?page=$x' class='customBtn'>$x</a> "; } } } // ***** for 'next' and 'last' pages if($page<$total_pages){ // ********** show the next page $next_page = $page + 1; echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$next_page}' title='Next page is {$next_page}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> > </span>"; echo "</a>"; // ********** show the last page echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$total_pages}' title='Last page is {$total_pages}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> >> </span>"; echo "</a>"; } echo "</div>"; // ***** allow user to enter page number echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='GET'>"; echo "Go to page: "; echo "<input type='text' name='page' size='1' />"; echo "<input type='submit' value='Go' class='customBtn' />"; echo "</form>"; // *************** </PAGING_SECTION> *************** } // tell the user if no records were found else{ echo "<div class='noneFound'>No records found.</div>"; } ?> </body> </html> Hello everyone, I am not a php programmer, but I would like to solve a problem regarding math with PHP. I was looking around on the web on how to add (in this case digits) using PHP. I found out that adding two strings using a . I can then echo out the results; so far so good. My question however is as follow. How do I add up information from multiple pages? Let's say on one page (let's call it weekly.php) I have my weekly expenses of $300, and on the second page (let's call it monthly.php) I have my monthly expenses of $1400. I would like the result (weekly + monthly) to be displayed (echo'ed out) on the third page (let's call it totalamount.php). I don't want to take advantage of anyone's time, so I am not asking for the entire solution (code) unless you want to , but I would be just happy to be pointed in the right direction, I will do the rest on my own. Thank you very much for your time. Cheers, Luigi This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=354302.0 Hi there, I'm trying to get the full Product Name in the <title> of each of the product pages - I can't seem to figure out what to put in the product_info.php... I've tried a few different options but I'm not great with php Here's what I have currently but it creates errors... <script language="javascript"><!-- document.write('<title><?php echo TITLE; ?> : <?php echo $product_info['products_name']; ?> </title>'); //--></script> Hope someone can help - thanks so much! I cant get my head around this. I m trying to add product attributes into this script. I have products tables and product_extras product.id and product_extras.id are same. How can I add this to cart. Is there any easy way to do this. Any help would be much appreciated! Quote cart.php Code: [Select] <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>products</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="contents"> <h1>Please check quantities...</h1> <?php echo showCart(); ?> <p><a href="index.php">Back to products...</a></p> </div> </body> </html> Quote functions.php Code: [Select] <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM products WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$title.'</td>'; $output[] = '<td>£'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>£'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> My table looks like this.. `guns_id` int(255) NOT NULL auto_increment, `guns_name` varchar(255) collate latin1_general_ci NOT NULL, `guns_price` int(255) NOT NULL, PRIMARY KEY (`guns_id`) I want to add a product key that is unique through out the whole database as I have other products other than guns aswell. |