24, July 2008

numbering database results - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ 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

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



« on: Sep 11, 2006, 01: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

Visit through proxy Visit through proxy Visit through proxy

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


It's time to use PHP5!


« Reply #1 on: Sep 11, 2006, 01: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 Visit through proxy


Last blog : 4th of July Lottery from TemplateMonster.com
Community Supporter ?
I am a fanatic. So?
*****
Gender: Male
Posts: 500
4934 credits
Members referred : 0


www.demonhale.com


« Reply #2 on: Sep 11, 2006, 06: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.demonhale.com Visit through proxy , Just Visit...
Partners:
http://www.resume-fix.com Visit through proxy , Free Resumes

Last blog : Slowly Getting Back
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #3 on: Sep 11, 2006, 03: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?

Visit through proxy Visit through proxy Visit through proxy

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



« Reply #4 on: Sep 11, 2006, 03: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 Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Sep 11, 2006, 04: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 Visit through proxy


Last blog : 4th of July Lottery from TemplateMonster.com
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #6 on: Sep 11, 2006, 09: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.

Visit through proxy Visit through proxy Visit through proxy

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



« Reply #7 on: Sep 12, 2006, 08:48:31 AM »

Before the while statement add this :

$i = 0;

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #8 on: Sep 13, 2006, 01:25:07 AM »

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

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Community Supporter ?
I am a fanatic. So?
*****
Gender: Male
Posts: 500
4934 credits
Members referred : 0


www.demonhale.com


« Reply #9 on: Sep 14, 2006, 02:19:46 PM »

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

http://www.demonhale.com Visit through proxy , Just Visit...
Partners:
http://www.resume-fix.com Visit through proxy , Free Resumes

Last blog : Slowly Getting Back
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #10 on: Sep 14, 2006, 04:12:42 PM »

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

Visit through proxy Visit through proxy Visit through proxy

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

Topic sponsors:
Get a permanent link here for $1.99!


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?
Jul 24, 2008, 11:28:01 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!


Forum Statistics
Total Posts: 35.717
Total Topics: 7.379
Total Members: 3.710
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: prolist

47 Guests, 3 Users online :

11 users online today:



Readers

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