28, May 2012

numbering database results - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  Databases  >  MySQL
Topic: numbering database results
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: numbering database results  (Read 3171 times)
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« on: Sep 11, 2006, 12:20:20 am »

when the data is pulled from the database and it is printed on the screen (up to 20 items at once) how do you make it number each item? i know you can echo the item ID, but if you delete one, that will mess up the numbering for future items.. if you understand this, help please Smiley


Last blog : phpHaze 1.59.1 in Development
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Sep 11, 2006, 12:33:41 am »

when the data is pulled from the database and it is printed on the screen (up to 20 items at once) how do you make it number each item? i know you can echo the item ID, but if you delete one, that will mess up the numbering for future items.. if you understand this, help please Smiley
try this script:
http://www.finalwebsites.com/snippets.php?id=29

Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 619
5660 credits
Members referred : 0


www.dg9.org


« Reply #2 on: Sep 11, 2006, 05:26:02 am »

cant you put an incremental variable and have that one echo per output so that it wont mess up counting when an item is generated...?

http://www.dg9.org , Just Visit...
Partners:
http://www.resume-fix.com , Free Resumes

Last blog : Archos: Where are you?
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #3 on: Sep 11, 2006, 02:33:21 pm »

olaf: that script is mighty large considering the simplicity of what im trying to do

designer: how would i go about doing that?


Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #4 on: Sep 11, 2006, 02:43:54 pm »

$req = mysql_db_query(.......);
while ( $rec = mysql_fetch_array($req) ){
    $i ++;
    echo $i;
}

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Sep 11, 2006, 03:26:32 pm »

olaf: that script is mighty large considering the simplicity of what im trying to do

designer: how would i go about doing that?

because pagination could be tricky I wrote this very easy to use php script, check the example and compare this with this real live page:
http://www.all4yourwebsite.com/search.php

aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #6 on: Sep 11, 2006, 08:21:18 pm »

for some reason my results started at #32 instead of #1, so this is what my code looks like:

Code:
<?php
if ($_GET["order"]=="cmb"
$result dbquery("SELECT * from ".$db_prefix."hiscores ORDER BY player_cmb DESC LIMIT 20"); }
elseif ($_GET["order"]=="hp"
$result dbquery("SELECT * from ".$db_prefix."hiscores ORDER BY player_hp DESC LIMIT 20"); }
elseif ($_GET["order"]=="overall"
$result dbquery("SELECT * from ".$db_prefix."hiscores ORDER BY player_overall DESC LIMIT 20"); }
elseif ($_GET["order"]=="player"
$result dbquery("SELECT * from ".$db_prefix."hiscores ORDER BY player_name ASC LIMIT 20"); }
elseif ($_GET["order"]=="cmb-sort=asc"
$result dbquery("SELECT * from ".$db_prefix."hiscores ORDER BY player_cmb ASC LIMIT 20"); }
elseif ($_GET["order"]=="hp-sort=asc"
$result dbquery("SELECT * from ".$db_prefix."hiscores ORDER BY player_hp ASC LIMIT 20"); }
elseif ($_GET["order"]=="overall-sort=asc"
$result dbquery("SELECT * from ".$db_prefix."hiscores ORDER BY player_overall ASC LIMIT 20"); }
elseif ($_GET["order"]=="player-sort=desc"
$result dbquery("SELECT * from ".$db_prefix."hiscores ORDER BY player_name DESC LIMIT 20"); }
else { $result dbquery("SELECT * from ".$db_prefix."hiscores ORDER BY player_cmb DESC LIMIT 20"); }
while ($data dbarray($result))
{ $i ++;
$player_id $data['player_id'];
$player_user $data['player_user'];
include(ADMIN."hiscores/highest_skill_formula.php");
include(ADMIN."hiscores/colors.php");
include(ADMIN."hiscores/account_converter.php");
$update;
echo "<tr>";
echo "<td class='tbl1' align='center'><small><font color='$player_color'>";
echo $i 31;
echo "</font></small></td>";
echo "<td class='tbl2' align='left'><small><font color='$player_color'>".$data['player_name']."</font></small></td>";
echo "<td class='tbl1' align='center'><small><font color='$player_color'>".$data['player_cmb']."</font></small></td>";
echo "<td class='tbl2' align='center'><small><font color='$player_color'>".$data['player_hp']."</font></small></td>";
echo "<td class='tbl1' align='center'><small><font color='$player_color'>".$data['player_overall']."</font></small></td>";
echo "<td class='tbl2' align='center'><small><font color='$player_color'>".$highest_skill." ".$skill_name."</font></small></td>";
echo "</tr>"
}
?>


currently, with $i - 31, it is working, showing 1, 2, 3, etc.


Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #7 on: Sep 12, 2006, 07:48:31 am »

Before the while statement add this :

$i = 0;

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #8 on: Sep 13, 2006, 12:25:07 am »

thanks man Smiley fixed that problem, now its just echo $i; instead of echo $i - 31


Last blog : phpHaze 1.59.1 in Development
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 619
5660 credits
Members referred : 0


www.dg9.org


« Reply #9 on: Sep 14, 2006, 01:19:46 pm »

i hope its all dandy now... i was late to answer, wheee...

http://www.dg9.org , Just Visit...
Partners:
http://www.resume-fix.com , Free Resumes

Last blog : Archos: Where are you?
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #10 on: Sep 14, 2006, 03:12:42 pm »

yeah this is working now, having problem with a bigger project tho Smiley


Last blog : phpHaze 1.59.1 in Development
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=4029
Tags : php databases Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  Databases  >  MySQL
Topic: numbering database results
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 04:24:32 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.