sp@rky13 Posted November 14, 2009 Share Posted November 14, 2009 Ok so in sql how can you make it return a number for each result. So I have this echo: echo $row['name']." - "."[village]".$row['x']."|".$row['y']."[/village]"."<br>"; Which returns this: Gianni23 - [village]700|495[/village] Gianni23 - [village]699|440[/village] Gianni23 - [village]708|475[/village] Gianni23 - [village]699|435[/village] Gianni23 - [village]714|456[/village] Gianni23 - [village]633|674[/village] ...... How can I make it be: 1. Gianni23 - [village]700|495[/village] 2. Gianni23 - [village]699|440[/village] 3. Gianni23 - [village]708|475[/village] 4. Gianni23 - [village]699|435[/village] 5. Gianni23 - [village]714|456[/village] 6. Gianni23 - [village]633|674[/village] ..... Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/ Share on other sites More sharing options...
phpretard Posted November 14, 2009 Share Posted November 14, 2009 $stop="20"; //<< count the rows in the DB for($i = 1; $i < $stop; $i++){ echo "$i. your stuff<br />"; } Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957329 Share on other sites More sharing options...
sp@rky13 Posted November 14, 2009 Author Share Posted November 14, 2009 Why is it stop = 20 Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957331 Share on other sites More sharing options...
phpretard Posted November 14, 2009 Share Posted November 14, 2009 it could be: $stop=mysql_num_rows($queryName); 20 is just a number I made up... The $stop is there in case you need to paginate later. You don't have to stop it at all. Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957332 Share on other sites More sharing options...
sp@rky13 Posted November 14, 2009 Author Share Posted November 14, 2009 I changed it to that with query name changed to $result (which is the wuery name) but it outputs 1's for every row???? Here's the query's code: $result = mysql_query("SELECT * FROM village$world JOIN player$world ON village$world.player = player$world.id WHERE player$world.name = '$vpt_sub' $include;") or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo "$i".$row['name']." - "."[village]".$row['x']."|".$row['y']."[/village]"."<br>"; } Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957334 Share on other sites More sharing options...
Garethp Posted November 14, 2009 Share Posted November 14, 2009 $result = mysql_query("SELECT * FROM village$world JOIN player$world ON village$world.player = player$world.id WHERE player$world.name = '$vpt_sub' $include;") or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo "$i".$row['name']." - "."[village]".$row['x']."|".$row['y']."[/village]"."<br>"; $i++; } Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957335 Share on other sites More sharing options...
phpretard Posted November 14, 2009 Share Posted November 14, 2009 $stop=mysql_num_rows($result); for($i = 1; $i < $stop; $i++) { echo "$i".$row['name']." - "."[village]".$row['x']."|".$row['y']."[/village]"."<br>"; } Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957336 Share on other sites More sharing options...
sp@rky13 Posted November 14, 2009 Author Share Posted November 14, 2009 I tried that and I get the numbering but then the actual content isn't imported. So it comes up as: 1 - [village]|[/village] 2 - [village]|[/village] .... instead of: 1 - [village]456|567[/village] 2 - [village]123|543[/village] ..... Why is this? I should have probably given you this in the first place but here's the complete code: <?php $x = $_GET["x"];?> <?php $x1 = $_GET["x1"];?> <?php $x2 = $_GET["x2"];?> <?php $y = $_GET["y"];?> <?php $y1 = $_GET["y1"];?> <?php $y2 = $_GET["y2"];?> <?php $k = $_GET["k"];?> <?php $k1 = $_GET["k1"];?> <?php $world = $_GET["world"];?> <?php $vpt_sub = $_GET["village/player/tribe_submit"]; ?> <?php if ($x=='on' AND $y=='') $include = "AND x BETWEEN '$x1' AND '$x2'"; else if ($y=='on' AND $x=='') $include = "AND y BETWEEN '$y1' AND '$y2'"; else if ($y=='on' AND $x=='on') $include = "AND x BETWEEN '$x1' AND '$x2' AND y BETWEEN '$y1' AND '$y2'"; else if ($y=='' AND $x=='') $include = ""; $yLow = floor($k1 / 10) * 100; $yHigh = $yLow + 99; $xLow = ($k1 % 10) * 100; $xHigh = $xLow + 99; $BetweenClause = "x BETWEEN $xLow AND $xHigh AND y BETWEEN $yLow AND $yHigh"; $con = mysql_connect("****","******","*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("*****", $con); $result = mysql_query("SELECT * FROM village$world JOIN player$world ON village$world.player = player$world.id WHERE player$world.name = '$vpt_sub' $include;") or die(mysql_error()); $stop=mysql_num_rows($result); for($i = 1; $i < $stop; $i++) { echo "$i".$row['name']." - "."[village]".$row['x']."|".$row['y']."[/village]"."<br>"; } mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957338 Share on other sites More sharing options...
phpretard Posted November 14, 2009 Share Posted November 14, 2009 $i=mysql_num_rows($result); while($row = mysql_fetch_array($result)) { $name=$row['firstname']; $yrow=$row['gender']; $xrow=$row['level']; echo "$i. $name - [village] $xrow | $yrow [/village] <br>"; $i++; } Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957341 Share on other sites More sharing options...
sp@rky13 Posted November 14, 2009 Author Share Posted November 14, 2009 Thankyou ever so much I did correct something though as it didn't work at first which was not having: $stop=mysql_num_rows($result); So ty again. Can someone please tell me how to mark as solved? EDIT: I found it Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957345 Share on other sites More sharing options...
sp@rky13 Posted November 14, 2009 Author Share Posted November 14, 2009 :( A really weird problemjust arose. I need no spaces in the [village] $xrow | $yrow [/village] so I changed to: [village]$xrow|$yrow[/village] but I get this error: Parse error: syntax error, unexpected '/', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /the page that was being viewed on line 46 Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957348 Share on other sites More sharing options...
sp@rky13 Posted November 14, 2009 Author Share Posted November 14, 2009 I tried what Garethp posted earlier and it kinda works but it does this: Gianni23 - [village]700|495[/village] 1. Gianni23 - [village]699|440[/village] 2. Gianni23 - [village]708|475[/village] Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957357 Share on other sites More sharing options...
Garethp Posted November 14, 2009 Share Posted November 14, 2009 So put $i = 1; before the while Link to comment https://forums.phpfreaks.com/topic/181481-solved-numbering-results/#findComment-957359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.