PHP - Need Help With Page Numbers
Hello everyone, i am working on a page that displays news topic and would like to have the page numbers at the bottom of the page as links. You know the usual prev (link) then list couple of pages and then next (link).
prev - 1 2 3 4 5... next below is the code i have to count my records on my db and display them. but the problem with this is that it displays all of them. page 1 through 50. Code: [Select] $query2 = "SELECT COUNT(title) FROM news"; $result2 = mysql_query($query2); $row = mysql_fetch_row($result2); $total_records=$row[0]; $total_pages = ceil($total_records / 5); for ($i=1; $i<=$total_pages; $i++) { if ($i!=1 and $i !=10) { print "<a href='newsevents.php?page={$i}'> " .$i. " </a>"; } if ($i==$total_pages) { print"<p><a href='newsevents.php?page={$i}'> Last Page </a>"; } if ($i==1) { print "<p class='floatleft'><a href='newsevents.php?page={$i}'> First Page </a>"; } } Can someone help? Similar TutorialsHi, somehow iv managed to add pagination to my project, but im struggling with one thing - i dont know how to move the pagination "symbols" (idk how they r called).. here's a pic that will explain what im talking about: and heres the code that im using: //The directory to your images folder, with trailing slash $dir = "uploads/thumbs/watermarkedthumbs/"; //Set the extensions you want to load, seperate by a comma. $extensions = "jpeg,jpg"; //Set the number of images you want to display per page $imagesPerPage = 4; //Set the $page variable if(!isset($_GET['page'])){ $page = 1; }else{ $page = $_GET['page']; } //Load all images into an array $images = glob($dir."*.{".$extensions."}", GLOB_BRACE); //Count the number of images $totalImages = count($images); //Get the total pages $totalPages = ceil($totalImages / $imagesPerPage); //Make sure the page you are on is not greater then the total pages available. if($page > $totalPages){ //Set the currnet page to the total pages. $page = $totalPages; } //Now find where to start the loading from $from = ($page * $imagesPerPage) - $imagesPerPage; //Now start looping for($i = $from; $i < ($from + $imagesPerPage); $i++){ //We need to make sure that its within the range of totalImages. if($i < $totalImages){ //Now we can display the image! echo "<img style='border:thin solid #FFF;margin-top:10px;margin-left:10px;margin-right:10px' src='{$images[$i]}'alt='{$images[$i]}' />"; } } //Now to display the page numbers! for($p = 1; $p <= $totalPages; $p++){ if($p == $page){ $tmp_pages[] = "<strong>{$p}</strong>"; }else{ $tmp_pages[] = "<a href='?page={$p}'>{$p}</a>"; } } //Now display pages, seperated by a hyphon. echo "<br />" . implode(" - ", $tmp_pages); ?> how do i move the 'page numbers' ? thanks in advance Hi iam currently writing some code for my website and i have a number of records that i simply want to display in a table format, i have done this in a while loop and it works well, however i only want to display a maximum of 10 records per page as my div needs to be a fixed height and was wondering how i could include a next button that would act as like a page number. The thing is at any given point there could be from 1 record to display to 500, so i need a way of allowing the user to quickly navigate to the other records. How can i do this without using mulitple pages. Hope this makes sense. Heres my code Code: [Select] <?php echo"<table width='100%' border='1' align='center'><tr><th>Referal Name</th><th>Amount Received</tr>"; while ($row = mysql_fetch_array($sql_info)) { extract($row); echo "<tr><td align='center'>".$username."</td><td align='center'>".$cumulative_referral."</td></tr>"; } echo "</table>"; ?> Thanks for your help Hi, I need to sort variables in groups of up to 15 and put it in an array. For example: $exstract['center_tabOpBody_0'] =5 $exstract['center_tabOpBody_1'] =6 $exstract['center_tabOpBody_2'] =8 $exstract['center_tabOpBody_3'] =1 Should yield: ARRAY( = center_tabOpBody_1,center_tabOpBody_2,center_tabOpBody_3 // <-----15 [1] = center_tabOpBody_0 //<----5 ) Is there some simple function do do the "efficiency" sort? Thanks, Vadim can you have something like.. echo $whatever; this putput 1.2 can you split this number so the first integer will be in $val"(1)" or whatever and the second integer after the "." will be in $val2"(2)" i have a price i want to add 10%-15% to the base price and that the result will be rounded to 9 in the ones digit place. for example 85 +15%=97.7 $result=99 117+15%=134.55 $result = 139 played with round() and ceil() Hi Guys
I have a regex conundrum that at first I thought would be very easy but then appears to be quite hard :/
I want to match a string with a regex where the regex can only pass if it contains letters and numbers (nothing else) and it has to contain at least one of each.
I've been trying out lookaheads but just can't get it right.
Any help is appreciated.
Drongo
Hello Guys, I have a var for height like $height="67" and want to be able to split that number into, so that I can display 6 feet 7 inches but I have not figured out how to do it.. Please advise.. This is the current code I am working with but doesn't work. The problem is that explode won't work without some type of separator. Code: [Select] $height2 = explode(" ", $height); echo "This is feet". $height2[0] ."<br>"; echo "This is inches". $height2[1]. "<br>"; Hello, Example X = 50 I have been trying to find a way so that I can loop a foreach to insert into a database X and every other number below X unless X already exists. is this possible? -John Sorry if this has already been solved. Also, I apologize if this is an amateur question... I have a simple form and a script to do some validating of user data, among other tasks. One part of the script is intended to verify a birthday. Code: [Select] $x = $_POST['x']; $x = trim($x); According to the php.net manual, trim() is supposed to remove whitespace before and after a string. My intent by using trim() is to determine if someone tried to skip the birthday field. I have other validation running on the value of $x, but I wanted trim() to remove whitespace. However, the value of x, which in this case is expected to be numeric, such as 12 for a month, ends up being 1. This happens with any 2-digit number that a user might enter into the form field for x. The second number is always removed. Any insight into why trim() removes the second number, 2 in the above example, leaving only a "1" as the value of $x, would be very greatly appreciated. Thanks in advance. if (preg_match($fname [0-9])) { echo "invalid FirstName"; } want the user to only be able to enter letters this is the code i have assuming that preg_match will spot any number in the $fname field and print "invalid firstname" if the user entered a number. how can i get the users to only insert letters? I need to be able to add all the numbers together collected from the database with mysql_fectch_array Code: [Select] public function gradeQuery(){ $id = $this->idQuery(); $sql = "SELECT*FROM grades WHERE moviesID = '$id'"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $num_rows = mysql_num_rows($result); } Hi i got an error. I cant get $new_score and $new_played variables. $name = $_POST["name"]; $score = $_POST["score"]; $result = mysql_query("SELECT * FROM taure_lentele WHERE name='$name'"); $row = mysql_fetch_array($result); if(mysql_num_rows(mysql_query("SELECT name FROM taure_lentele WHERE name='$name'") ) == 1 ) { $old_score = $row['score']; $score + $old_score = $new_score; $old_played = $row['played']; $new_played = $old_played++; mysql_query("DELETE FROM taure_lentele WHERE name='$name'"); mysql_query("insert into `taure_lentele` set `name` = '$name', `score` = '$new_score', `played` = '$new_played"); } This is my current script <?php $iFile = "accounts.txt"; //Put your list lagger's info in this txt file in the same directory as this script. Format is UserID(space)AuthKey $login = file($iFile, FILE_SKIP_EMPTY_LINES); if(!is_file($iFile)) echo "The logins file couldn't be found...".sleep(999999); foreach($login as $line_num => $line) { $login = explode(" ", htmlspecialchars(str_replace(" "," ",$line))); //////////////// ////////////// /////////// ///////// if(stristr($login[1], "\n")) $login[1] = substr($login[1], 0, strlen($login[1])-2); $MobLink = "http://mobsters-fb-apache-dynamic-lb.playdom.com/mob_fb/"; $RefreshStat = file_get_contents($MobLink."refresh_stat?user_id=".$login[1]."&auth_key=".$login[0]); $Mob_Name = explode("<mob_name>", $RefreshStat); $Mob_Name = explode("<", $Mob_Name[1]); $Name = $Mob_Name[0]; $Cash = explode("<cash>", $RefreshStat); $Cash = explode("<", $Cash[1]); $CurrentCash = $Cash[0]; echo $Name."-$".number_format($CurrentCash)." - ".$login[1]."\n"; } sleep(99999); ?> The Script runs through for 100 different accounts, is it possible to add all the Cash values that get echo'd? is this a proper way of entering this? Code: [Select] $result = mysql_query("SELECT * FROM jobs WHERE id2 >= '$startdate' AND id2 < '$enddate' ORDER BY id"); How I can format the number in a string to be displayed as four-digit. I mean transforming 1 to 0001; and 54 to 0054. I have a cards array, and I have this function which will shuffle the cards for me. How can I edit this to 'deal' 12cards (6 & 6) until all the cards are a specific 6 & 6 I pick out? Code: [Select] function ShuffleCards(&$cardsArray, $times) { // Randomizes where to split within center (-3 to +3 from dead center) (MINIMUM 10 CARDS IN DECK) // Splits into two array. Randomizes how many cards from left and how many cards from right (between 1 and 3) // Alternates sides. Continues until both arrays are empty. $arraySize = count($cardsArray); if($arraySize<10) return; $deadCenter = $arraySize/2; for($i=0;$i<$times;$i++) { reset($cardsArray); $cutVariant = rand(-3, 3); $cutLocation = $deadCenter+$cutVariant; $firstArray = array(); $secondArray = array(); for($z=0;$z<$arraySize;$z++) { if($z<$cutLocation) array_push($firstArray, $cardsArray[$z]); else array_push($secondArray, $cardsArray[$z]); } $bottomFirst = rand(0, 1); $cardsArray = array(); while(count($firstArray) && count($secondArray)) { $leftNewCards = array(); $rightNewCards = array(); $leftVariant = rand(1, 3); if($leftVariant>count($firstArray)) $leftVariant = count($firstArray); $rightVariant = rand(1, 3); if($rightVariant>count($secondArray)) $rightVariant = count($secondArray); for($x=0;$x<$leftVariant;$x++) { array_push($leftNewCards, array_shift($firstArray)); } for($y=0;$y<$rightVariant;$y++) { array_push($rightNewCards, array_shift($secondArray)); } if($bottomFirst==0) { $newCardsArray = array_merge($leftNewCards, $rightNewCards); $bottomFirst = 1; } else { $newCardsArray = array_merge($rightNewCards, $leftNewCards); $bottomFirst = 0; } reset($newCardsArray); while(count($newCardsArray)) { array_push($cardsArray, array_shift($newCardsArray)); } } if(count($firstArray)) { while(count($firstArray)) array_push($cardsArray, array_shift($firstArray)); } if(count($secondArray)) { while(count($secondArray)) array_push($cardsArray, array_shift($secondArray)); } } } Working through some beginner stuff and ive copied some code straight out the textbook, word for word yet it produces: Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in C:\wamp\www\PHP Work\StringtoNumbers.php on line 11 <html> <head> <title>Strings Into Numbers</title> </head> <body> <h1>Strings Into Numbers</h1> <ul> <?php $n = "0x237a"; echo "<li>".$n."</li>" echo "<li>".($n * 3)."</li>"; $n2 = "34re5"; echo "<li>".($n2 + 2)."</li>"; $n3 = "boo"; echo "<li>".($n3 + 2)."</li>"; ?> </ul> </body> </html> Hey i'm just woundering how i would echo numbers from a database like 1000000 lets say 1 million how would i go about on echoing it like this 1,000,000 ZhsHero Hey, I have checkbox and with these I am setting an exam. I want the questions to contain numbers. So for each question a number would be displayed. So far I am Only getting the question and the choices to display. <html> <?php session_start(); include '../Database/connection.php'; $Value22 = mysql_real_escape_string(trim($_POST['myselects'])); $_SESSION['myselect23'] = $Value22; //echo $_SESSION['myselect23']; ?> <body> <form action="Staff_Menu.php" method="post"> <?php include '../Database/previous_q.php'; while($info = mysql_fetch_array( $sql )) { echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; } ?> <input type="submit" value="submit"/> </body> </html> </body> </html> Hi ..am new to PHP and am using it to solve some mathematical problems which require extensive computation. Following is a code to solve a problem: Code: [Select] <?php $num =1; $n =0; $temp = 0; $count =0; $Final =0; While( $num < [color=orange]1000000)[/color] { $n = $num; while($n >1) { if(( $n % 2) == 0) { $n = $n/2; $temp++; } else { $n =3*$n +1; $temp++; } } If($temp > $count) { $count =$temp; $Final =$num; } $num++; $temp =0; } echo $Final; echo "<BR>"; echo $count; ?> I am running into "Maximum execution time of 30 seconds exceeded" error...its happening coz of the number 1 million...the code wrks fine for 100,1000,10000 and 100000...but breaks down @ 1000000.....is there any way to solve this situation...or PHP is not capable of handling huge numbers? please help...am stuck with this even though am so close to solving the prob. Thanks Abhijeet |