RE: [PHP] Help with database queries

From: Date: Mon, 17 Sep 2001 21:39:07 +0000
Subject: RE: [PHP] Help with database queries
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-67646@lists.php.net to get a copy of this message
> Hi, > > need some help with the code below. I am thinking of reusing this for > building a thumbnail gallery from a database. > > First, is the code actually good? Do i do something that will slow down the > responses? > > Second, can anyone help me with a code sample to implement that will limit > how many records the query is displaying? (break the database response into > pages) > > Third, any good ideas on how to do this the easiest way is appreciated :) > > Thanks! > - Daniel > > > $db = mysql_connect("localhost", "xxx", "xxx"); > > mysql_select_db("xxx",$db); > > $result = mysql_query("SELECT * FROM film WHERE artnr LIKE '$avd'",$db); > > if ($myrow = mysql_fetch_array($result)) { > > echo "<TABLE cellSpacing=3 cellPadding=5 width=600 border=0>\n"; > echo "<TR><TD><span > class='text2'>Art.nr</span></TD>\n"; > echo "<TD><span class='text2'>Titel</span></TD>\n"; > echo "<TD><span > class='text2'></span></TD></TR>\n"; > > do { > > printf("<TR><TD bgColor=#efefef><span > class='text'>%s</span></TD> > <TD bgColor=#efefef><span > class='text'><b>%s</b></span></TD> > <TD bgColor=#efefef><span class='text'>%smin</span></TD> > </TR>\n", $myrow["artnr"], $myrow["titel"], > $myrow["dur"]); use fullstops instead of commas: printf($myrow["artnr"].$myrow["titel"].$myrow["dur"]); > > } while ($myrow = mysql_fetch_array($result)); > echo "</table>\n"; > > } else { > echo "<span class='text2'>No records available...</span>"; > } If you want to limit record outputed at the page, try change mysql query: SELECT * FROM film WHERE artnr LIKE '$avd' LIMIT 0, 10 where first number is row with record and second is number of getting records, or you can to use function mysql_data_seek(), which move pointer to database on selected row: mysql_data_seek($result, 10); this move your internal result pointer to 10. line. Now, when you can output ten next lines, you can do it so: for ($i = 0; $i < 10; $i++) { $row = mysql_fetch_array($result); echo $row["titel"]; // this outputs you "titel" from 11. row of table } // then will be next 9 rows outputed Luboslav Gabal

« previous php.general (#67646) next »