how to handle exception in php

how to handle exception in php

am 02.05.2010 07:26:53 von Bavithra R

--0016363b877c58e0d7048595b90a
Content-Type: text/plain; charset=ISO-8859-1

hi friends

I am doing a simple student mark details project.
for calculating rank I need to compare the total marks one by one.
To do so i use *for loop.* so atlast while reaching the end of the table it
shows the following warning.
*
Warning*: mysql_result()
[function.mysql-result]:
Unable to jump to row 18 on MySQL result index on line *50*

It is because it has no next value to compare.How to use try..catch
exception handling in this.?Or any other suggestion.
Can anybody help me

--Bavithra

--0016363b877c58e0d7048595b90a--

Re: how to handle exception in php

am 02.05.2010 15:32:31 von Luiz Alberto

Dear Bavithra,

I would suggest you the following solution

$sql = "SELECT x FROM y";
$rs = mysql_query ($sql)
$num = mysql_numrows($rs);
while ($i < $num){
z = mysql_result($rs, $i, 'x');
$i++;
}

I hope that above solution help you.

Luiz Alberto


On Sun, 2010-05-02 at 10:56 +0530, Bavithra R wrote:
> hi friends
>
> I am doing a simple student mark details project.
> for calculating rank I need to compare the total marks one by one.
> To do so i use *for loop.* so atlast while reaching the end of the table it
> shows the following warning.
> *
> Warning*: mysql_result()
> [function.mysql-result]:
> Unable to jump to row 18 on MySQL result index on line *50*
>
> It is because it has no next value to compare.How to use try..catch
> exception handling in this.?Or any other suggestion.
> Can anybody help me
>
> --Bavithra


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: how to handle exception in php

am 03.05.2010 05:51:26 von dmagick

On 02/05/10 15:26, Bavithra R wrote:
> hi friends
>
> I am doing a simple student mark details project.
> for calculating rank I need to compare the total marks one by one.
> To do so i use *for loop.* so atlast while reaching the end of the table it
> shows the following warning.
> *
> Warning*: mysql_result()
> [function.mysql-result]:
> Unable to jump to row 18 on MySQL result index on line *50*
>
> It is because it has no next value to compare.How to use try..catch
> exception handling in this.?Or any other suggestion.
> Can anybody help me

This isn't an exception, so a try catch won't work. (Exceptions are
fatal and would say something like "uncaught exception ...").

This is a warning about trying to read something that doesn't exist from
mysql.

I'd do something like

$query = "select blah";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
echo "do stuff here";
}

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: how to handle exception in php

am 04.05.2010 17:18:39 von Richard Quadling

On 2 May 2010 06:26, Bavithra R wrote:
> hi friends
>
> I am doing a simple student mark details project.
> for calculating rank I need to compare the total marks one by one.
> To do so i use *for loop.* so atlast while reaching the end of the table it
> shows the following warning.
> *
> Warning*: mysql_result()
> [function.mysql-result]:
> Unable to jump to row 18 on MySQL result index on line *50*
>
> It is because it has no next value to compare.How to use try..catch
> exception handling in this.?Or any other suggestion.
> Can anybody help me
>
> --Bavithra
>

Commonly the while loop looks like ...

while ($row = mysql_fetch_assoc($result)) {

If you intend to use this for other loops, watch out where the result
of the function is False to indicate the end of the iterations.

while (False !== ($row = mysql_fetch_assoc($result))) {

Whilst this offers nothing extra here, for functions where 0 or "" are
valid responses and False is the "get me out of here" response,
testing for type and value (!==) is important.

--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: how to handle exception in php

am 08.05.2010 13:30:43 von Bavithra R

--0016364eee10915c4d048613814f
Content-Type: text/plain; charset=ISO-8859-1

hi friends...

Thanks for your suggestions..but i could not get the exact rank list
properly..
My code is as below..

$sql2="SELECT * FROM rank";
$result=mysql_query($sql2,$con);
$num=mysql_num_rows($result);
for($i=0;$i<$num;$i++)
{
$f1=mysql_result($result,$i,"regno");
$d6=mysql_result($result,$i,"total");
$d7=mysql_result($result,$i+1,"total");
$d8=mysql_result($result,$i,"rank");
if($d6==$d7)
{
$sql8="UPDATE $_POST[test] set rank='$i'+1 where total='$d6'";
mysql_query($sql8,$con);
}
else if($d6!=$d7)
{
$sql1="UPDATE $_POST[test] SET rank='$i'+1 WHERE regno='$f1'";
mysql_query($sql1,$con);
}

But if i use while loop as you people said..No such list is obtained.
Please check and tell if i could do any changes in the above code..

Also if any two students has secured the same total they has to be given the
same rank..Till now it generates the rank but in this order...1 2 3 4 7 7
7..As the last 3 students has the got same total..
any suggestion


regards
--Bavithra

--0016364eee10915c4d048613814f--