PHP - Previous, And Next Record (when Not Ordered By Id)
SQL is made up below, but I have something similar sorted by dates, and NOT by ID. Currently I get this done by getting all the ID's in an array ordered by date and gleaning the two record ID's from that array. if the table is huge, that might not be the best way. Just seems like there should be an easier way to do it. Any ideas? Select startrek.ID, optc.opt_value as trk_series_id, optc.ID as trk_series_idID, startrek.trk_title, startrek.trk_episode, startrek.trk_season, startrek.trk_airdate, startrek.trk_stardate FROM startrek JOIN opt optc ON optc.ID = startrek.trk_series_id ORDER BY trk_airdate ASC
Similar TutorialsDear All I am seriously stuck up I am displaying a products for shoppoing cart (using MYSQL and PHP) then clicking on a product displaying thir more images and allow to specify qty rquired (for Shoppng cart) How can dislay prevous and next record of the product ( i believe i ned to remember query defied for previous page but i ma not clear how to display current record and previous record and next record ... I want to display previous and next based on query reun Alright I didn't really know what to name the thread but w/e. I'm working on writing a blog, just for the purpose of something to apply what I'm learning it's not for production. I need someone to point me in the general direction of how the front page would look where after a post is made its on top and the older posts are below it: -- new post -- old post -- old post I don't want the code just a general direction of how I should go about it. Thanks much. I have several forms which will request the user to select one of several options where the most common choices will be pronounced, and might look something like: Select Option A Select Option B Select Option C Select Option D Click here for more choicesThe client is responsible to determine which ones to display (opposed to hiding within "more choices") and the server is responsible to provide the list of options along with some means to determine which ones are most common. For a new user, the order will be based on my "best guess", however, whenever a user selects a given option its ranking for that user only should go up, and in addition more recent activities should have more bearing on the returned order. In addition, there will be more than one of these lists and each of these lists will expose a public identifier (most will use a string but some might use an incrementing integer series) instead of the primary key. I have some fragmented ideas how to best implement but would like other people's thoughts on how to best do so. Starting with the list schema, undecided on which approach below. Any preferences or something else altogether? Solution 1: abstract_list - id (INT PK) - discriminator (string) - name (string unique with discriminator) - ranking (TBD whether float or integer. This represents my initial "best guess") list1 (list2, etc) - id (FK to abstract_list.id) - discriminator (FK to abstract_list.discriminator) - public_id (string or integer based on specific list. unique with discriminator) Solution 2: abstract_list - id (INT PK) - discriminator (string) - name (string unique with discriminator) - ranking (TBD whether float or integer. This represents my initial "best guess") - public_id (Application responsible to cast as string or integer. unique with discriminator) list1 (list2, etc. This class has no properties and only a method to cast the public ID as required. Seems like a waste...) - id (FK to abstract_list.id)
user_list_ranking - abstract_list_id - user_id - ranking (TBD) To retrieve the list options, will query abstract_list and LEFT JOIN user_list_ranking and then sort on some mathematical formula acting on abstract_list.ranking and COALESCE(user_list_ranking.ranking, 0). To promote recent activity, maybe increment user_list_ranking.ranking every time the user selects a given option and also decrement all other options of the associated list. To prevent excessive windup, cap the the value to some max value (i.e. If list1 has a total of 10 records, cap it three times that value resulting in 30), and cap the minimum at zero. Uncharted territory here and am very open to other approaches. I am undecided whether I should just return an ordered array of the options, or also include either an order integer or some normalized value from 0 to 1. If there is a common way to do this, please let me know what it is so I may mimic it. If not, please provide any critique or recommended changes to my intended approach. Thanks Basically I am setting up my own cricket management game, but there are 3 areas that I am slightly stuck on and would appreciate help: 1) When a use registers, I need to create 11 players for their team. For this, I am going to have one text files with first names and one text file with surnames. How can I open each file and select a name and then match them together? 2) I need to create the list of games to be executed at particular times through a cron job. How can I go through all the teams in a table and match them together in games, ensuring everyone plays everyone? If a new player registers, he will be put into a random league and so the games for that league will have to be redone 3) How can I set up a cron job to execute the above games? Each team should play once a day and so if there are 24 teams in a table, there will be 12 games that occur through this cron job. I assume cron jobs are the best thing for this. Any help would be appreciated. Thanks. I'm trying to create a function where you specify the $points it will then do some mathematical stuff with the $points (explain later) an return an array containing the $rank and $level. The mathematical stuff: It starts at 99 and when it reaches +199 it changes the key of the array. I'm not sure how to describe this theirfore i'll just provide examples: Example 1: If $points <= 99 It will return an array containing $ranks[0] and $levels[0], would be the following: return array('Peon', 0); Example 2: If $points >= 100 && $points <= 299 It will return an array containing $ranks[1] and $levels[1], would be the following: return array('Grunt', 1); Example 3: If $points >= 300 && $points <= 499 It will return an array containing $ranks[2] and $levels[2], would be the following: return array('Berserker', 2); etc.. until it reaches the 7th key of the $ranks/$levels array Heres my code: <?php function rank($points){ //their are 0-7 levels $levels = range(0, 7); //7 ranks $ranks = array('Peon', 'Grunt', 'Berserker', 'Tauren', 'Spirit Walker', 'Wind Rider'); for(...) { return array($rank, $level); } } ?> PHP script return 20 UL LIST values like, < ul >
A < /ul > How to display UL LIST into row wise 5 columns like
A B C D Hi all, I have a fairly simple problem, but i cannot get to it. I have a page, that displays one (1) record at the time, and I want to have forward and back buttons (links) at the top and bottom of the page. Can anyone help me with that??? Here is a part of my code. Code: [Select] <form method="get"> <table border="0" width="90%" cellpadding="2" cellspacing="2" align="center"> <tr><td align="center"> Select first letter or kind of the story: <input type="hidden" name="link" value="stories.php"> <input type="hidden" name="Pripadnost" value="3"> <select name="letter" onchange="this.form.submit()"> <?PHP $letter = trim($_REQUEST["letter"]); ?> <option value="Sve" <?PHP echo $letter == "All" ? " selected " : "" ; ?>>All</option> <?PHP include_once ("/includes/databaseMySQL.php"); mysql_set_charset('utf8'); $SQL = "Select distinct ucase(left(title,1)) as sl FROM tblStoryes order by sl"; $rs_data = mysql_query($SQL) or die(mysql_error()); while ($row_data = mysql_fetch_assoc($rs_data)) { ?> <option value="<?PHP echo $row_data["sl"]; ?>"<?PHP echo $letter == $row_data["sl"] ? " selected " : "" ; echo ">".$row_data["sl"] ;?></option> <?PHP // ****************** Listed all the first letters of the titles into a drop box. *********************** // } ?> </select> Bosnian <input type="checkbox" name="Bosnian " <?PHP echo isset($_REQUEST["Bosnian "]) ? "checked=checked" : "" ;?> onclick="this.form.submit()" /> Turkish <input type="checkbox" name="Turkish " <?PHP echo isset($_REQUEST["Turkish "]) ? "checked=checked" : "" ;?> onclick="this.form.submit()" /> Arabian <input type="checkbox" name="Arabian " <?PHP echo isset($_REQUEST["Arabian "]) ? "checked=checked" : "" ;?> onclick="this.form.submit()" /> </td></tr> </table> <table border="0" width="90%" cellpadding="2" cellspacing="2" align="center"> <?PHP $id = -1; $rs_data = mysql_query("Select max(id) as maxid from tblStories WHERE aktivno = True") or die(mysql_error()); $row_data = mysql_fetch_assoc($rs_data); $maxid = (int) $row_data["maxid"]; // ****************** Found the largest ID from the table. *********************** // $SQL = "SELECT * FROM tblStories WHERE aktivno = True "; if ( strlen($letter) < 3 && strlen($letter) > 0 ) { $SQL = $SQL . " and ucase(left(`title`, 1)) = '" . $Letter . "'"; } $lang = 0; $lang = $lang + isset($_REQUEST["Bosnian"]) * 4; $lang = $lang + isset($_REQUEST["Turkish"] ) * 2; $lang = $lang + isset($_REQUEST["Arabian"] ); switch ($lang) { case 6: // bos i tur $SQL = $SQL . " and ( Bosanski = 1 or Turski = 1 ) "; break; case 5: // bos i ar $SQL = $SQL . " and ( Bosanski = 1 or Arapski = 1) "; break; case 4: // bos $SQL = $SQL . " and Bosanski = 1 "; break; case 3: // tur i ar $SQL = $SQL . " and ( Turski = 1 or Arapski =1) "; break; case 2: // tur $SQL = $SQL . " and Turski = 1 "; break; case 1: // ar $SQL = $SQL . " and Arapski =1 "; break; } if (trim($_REQUEST["DBid"]) <> "" or $_REQUEST["DBid"] > 0) $SQL = $SQL . " and id > " . trim($_REQUEST["DBid"]) ; $SQL = $SQL . " LIMIT 1"; //order by naslov $rs_data = mysql_query($SQL) or die(mysql_error()); echo "<!--" . $SQL . " : Jezik je:" . $lang . "-->"; while ($row_data = mysql_fetch_assoc($rs_data)) { $id = (int) $row_data["ID"]; ?> <tr> <td align="center" colspan=3> <h3><?PHP echo $row_data["Title"];?> </h3> </td> </tr> <tr> <td width=20%> </td> <td align="justify" width=60%> <?PHP echo $row_data["tekst"]; // tekst = text, but not keyword ?> </td> <td width=20%> </td> </tr> <?PHP } ?> </table> <p> <?PHP // ****************************** HEEEEELLLLPPPPPP ******************************* // ?> <table border="0" width="90%" cellpadding="1" align="center"> <tr> <td align="center"><a href="?DBid=1<?PHP foreach($_REQUEST as $arr => $elem){ if ( $arr != "DBid") echo "&" . $arr . "=" . $elem; } ?>"> <<</a></td> <td align="center"><a href="?DBid=<?PHP echo $_REQUEST["id"]; foreach($_REQUEST as $arr => $elem){ if ( $arr != "DBid") echo "&" . $arr . "=" . $elem; } ?>" ><</a></td> <?PHP if ( $maxid <= $id ) { ?> <td align="center">></td> <td align="center">>></td> <?PHP } else {?> <td align="center"><a href="?DBid=<?PHP echo $id ; foreach($_REQUEST as $arr => $elem){ if ($arr != "DBid") echo "&" . $arr . "=" . $elem; } ?>">></a></td> <?PHP if ( ($id + 9) < $maxid ) { ?> <td align="center"><a href="?DBid=<?PHP echo $id+10 ; foreach($_REQUEST as $arr => $elem){ if ($arr != "DBid") echo "&" . $arr . "=" . $elem; } ?>">>></a></td> <?PHP } else {?> <td align="center">>></td> <?PHP }?> <?PHP }?> </tr> </table> </form> I have rows being generated in a foreach loop. I need to find the time in the row before it (or maybe after it if my logic is screwed up) to see if the times are equal. If they are equal, I need to see if the next row after that is equal. If it is not equal then stop. mysql user id time action 1 5 bought 1 5 purchased 1 5 sold 1 4 created Code: [Select] foreach($newsfeed as $k => $news) { if ($news['time'] == $news['time'] of $k--) { echo " you bought purchased and created"; } else { echo $news['action']; } } How can I get the next four and previous four rows? Here is what I have and it isn't working at at all. $q1 = Mysql::query("SELECT id, file, dir FROM photos WHERE id > $id AND album = '$al' ORDER BY id ASC LIMIT 4"); $q2 = Mysql::query("SELECT id, file, dir FROM photos WHERE id < $id AND album = '$al' ORDER BY id DESC LIMIT 4"); Is there a way to take data that is listed like a,b,c,d,e and turn that into an unordered list? Basically, I'm going to have a list of schools that will be listed with comma separators. I'll print that data out in two places, one will be printed as it's in the database. The other I would like to echo as an unordered list. Hi all, Anyone give me a few hints how I can add a next and previous button to my pagination links? I currently have this: <?php } if($total_records > 5) ?> <div id="pg"> <?php { for ($i = 1; $i <= $total_pages; $i++) { echo "<a title='page $i' class='current' href='?catid=" . $catid ."&"; if($subid > 0) { echo "subid="; echo $subid . "&"; } echo "p= $i'>$i</a>"; } } ?> </div> Which displays them nicely, but I would like a next and previous button. Cheers I am trying to create a gallery page, one photo on the page with Next/Previous links either above or below but am having a little local difficulty. This is what I have:- Code: [Select] //>>> Set up arrays and variables <<< $piccies = array(); $exif = array(); $exifdata = array(); $pic = 0; $img =''; $date = ''; $time = ''; $caption = ''; $copyright =''; $imageid = 1; $first = 1; $last = 5; $self = $_SERVER['PHP_SELF'] . "?imageid="; //>>> Read images from folder and assign to the array $piccies[] <<< $piccies = read_folder(); //>>> Find image and extract the Exif info <<< $exif = read_exif_info($piccies, $pic); //>> Populate with required info from $exifdata with required info from $exif $exifdata = populate_exif_data($exif, $date, $time); $img = substr_replace($img, "", 0, 2); ?> <div id="pict"> <img src="<?php echo $img; ?>" /> <?php echo "<p>" . $caption . "</p>"; if ($imageid < $last) { echo "<a href=" . $self . ($imageid + 1) . "><h2>Next</h2></a>"; } if ($imageid > $first) { echo "<a href=" . $self . ($imageid - 1) . "><h2>Previous</h2></a>"; } ?> </div> It puts the 'Next' link in fine, but when clicked the link goes to the Parent directory:- Index of /php/gallery [ICO] Name Last modified Size Description [DIR] Parent Directory - [ ] functions.php 27-Oct-2011 09:25 2.1K [ ] gallery index.php 27-Oct-2011 09:45 1.8K [DIR] images/ 26-Oct-2011 16:00 - and when I look at the source I see that the link has not been constructed as I expected. This is the source:- Code: [Select] <div id="pict"> <img src="images/blue sky.jpg" /> <p>Blue Sky over Auld Reekie</p><a href=/php/gallery test.php?imageid=2><h2>Next</h2></a></div> where '/php/gallery test.php' is showing I expected 'images/filename.jpg' etc. and I just can't figureout what I have done wrong...
I want to list the previous (minus) 10 records. echo $rs['tree'];
} Thanks... Hi , i read many articles and tried many things before asking but i came to a dead end. My problem is very simple (or at least i believe so).
In the main directory \httpdocs there is this file we call "header.php" and another file we call "article.php".
So the code of the article is very simple:
<?php include("header.php"); echo "bla bla bla\n"; ?> I messed around with a simple pagination script I found online. I'm still diving in and breaking it down to try and understand it better but I also was planning to have a "next" and "previous" link instead of just echoing out page numbers. I know I'll have to come up with some $pg+1 or $pg-1 function but how do I find out what $pg is currently on? function showSubmissions(){ $max = 9; // number of news entries per page $pg = $_GET['pg']; if(empty($pg)) { $pg = 1; } $limits = ($pg - 1) * $max; //view all the news articles in rows $q = mysql_query("SELECT * FROM submissions WHERE approved='YES' ORDER BY postdate DESC LIMIT " . $limits . ", $max") or die(mysql_error()); //the total rows in the table $totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM submissions"), 0); //the total number of pages (calculated result), math stuff... $totalpages = ceil($totalres / $max); // BEGIN PAGINATION print ' <div class="paginationList"> <ul class="pgList"> <li><img src="images/icon_prevresult.png" title="" alt="" /></li>'; for($i = 1; $i <= $totalpages; $i++) { //this is the pagination link print '<li><a href="submissions.php?pg=' . $i . '">' . $i . ' </a></li>'; } print ' <li><img src="images/icon_nextresult.png" title="" alt="" /></li> </ul> </div>'; // END PAGINATION // PRINT RESULTS while($row = mysql_fetch_array($q)) { $id = $row['id']; $name = stripslashes($row['name']); $email = $row['email']; print ' <div class="sub-thumb-wrapper"> <div class="sub-thumb-user"> <div class="ps-name"><p class="sub-label">NAME:</p><a href="mailto:' . $email . '">' . $name . '</a></div> </div> </div>' . "\n"; } // END PRINT RESULTS } I'm not sure if this is a pure mySQL question or if it's more PHP but I thought this seemed like a good place to ask it.
I have a table which has data stored into it twice daily. The data stored is the timestamp, an account_ID, and the number of followers.
I am trying to add another field of "gains_losses". This should look at the previous entry for that account_ID, find out the followers data, and then find out the difference between the data being submitted today.
How would you go about doing this? I'm a bit stuck because I can't do it based on the date previously, and the times can change so I can't do a search for "Where time = this minus one day".
Here's a screenie of the table, you can see the account_ID repeats often as these are entries for each of these accounts.
I've got a page that displays all my blog entries on a single page. When you click on a specific entry, it pulls the post ID and loads the page specifically. From there, I wanted to have the option to click either onto the next or previous post by finding the next or previous ID in the database.. however, I know that sometimes posts are deleted, etc. so the ID's won't exactly be in order. What direction should I take with this? I'm trying to figure out how to filter the results of a database query. For example somebody uses a php/javascript form to search for ford cars. When they see 100 results, they then narrow the results by model and/or color. Am I right in thinking that the way to do this is by creating a temporary table of the results? What is the best approach to what I'm trying to do? Hi guyz, I have created an event calender with PHP for customer appointments (calender.php). It is very basic and simple were all the days in the month are clickable; click on the day and you are redirected to diary page (diary.php) to view the appointments for that day. At the moment after the user is done looking at appointment and want to view another, they have to go back to the calender.php page for the next/previous day. I would like a previous and next button (Like the calender on MS Outlook) on the (diary.php page) so I don't have to keep going back to the calender.php page to go to the next or previous day. Please guys help me out, I realise it is quite complicated so any suggestions, ideas, or even if you have a similar script to see how you did it would be much appreciated and very helpful. Thanks guys! |