marukochan Posted February 8, 2007 Share Posted February 8, 2007 Hi!, Hope somebody can help me out. What I want to do is first for the user to select either 1) All projects or 2) By status of the projects (Another script - project_db.php) Then the option will be passed to this script (project_pagination.php) 'switch' in this script will determine which query to run based on the user's selected option. The first page goes OK but error occurs when I click the next page. Error is Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\htdocs\project paper\mogec24Jan07\project_pagination.php on line 38 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\htdocs\project paper\mogec24Jan07\project_pagination.php on line 42 Nothing to Display! Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\htdocs\project paper\mogec24Jan07\project_pagination.php on line 59 Does this has something to do with 'switch' ? My code (project_pagination.php): <?php include ("page_function.php"); header_start(); header_user(); echo ("<p><b>Project List</b></p>"); connect_database(); $option = $_POST['option']; // Set page to zero if no current page if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } // Set n $max_results = 5; // Limit for current page $from = (($page * $max_results) - $max_results); switch ($option){ case "all": $sql = mysql_query("SELECT * FROM project LIMIT $from, $max_results"); $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM project"),0); break; case "status": $status = $_POST['status']; $sql = mysql_query("SELECT * FROM project WHERE project_status = '$status' LIMIT $from, $max_results"); $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM project WHERE project_status='$status'"),0); break; } // Display Area if(mysql_num_rows($sql) == 0){ echo("Nothing to Display!"); } $bgcolor = "#E0E0E0"; // light gray echo("<table width=759 border=0>"); echo("<td width=30% align=middle><i><b>Title</b></i></td>"); echo("<td width=15% align=middle><i><b>Client</b></i></td>"); echo("<td width=10% align=middle><i><b>Status</b></i></td>"); echo("<td width=10% align=middle><i><b>Bid Close</b></i></td>"); echo("<td width=10% align=middle><i><b>Award Date</b></i></td>"); echo("<td width=15% align=middle><i><b>Consultant</b></i></td>"); echo("<td width=10% align=middle><i><b>Details</b></i></td>"); echo("</tr>"); while($row = mysql_fetch_array($sql)){ if ($bgcolor == "#E0E0E0"){ $bgcolor = "#FFFFFF"; }else{ $bgcolor = "#E0E0E0"; } echo("<tr bgcolor=".$bgcolor.">"); echo("<td width=30%>".$row["project_title"]."</td>"); echo("<td width=15%>".$row["client"]."</td>"); echo("<td width=10%>".$row["project_status"]."</td>"); // Set format of bid close date to mm-yyyy $split1 = explode("-", $row["date_bidclose"]); $date_bid= "" . $split1[1] . "-" . $split1[0] .""; echo("<td width=10% align=middle>".$date_bid."</td>"); // Set format of award date to mm-yyyy $split2 = explode("-", $row["date_award"]); $date_award = "" . $split2[1] . "-" . $split2[0] .""; echo("<td width=10% align=middle>".$date_award."</td>"); // Get consultant name from table company $consultant_id=$row['company_id']; $check = mysql_query("SELECT * FROM company WHERE company_id = '$consultant_id'") or die(mysql_error()); $co_info=mysql_fetch_array($check); $consultant=$co_info['company_name']; echo("<td width=15%>".$consultant."</td>"); echo ("<td width=10% align=middle><a href='project_details.php?id=".$row["project_id"]."'>View</a>"); echo("</tr>"); } echo("</table>"); echo("</br>"); // Find out total number of pages $total_pages = ceil($total_results / $max_results); if ($page < 1) { $page = 1; } elseif ($page > $total_pages) { $pagenum = $total_pages; } // Link for previous page if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><b>Previous </b></a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } } // Link for next page if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"><b> Next</b></a>"; } echo "</center>"; footer(); ?> Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.