webmaster1 Posted February 7, 2009 Share Posted February 7, 2009 Hi All, I know how to display records in a php page using a loop. ??? Firstly I'm stuck on the basics of trying to display a single record. ??? Secondly I'd like to set a condition whereby only the next available record is displayed as a single record. <?php //INCLUDE DB CONNECTION INFO include("dbinfo.php"); //CONNECT TO DATABASE mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); //DEFINE QUERY $query="SELECT * FROM tablename where masterdataid =1"; $result=mysql_query($query); $num=mysql_num_rows($result); mysql_close(); //DEFINE QUERY RESULTS AS VARIABLES $masterdataid=mysql_result($result,$i,"masterdataid"); echo "Master Data ID: "; echo $masterdataid; ?> Quote Link to comment https://forums.phpfreaks.com/topic/144211-solved-basic-how-to-disaplay-a-single-record-and-then-the-next-available-record/ Share on other sites More sharing options...
webmaster1 Posted February 7, 2009 Author Share Posted February 7, 2009 Actually scratch that. It looks like fetching the next available record using an auto_increment or datestamp field can get fairly messy. I'll probably just partially display all the records and let the user enter the full record using GET. Quote Link to comment https://forums.phpfreaks.com/topic/144211-solved-basic-how-to-disaplay-a-single-record-and-then-the-next-available-record/#findComment-756782 Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 The problem is that if you're working in a multi-user environment (more than one person accesses the page), there is no way you can guarantee the next id is gonna be the same thing you initially looked up. Easiest 'workaround' is to go ahead and do a preemptive table insert as a placeholder, so that if someone else comes along they don't grab it. Problem with that solution though is that if it turns out you don't need it, it's taking up unnecessary space. You can turn around and delete it no problem, but then you're going to have ids that skip sequence a lot, which may or may not be an issue to you. IMO your best option is to sit down and really think about whether you need to know the next id in the first place, and try to work it so you don't. Quote Link to comment https://forums.phpfreaks.com/topic/144211-solved-basic-how-to-disaplay-a-single-record-and-then-the-next-available-record/#findComment-756788 Share on other sites More sharing options...
webmaster1 Posted February 7, 2009 Author Share Posted February 7, 2009 Thanks for the advice Crayon. I've broken it down to what processes are actually required rather than how I think it should work. I'm using 'get' variable (a list of partially displayed records, each with a link) and passing it through the next page via the url to view the record by itself and in full. Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/144211-solved-basic-how-to-disaplay-a-single-record-and-then-the-next-available-record/#findComment-756826 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.