Warning my sql fetch array() expets parameter 1 errror.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webtechbharathi
    New Member
    • May 2014
    • 9

    #1

    Warning my sql fetch array() expets parameter 1 errror.

    Warning: mysql_fetch_arr ay() expects parameter 1 to be resource, boolean given in C:\wamp\www\pro jects\...on line 164.

    Warning: mysql_fetch_arr ay() expects parameter 1 to be resource, boolean given in C:\wamp\www\pro jects\ on line 391


    Code:
      <html> 
    <head> 
    <title>Online examination</title>
    <image src="logo.png" height="15%" width="100%"><br>
    <link rel="stylesheet" type="text/css" href="heading.css">
    <style type="text/css">
    <!--
    body {
    	margin-left: 0px;
    	margin-top: 0px;
    	margin-right: 0px;
    	margin-bottom: 0px;
    	background-color: #026290;
    }
    
    *{
    padding: 0px;
    margin: 0px;
    }
    #vertmenu {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 100%;
    width: 160px;
    padding: 0px;
    margin: 0px;
    }
    
    #vertmenu h1 {
    display: block;
    background-color:#FF9900;
    font-size: 90%;
    padding: 3px 0 5px 3px;
    border: 1px solid #000000;
    color: #333333;
    margin: 0px;
    width:159px;
    }
    
    #vertmenu ul {
    list-style: none;
    margin: 0px;
    padding: 0px;
    border: none;
    }
    #vertmenu ul li {
    margin: 0px;
    padding: 0px;
    }
    #vertmenu ul li a {
    font-size: 80%;
    display: block;
    border-bottom: 1px dashed #C39C4E;
    padding: 5px 0px 2px 4px;
    text-decoration: none;
    color: #666666;
    width:160px;
    }
    
    #vertmenu ul li a:hover, #vertmenu ul li a:focus {
    color: #000000;
    background-color: #eeeeee;
    }
    .style1 {color: #000000}
    div.pagination {
    
    	padding: 3px;
    
    	margin: 3px;
    
    }
    
    
    
    div.pagination a {
    
    	padding: 2px 5px 2px 5px;
    
    	margin: 2px;
    
    	border: 1px solid #AAAADD;
    
    	
    
    	text-decoration: none; /* no underline */
    
    	color: #000099;
    
    }
    
    div.pagination a:hover, div.pagination a:active {
    
    	border: 1px solid #000099;
    
    
    
    	color: #000;
    
    }
    
    div.pagination span.current {
    
    	padding: 2px 5px 2px 5px;
    
    	margin: 2px;
    
    		border: 1px solid #000099;
    
    		
    
    		font-weight: bold;
    
    		background-color: #000099;
    
    		color: #FFF;
    
    	}
    
    	div.pagination span.disabled {
    
    		padding: 2px 5px 2px 5px;
    
    		margin: 2px;
    
    		border: 1px solid #EEE;
    
    	
    
    		color: #DDD;
    
    	}
    
    	
    -->
    </style>
    </head>
    <body>
    <table align="center" border="1" width="100%">
      <tr>
        <td><form action="" method="get" name="page">
             <font color="#FFFFFF" size="+2"> Page per Record</font>
             <input name="limit" type="text"  style="margin-left:10px;" value="<?php if(isset($_GET['limit'])) echo $_GET['limit']; else echo "5";?>" size="3" maxlength="3">
             <input name="go" type="submit" value="Go"> 
          </form>
       </td>
      </tr>
    </table>
    <?php 
    echo @$_REQUEST['id'];
    echo @$_REQUEST['sub_name'];  
    include("db.php");
        if(mysqli_connect_errno())
          {
    	     echo "Failed to connect to MYSQL: " .mysqli_connect_error();
          }
    
    
         $sql = "SELECT * FROM ".@$_REQUEST['sub_name']."";
         $tbl_name=@$_REQUEST['sub_name'];		//your table name
          $adjacents = 4;          // How many adjacent pages should be shown on each side?
    	                            /*First get total number of rows in data table. 
                                     If you have a WHERE clause in your query, make sure you mirror it here.*/
    
    	echo $query = "SELECT COUNT(*) as num FROM ".@$_REQUEST['sub_name']."";
    	$total_pages = mysql_fetch_array(mysql_query($query,$con));
    	//$total_pages = mysql_fetch_array(mysql_query($query,$con)) or die($query."<br/><br/>".mysql_error());
       
    	$total_pages = $total_pages['num'];/* Setup vars for query. */
    
    	$targetpage = "pagination5.php"; 	//your file name  (the name of this file)
    
    	$limit = 2; 								//how many items to show per page
    	if(isset($_GET['limit']))
    	$limit=$_GET['limit'];
    	                                 
    									 
    	@$page =$_GET['page'];
    
    	if($page) 
    
    		$start = ($page - 1) * $limit; 			//first item to display on this page
    
    	else
    
    		$start = 0;								//if no page var is given, set start to 0
    
    	
    
    	/* Get data. */
    
    	$sql = "SELECT * FROM  ".@$_REQUEST['sub_name']." ORDER BY id LIMIT $start, $limit ";
    	
    	
    	$result = mysql_query($sql,$con);
    
    	
    
    	/* Setup page vars for display. */
    
    	if ($page == 0) $page = 1;					//if no page var is given, default to 1.
    
    	$prev = $page - 1;							//previous page is page - 1
    
    	$next = $page + 1;							//next page is page + 1
    
    	$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.
    
    	$lpm1 = $lastpage - 1;						//last page minus 1
    
    	
    
    	/* 
    
    		Now we apply our rules and draw the pagination object. 
    
    		We're actually saving the code to a variable in case we want to draw it more than once.
    
    	*/
    
    	$pagination = "";
    
    	if($lastpage > 1)
    
    	{	
    
    		$pagination .= "<div class=\"pagination\">";
    
    		//previous button
    
    		if ($page > 1) 
    
    			$pagination.= "<a href=\"$targetpage?page=$prev&limit=$limit\">« previous</a>";
    
    		else
    
    			$pagination.= "<span class=\"disabled\">« previous</span>";	
    
    		
    
    		//pages	
    
    		if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
    
    		{	
    
    			for ($counter = 1; $counter <= $lastpage; $counter++)
    
    			{
    
    				if ($counter == $page)
    
    					$pagination.= "<span class=\"current\">$counter</span>";
    
    				else
    
    					$pagination.= "<a href=\"$targetpage?page=$counter&limit=$limit\">$counter</a>";					
    
    			}
    
    		}
    
    		elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
    
    		{
    
    			//close to beginning; only hide later pages
    
    			if($page < 1 + ($adjacents * 2))		
    
    			{
    
    				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
    
    				{
    
    					if ($counter == $page)
    
    						$pagination.= "<span class=\"current\">$counter</span>";
    
    					else
    
    						$pagination.= "<a href=\"$targetpage?page=$counter&limit=$limit\">$counter</a>";					
    
    				}
    
    				$pagination.= "...";
    
    				$pagination.= "<a href=\"$targetpage?page=$lpm1&limit=$limit\">$lpm1</a>";
    
    				$pagination.= "<a href=\"$targetpage?page=$lastpage&limit=$limit\">$lastpage</a>";		
    
    			}
    
    			//in middle; hide some front and some back
    
    			elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
    
    			{
    
    				$pagination.= "<a href=\"$targetpage?page=1&limit=$limit\">1</a>";
    
    				$pagination.= "<a href=\"$targetpage?page=2&limit=$limit\">2</a>";
    
    				$pagination.= "...";
    
    				for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
    
    				{
    
    					if ($counter == $page)
    
    						$pagination.= "<span class=\"current\">$counter</span>";
    
    					else
    
    						$pagination.= "<a href=\"$targetpage?page=$counter&limit=$limit\">$counter</a>";					
    
    				}
    
    				$pagination.= "...";
    
    				$pagination.= "<a href=\"$targetpage?page=$lpm1&limit=$limit\">$lpm1</a>";
    
    				$pagination.= "<a href=\"$targetpage?page=$lastpage&limit=$limit\">$lastpage</a>";		
    
    			}
    
    			//close to end; only hide early pages
    
    			else
    
    			{
    
    				$pagination.= "<a href=\"$targetpage?page=1&limit=$limit\">1</a>";
    
    				$pagination.= "<a href=\"$targetpage?page=2&limit=$limit\">2</a>";
    
    				$pagination.= "...";
    
    				for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
    
    				{
    
    					if ($counter == $page)
    
    						$pagination.= "<span class=\"current\">$counter</span>";
    
    					else
    
    						$pagination.= "<a href=\"$targetpage?page=$counter&limit=$limit\">$counter</a>";					
    
    				}
    
    			}
    
    		}
    
    		
    
    		//next button
    
    		if ($page < $counter - 1) 
    
    			$pagination.= "<a href=\"$targetpage?page=$next&limit=$limit\">next »</a>";
    
    		else
    
    			$pagination.= "<span class=\"disabled\">next »</span>";
    
    		$pagination.= "</div>\n";		
    
    	}
    
    
    ?>
    <?php /*?><?php if(isset($_GET['msg'])) echo "id:[ ".$_GET['id']." ] <center>".$_GET['msg']."</center>"; 
    					
    					if(isset($_GET['cmsg'])) echo "<center>".$_GET['cmsg']."</center>";
    					?>
    <?php */?>
    
    <table align="center" width="100%">
    <tr>
    <td>      
    	
    
     <table align="center" style="color:#FFFFFF">
       <font color="#FFFFFF">Online examination system</font> </span></strong></div>
    
    
        <?php   
                    while($row = mysql_fetch_array($result))
                    {
         ?>
            
                <?php echo" <form name='exam' method='post' action='results.php'>"
    
    	."<tr ><td>" ."Q" .$row['id']. "." ."&nbsp;".$row['question'] ."</td></tr>"
    	."<tr><td>" ."&nbsp;" ."&nbsp;" ."&nbsp;" ."a" ."&nbsp;"  ."<input type='radio' name='answer' value='a'>"  .$row['a']  ."</td></tr>"
    	."<tr><td>" ."&nbsp;"."&nbsp;"  ."&nbsp;" ."b" ."&nbsp;"  ."<input type='radio' name='answer' value='b'>"  .$row['b']  ."</td></tr>"
    	. "<tr><td>" ."&nbsp;" ."&nbsp;" ."&nbsp;" ."c" ."&nbsp;"  ."<input type='radio' name='answer' value='c'>"  .$row['c'] ."</td></tr>"
    	. "<tr><td>" ."&nbsp;" ."&nbsp;" ."&nbsp;" ."d" ."&nbsp;"  ."<input type='radio' name='answer' value='d'>"  .$row['d'] ."<br>" .'<br />';
      echo "</form>"; ?>
    		
    <!-- 		<td width="100"> <a href="update_stock_entries.php?id=<?php// echo $entryid;?>"><img src="images/edit-icon.png" border="0" alt="delete"></a></td>
     -->		
    							<!-- <td width="100">&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="<?php // echo $row['id']; ?>" name="checklist[]" /></td>
     -->				
     <?php } ?>
    </table>
    </td>
    
    <tr><td align="center"><div style="margin-left:20px;"><?php echo $pagination; ?></div></td></tr>
    <tr>
       <td height="30" align="center" bgcolor="#72C9F4"><span class="style1"><a href="http://www.parinamam.in">Developed by Parinamam  </a></span></td></tr>
    </table>
    
    </body>
    </html>
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    RTFM
    On: http://php.net/manual/en/function.mysql-query.php
    "For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. "

    so, on line 165:
    Code:
     $total_pages = mysql_fetch_array(mysql_query($query,$con));
    you do something that could lead to this error.

    Comment

    Working...