PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 6:14 pm
i found this script on a site...i pretty much understand it
BUT i have no idea what "rs" is... what is it?
like the line - while (odbc_fetch_row($rs))
or the lines ->
$compname=odbc_result($rs,"CompanyName");
$conname=odbc_result($rs,"ContactName");
anyone know?
------
Code: Select all
<html><body><?php
$conn=odbc_connect('northwind','','');
if (!$conn)
{
exit("Connection Failed: " . $conn);
}
$sql="SELECT * FROM customers";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{
exit("Error in SQL");
}
echo "<table><tr>";
echo "<th>Companyname</th>";
echo "<th>Contactname</th></tr>";
while (odbc_fetch_row($rs))
{
$compname=odbc_result($rs,"CompanyName");
$conname=odbc_result($rs,"ContactName");
echo "<tr><td>$compname</td>";
echo "<td>$conname</td></tr>";
}
odbc_close($conn);
echo "</table>";
?>
</body>
</html>
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Wed Jan 05, 2005 6:21 pm
(don't kill me if i'm wrong, but this is more or less how it goes)
If you want to know more about functions, this is a good tip:
surf to
http://www.php.net/function_name , so in your case
http://www.php.net/odbc_exec
http://www.php.net/odbc_fetch_row
...
if you perform on a query on a rdbms, the result is a set (of tuples).. in other words, a resultset. so usually a programmer chooses a variable with the name $rs or $result.
and then you iterate over all the rows in that set like
and finally you retrieve the info from each of those tuples into a variable:
Code: Select all
$compname=odbc_result($rs,"CompanyName");
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 6:47 pm
SOLVED
well look...i understood! and i cahnged the varibles and made some more tables...
ima add a background and stuff...and there i have my Gameserver ranking page..
BUT
how would i make the Table in order from highest level to lowest lvl?
this is the page
SOLVED
http://www.simplemu.no-ip.org/branking.php
SOLVED
the code is this!
Code: Select all
<html><center><body><?php
$conn=odbc_connect('MuOnline','','');
if (!$conn)
{
exit("Connection Failed: " . $conn);
} $sql="SELECT * FROM character WHERE CtlCode IS NULL ORDER BY cLevel LIMIT 35 DESC";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{
exit("Error in SQL");
}
echo "<table border=1><tr>";echo "<th>Name</th>";
echo "<th>Level</th>";
echo "<th>Money</th>";
echo "<th>Experiance</th>";
echo "<th>Strength</th>";
echo "<th>Agility</th>";
echo "<th>Vitality</th>";
echo "<th>Energy</th></tr>";
while (odbc_fetch_row($rs))
{
$xp=odbc_result($rs,"Experience");
$str=odbc_result($rs,"Strength");
$agi=odbc_result($rs,"Dexterity");
$vit=odbc_result($rs,"Vitality");
$nrg=odbc_result($rs,"Energy");
$zen=odbc_result($rs,"Money");
$pname=odbc_result($rs,"Name");
$level=odbc_result($rs,"cLevel");
echo "<tr><td>$pname</td>";
echo "<td>$level</td>";
echo "<td>$zen</td>";
echo "<td>$xp</td>";
echo "<td>$str</td>";
echo "<td>$agi</td>";
echo "<td>$vit</td>";
echo "<td>$nrg</td></tr>";
}
odbc_close($conn);
echo "</table>";
?></body></html>
(right now it goes by ABC order by the name table.. =/ )
k thanks
Last edited by
rodrigorules on Wed Jan 05, 2005 9:14 pm, edited 11 times in total.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Wed Jan 05, 2005 7:06 pm
$sql="SELECT * FROM character ORDER BY cLevel DESC"
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 7:10 pm
worked perfectly thanks
NOW how would i make it so...ONLY users with the row "CtlCode" witha value of NULL show up
BECUASE - GameMasters have a CtlCode of 8, i dont want GM's to show up on ranking.
i have tried this!
Code: Select all
<?php
$sql="SELECT * FROM character WHERE CtlCode=NULL ORDER BY cLevel DESC";
?>
but then all the users with CtlCode 8 AND null didnt show up..
any solution?
hope u understand
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Wed Jan 05, 2005 7:33 pm
in sql null is not equal to null.....
if i'm nto mistaken you should use the isnull function
select * from foo where isnull(bar) and bar2 = 'foo2';
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 7:40 pm
huh? O_O
u mean
$sql="SELECT * FROM character WHERE isnull(CtlCode) ORDER BY cLevel DESC";
(character, clevel, and CtlCode are Collums)
? is that what u mean?
i didnt understand the "foo" and bars...
im new to php and stuff like this
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Jan 05, 2005 7:47 pm
Code: Select all
$sql="SELECT * FROM character WHERE CtlCode IS NOT NULL ORDER BY cLevel DESC";
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 7:50 pm
not it only shows the ones which ARE NOT NULL...
how would i make it show those which ARE NULL only?
change it to...
WHERE CtlCode IS NULL
?
ill try it
YEP thanks u put me on the right track
right code was
Code: Select all
<?php
$sql="SELECT * FROM character WHERE CtlCode IS NULL ORDER BY cLevel DESC";
?>
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Jan 05, 2005 7:51 pm
change it to...
WHERE CtlCode IS NULL
Sorry, my mistake. Your correct.
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 7:53 pm
another question...lol
how would i make the chart...35 people max?
like 36 rows(counting the stop row..so thats 35 people)
anyway to do this?
rodrigorules
Forum Commoner
Posts: 35 Joined: Wed Jan 05, 2005 3:10 pm
Post
by rodrigorules » Wed Jan 05, 2005 8:02 pm
heh its huge, so anyone know how to make the table 35 MAX?
someone told me it had something to do with this!
Code: Select all
<?php
for($i=0;$i < 100;++$i)
{
$row = mssql_fetch_row($rs);
?>
but i dont know how to put it into mine..