RE: Sequential read on a file
Yeah, we are gettign a single row each time. The file is hocatID (auto-increm) primary key Hocat (varchar - index) description (varchar) ...plus many other numeric/varchar fields. We are looking to display a single record on a page at one time with an option for the user to step through the file. In our current system, it's a simple case of read next / read previous on the file. Apologies if this is bad mailing list form, but here is the crux of the code. The $hoCategory & $description fields are a cut-down form in html thus.. Ho Category Description ..with the main code being... $GLOBALS["maxRecs"] || $num1 < 1 || $num1 == NULL) $num1 = 0; $sql = "SELECT * FROM `Ho Category` LIMIT " . $num1 . ",1"; $result = mysql_query($sql, $GLOBALS["link"]) or die("Failed on Query"); if (!mysql_num_rows($result)) { // No more records in the file if ($Args[0] == "Incr" || $Args[0] == "Last") $num1--;// undo action else $num1++; } while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $row = setVariables($row); foreach($row as $key => $value) $$key = $value;// copy value to key-named field/var. } mysql_free_result($result); return $num1; } ?> - As I said, we are fumbling a bit here as we look to move towards web-based systems. Regards, Colin K Heaps -Original Message- From: Jerry [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 19, 2003 3:01 PM To: Colin; [EMAIL PROTECTED] Subject: Re: Sequential read on a file Use and id column, like an auto increment one and use that in the html you are writing out +1 or -1 to get the next. i.e. "select id, X, X, X from table where id=1" returns 1, value of X, value of X, value of X etc etc etc then in the html use the id . id+1 Next need some error checking for less than 0 and finding out what the max is. Most lightly going to be something in here : http://www.devshed.com/Server_Side/PHP Is it a case of one rows worth of information from the dB per page/request ? -- Jerry @ MetalCat dot Net -- - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Sequential read on a file
You are right. "read previous" simply not exist. I think this is due to both historical reason and 'client/server model'. In fact, 'read next' is available by reading next row in a query. However, the record cursor is one direction only and cannot be read back. In my experience, I will store the row id of the previous record and perform another sql query if a back operation is required. Regards, > Hi, > Newbie here so please bear with me. > I am running MySQL 3.23.22 with PHP4.01 on WinNT client / Linux > host, everything is working okay and I'm just getting to grips with > some basic database handling. Although I can use mysql_query to get > a list of records using "Select * from `mydata`" - for what we are > looknig at, we also need a basic Next/Prev stepping capability on a > record per record basis. I realise this can be done just grabbing > all records and then moving through the rows, but we are also > looknig at picking up each record individually. I have had some > success using "count(*)" to get the last record, then stepping > through with "limit $x,1" in the select, where $x is decremented / > incremented based on which button is pressed. I cannot seem to find > any simply "read next" or "read previous" type command though. Is > the way I am going about it "right" or is there a more > simple/logical method? My main concern is that, with the key being > auto-increment, as records are added and removed from the database, > as simple +1/-1 may fall over. -Colin > > - > Before posting, please check: >http://www.mysql.com/manual.php (the manual) >http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php -- Yours, KH Chiu C&A Computer Consultants Ltd. Tel: 3104 2070 Fax: 3010 0896 Email: [EMAIL PROTECTED] Website: www.caconsultant.com - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Sequential read on a file
Use and id column, like an auto increment one and use that in the html you are writing out +1 or -1 to get the next. i.e. "select id, X, X, X from table where id=1" returns 1, value of X, value of X, value of X etc etc etc then in the html use the id . id+1 Next need some error checking for less than 0 and finding out what the max is. Most lightly going to be something in here : http://www.devshed.com/Server_Side/PHP Is it a case of one rows worth of information from the dB per page/request ? -- Jerry @ MetalCat dot Net -- - Original Message - From: "Colin" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, February 19, 2003 2:51 PM Subject: Sequential read on a file > Hi, > Newbie here so please bear with me. > I am running MySQL 3.23.22 with PHP4.01 on WinNT client / Linux host, > everything is working okay and I'm just getting to grips with some basic > database handling. > Although I can use mysql_query to get a list of records using "Select * from > `mydata`" - for what we are looknig at, we also need a basic Next/Prev > stepping capability on a record per record basis. > I realise this can be done just grabbing all records and then moving through > the rows, but we are also looknig at picking up each record individually. > I have had some success using "count(*)" to get the last record, then > stepping through with "limit $x,1" in the select, where $x is decremented / > incremented based on which button is pressed. > I cannot seem to find any simply "read next" or "read previous" type command > though. Is the way I am going about it "right" or is there a more > simple/logical method? > My main concern is that, with the key being auto-increment, as records are > added and removed from the database, as simple +1/-1 may fall over. > -Colin > > - > Before posting, please check: >http://www.mysql.com/manual.php (the manual) >http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php