# \[PHP\] cant understand why code wont work

**URL:** <https://forum.kirupa.com/t/php-cant-understand-why-code-wont-work/197926>\
**Category:** programming\
**Created:** [August 20, 2006, 11:13pm UTC](https://forum.kirupa.com/t/php-cant-understand-why-code-wont-work/197926 "2006-08-20T23:13:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Decfor](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@Decfor](https://forum.kirupa.com/u/Decfor)\
**Post date:** [August 20, 2006, 11:13pm UTC](https://forum.kirupa.com/t/php-cant-understand-why-code-wont-work/197926/1 "2006-08-20T23:13:08Z")

</div>

im looking to greatly improve my PHP skills. there are a few reasons bhind this.  
so, i thought what better way to do it than to try to create my own scripts.

so, im making a variety of scripts, and most of them work no probs. the odd one that i have a problem with, i post on here.

un fortunately, this is one of those (^) occasions.

im trying to make a php PM script, tha pulls the messages from a separate table in a database.

however, one of the lines gives the error  
“ **Warning** : mysql\_num\_rows(): supplied argument is not a valid MySQL result resource in **/myurl/inbox.php** on line **35** ”

ive posted my php below:

```php
<?php
//include session info
include("sessionfile_name.php");

//get current page
$page = $_GET['page'];

//if page is blank, then set page to 1
if($page==""){
$page='1';
}

// store the functions for chanigng pages.
$nextpage = $page + 1;
$prevpage = $page - 1;

//connection info
mysql_connect ("localhost", "user", "pass") or die ('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ("db");

//get info on current user, and store in an array
$getuser = mysql_query("SELECT * FROM contacts WHERE user = '$user_info[0]'");
$userdetails = mysql_fetch_array($getuser);

//retrieve the stat_id field from this array, and print it to screen (temporary, for error-handling purposes)
$stat_id = $userdetails['stat_id'];
echo $stat_id;

//retrieve the persons' mail based on their userinfo
$getmail = mysql_query("SELECT * FROM pms WHERE to = '$stat_id' ORDER BY date");

//get the number of rows (number of mail)

////////////////////////////////////////////////
// THIS LINE IS THE ONE THAT GIVES THE ERROR!!//
////////////////////////////////////////////////

$numofrows = mysql_num_rows($getmail);

//store the maximum amount that can be printed to a page into a variable.
$maxperpage = '10';

/*
if the number of mail is bigger than the maximum that can be stored on 1 page
then use the $maxperpage variable in the following for statement
else if all mail can fit on 1 page, use the amount of mail in the following for statement.
*/
if($numofrows > $maxperpage){
    $use = $maxperpage;
}elseif($numofrows <= $maxperpage){
    $use = $numrows;
}

//get the last page, by calculating how many pages the mail takes up
$lastpage = ceil($numofrows/$maxperpage);

/*if the page is 1, the starting row (i) is 0. if not, then
the starting row is the sum of the formula below. */
if($page==1){
$i=0;
}else{
$i=($page*$maxperpage)-($maxperpage-9);
}

//setup the table, and table headers.
echo'<table width="75%" border="1" cellspacing="5" cellpadding="0" align="center">';
echo'<tr>';
echo'<td><h3><div align="center">From:</div></h3></td>';
echo'<td><h3><div align="center">Sent:</div></h3></td>';
echo'</tr>';

//for each row, print out the mail, as well as a few extra details (like who it was sent by, and when)
for ($i; $i < $use; $i++){
        $mail = mysql_fetch_array($getmail);
        echo '<tr>';
        echo "<td>";
        echo '<a href="stats.php?id=' . mysql_result($mail,$i,'sender_id') . '">' . mysql_result($mail, $i, 'from') . '</a></td>';
        echo '<td>'.(mysql_result($mail,$i,'sent')).'</td>';
        echo'</tr>';
        
        echo '<tr>';
        echo'<td colspan="2">'.mysql_result($mail,$i,'message').'</td>';
        echo'</tr>';
        
}

//end table
echo '</table>';
?>

```

i really cant see why it gives this error. anyone got any ideas?  
thanx,  
Decfor
