Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Increment / Record in series (newbie)

Status
Not open for further replies.

omr1119

Programmer
Oct 7, 2003
34
0
0
PH
hi to all Tip master's,
Newbie here!

I have table and i want to print the record in series..
does anyone inform me what's wrong w/ my code...
<?php
$sql="SELECT stud_no, lastname, firstname, m_i, yr, cc, count(*) FROM stud_info group by stud_no, lastname, firstname, m_i, yr, cc order by lastname";
$b=pg_exec($con,$sql);
$graderow["no"] = 1;
while($graderow=pg_fetch_array($b)){
echo"row"> $graderow["row"];
print"<tr>";
$graderow["no"] = $graderow["row"] +1;
print"<td>{$graderow["no"]}</td>";
print"<td>{$graderow["stud_no"]}</td>";
print"<td>{$graderow["lastname"]}</td>";
print"<td>{$graderow["firstname"]}</td>";
print"<td>{$graderow["m_i"]}</td>";
print"<td>{$graderow["yr"]}</td>";
print"<td>{$graderow["cc"]}</td>";
print"</tr>";
}

Output
No Stud_no Lastname Firstname MI Year Course
1 04-0009 Acosta Jong C I IT
1 04-0014 Almanza Rommel M. I IT
1 03-0001 Alvarez Armi S II SE
1 04-0008 Basco Edsel A I SE

should be
No Stud_no Lastname Firstname MI Year Course
1 04-0009 Acosta Jong C I IT
2 04-0014 Almanza Rommel M. I IT
3 03-0001 Alvarez Armi S II SE
4 04-0008 Basco Edsel A I SE

thanks,
omr c",)

 
Why are you storing the count as $graderow['no']? Why not just use something like $count? I.e.
Code:
<?php
$sql="SELECT stud_no, lastname, firstname, m_i, yr, cc, FROM stud_info group by stud_no, lastname, firstname, m_i, yr, cc order by lastname";
$b=pg_exec($con,$sql);
[red]$number = 1;
while($graderow=pg_fetch_array($b)){
print"<tr>";
print"<td>{[red]$number[/red]}</td>";
print"<td>{$graderow["stud_no"]}</td>";
print"<td>{$graderow["lastname"]}</td>";
print"<td>{$graderow["firstname"]}</td>";
print"<td>{$graderow["m_i"]}</td>";
print"<td>{$graderow["yr"]}</td>";
print"<td>{$graderow["cc"]}</td>";
print"</tr>";
[red]$number++;[/red]
}

You could also try changing your SQL to
Code:
 $sql="SELECT stud_no, lastname, firstname, m_i, yr, cc, count(*)[red] AS row[/red] FROM stud_info group by stud_no, lastname, firstname, m_i, yr, cc order by lastname";

--Chessbot
 
hi Chessbot,

...thank you very much for ur help it works...

thxs. a lot
omr.. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top