Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Mysql php query

Need some mysql-php query help!



2:14 am on May 15, 2002 (gmt 0)

Inactive Member
Account Expired


Please take a look at my query script. It includes sorting, adding, order-option and alternating row colors. I donīt want to change a lot, because it works fine.

My Question:
How can i get THIS SCRIPT do to paged results?

Thank you
mysql_connect("-","-","-") or die ("DBMS Server Error");
mysql_select_db("-") or die ("DBMS Database Error");
$strSelect="select name,system,genre,umfang,fsk,preis,art from usedgames";
if (!empty($sort)) {
switch ($sort) {
case "name": $strSelect.=" order by name"; break;
case "system": $strSelect.=" order by system"; break;
case "genre": $strSelect.=" order by genre"; break;
case "umfang": $strSelect.=" order by umfang"; break;
case "fsk": $strSelect.=" order by fsk"; break;
case "preis": $strSelect.=" order by preis"; break;
case "art": $strSelect.=" order by art"; break;
if ($nRec>0) {
print "<CENTER><table border=0><tr bgcolor=#009DC1><td><a href=\"$PHP_SELF?sort=name\">Name</a></td><td><a href=\"$PHP_SELF?sort=system\">System</a></td><td><a href=\"$PHP_SELF?sort=genre\">Genre</a></td><td><a href=\"$PHP_SELF?sort=umfang\">Umfg</a></td><td><a href=\"$PHP_SELF?sort=fsk\">FSK</a></td><td><a href=\"$PHP_SELF?sort=preis\">Preis €</a></td><td><a href=\"$PHP_SELF?sort=art\">NEU</a></td></tr>\r\n";
while ($nLine<$nRec) {
$odd++; if ($odd==3) { $odd=1; }
if ($odd==1) { print "<tr>"; } else { print "<tr bgcolor=#08554F>"; }
if ((!empty($edit)) && (!empty($name)) && ($name==$name)) {
print "<form action=\"ugview.php\"><input type=hidden name=sort value=\"$sort\">";
print "<td>Modif</td>";
print "<td><input type=text name=system size= value=\"$system\"></td>";
print "<td><input type=text name=genre size= value=\"$genre\"></td>";
print "<td><input type=text name=umfang size= value=\"$umfang\"></td>";
print "<td><input type=text name=fsk size= value=\"$fsk\"></td>";
print "<td><input type=text name=preis size= value=\"$preis\"></td>";
print "<td><input type=text name=art size= value=\"$art\"></td>";
print "<td><input type=submit value=\"OK\"></td>";
print "</form>";
} else {
print "<td><a href=\"order.php?name=$name&system=$system&genre=$genre&umfang=$umfang&fsk=$fsk&preis=$preis&art=$art\">$name</a></td>";
if ($system=="") { $system=" "; }
print "<td>$system</td>";
if ($genre=="") { $genre=" "; }
print "<td>$genre</td>";
if ($umfang=="") { $umfang=" "; }
print "<td>$umfang</td>";
if ($fsk=="") { $fsk=" "; }
print "<td>$fsk</td>";
if ($preis=="") { $preis=" "; }
print "<td>$preis</td>";
if ($art=="") { $art=" "; }
print "<td>$art</td>";
print "</tr>\r\n";
print "</table>";
print "Anzahl: $nRec";

4:00 pm on May 15, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 6, 2000
votes: 0

Welcome to WebmasterWorld hb_mpp :)

The simplest way would be to change the contents of your while{} loop. Instead of printing directly to the screen, put the values into an array temporarily. eg:

while ($nLine<$nRec) {

Once you have all the results in their arrays, it's a fairly simple matter to print out, say, 10 rows at a time, starting at whatever element number of the array you choose (eg print out ten rows starting at element 0 for the first page of results, ten rows starting at element 10 for the second etc).

4:20 pm on May 15, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 6, 2002
votes: 0

If you use mysql_fetch_array all your variables are already to go. Then you can store that array in a multi-dimensional array.
4:42 pm on May 15, 2002 (gmt 0)


WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
votes: 0

I use the index col for the table, limit the results to 10 and sort asc or desc and then pass the index num so I can get the next 10 after and then I use the mysql_fetch_array to store in a multidimensional array. The I can easily work with the array and do what I like when outputting it.