homepage Welcome to WebmasterWorld Guest from 54.145.172.149
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Mysql php query
Need some mysql-php query help!
hb_mpp

10+ Year Member



 
Msg#: 409 posted 2:14 am on May 15, 2002 (gmt 0)

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;
}
}
$rs=mysql_query($strSelect);
$nRec=mysql_num_rows($rs);
$nLine=0;
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";
$odd=1;
while ($nLine<$nRec) {
$name=mysql_result($rs,$nLine,"name");
$system=mysql_result($rs,$nLine,"system");
$genre=mysql_result($rs,$nLine,"genre");
$umfang=mysql_result($rs,$nLine,"umfang");
$fsk=mysql_result($rs,$nLine,"fsk");
$preis=mysql_result($rs,$nLine,"preis");
$art=mysql_result($rs,$nLine,"art");
$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";
$nLine=$nLine+1;
}
print "</table>";
}
print "Anzahl: $nRec";
mysql_close();
?>
--------------------------------------------------
eof

 

sugarkane

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 409 posted 4:00 pm on May 15, 2002 (gmt 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:

[perl]
$counter=0;
while ($nLine<$nRec) {
$name[$counter]=mysql_result($rs,$nLine,"name");
$counter++;
}
[/perl]

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).

Lisa

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 409 posted 4:20 pm on May 15, 2002 (gmt 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.

jatar_k

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



 
Msg#: 409 posted 4:42 pm on May 15, 2002 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved