views:

162

answers:

4

Here I have a problem in this code ..

I want to specify the 4 values in each page .. But I can not ... So far there is a problem, I think, in limit

<?php 

if ( !isset( $_GET["page"] ) ) 
{ 
  $page = 1; 
  include( "connect.php" );  
} else { 
  $page = intval( $_GET['page'] ); 
} 
$max  = 4; 
$from = ($max * $page) - $max; 
$sql  = mysql_query( "
  select *
    from uploads
       , members
       , rooms
   where uploads.MemberID = members.MemberID
     and uploads.RoomID = rooms.RoomID
     and UploadCategory = 'L'
   order by UploadID desc
   limit $from, $max
");  

$num_sql = mysql_num_rows( $sql ); 
$pages   = ceil( $num_sql / $max ); 
$num     = mysql_num_rows( $sql ); 

?> 

<table width="400" border="0" cellspacing="1" cellpadding="0"> 
  <tr> 
    <td>
      <form name="form1" method="post" action=""> 
        <div align="center"> 
          <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
            <tr> 
              <td bgcolor="#FFFFFF">&nbsp;</td> 
              <td colspan="4" bgcolor="#FFFFFF"> 
                <p align="center"><font size="4"> file</font>
              </td> 
            </tr> 
            <tr> 
              <td align="center" bgcolor="#FFFFFF">#</td> 
              <td align="center" bgcolor="#FFFFFF"><strong>member</strong></td> 
              <td align="center" bgcolor="#FFFFFF"><strong> Name</strong></td> 
            </tr>
          </table> 
        </div>
      </form> 
    </td>
  </tr>
  <?php while( $row = mysql_fetch_array( $sql ) ) : ?>
  <tr> 
    <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['UploadID']; ?>"></td> 
    <td bgcolor="#FFFFFF"> <?php echo $row[MemberName]. "<br />";  ?></td> 
    <td bgcolor="#FFFFFF"> <?php echo $row[UpoadName]."<br />";  ?></td> 
  </tr> 
  <?php endwhile; ?> 
  <tr> 
    <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="delete"></td> 
  </tr>
</table>
<?php 

if ( $page > 1 ) 
{ 
  $prev = $page - 1; 
  echo "<a href=" . $PHP_SELF . "?page=$prev\">prev</a>"; 
} 
for ( $i = 1; $i <= $pages; $i++ )  
{
  echo ( $page == $i )
    ? " [$i] " 
    : " <a href=" . $PHP_SELF . "?page=$i\">$i</a> "; 
} 
if ( $page < $pages ) 
{ 
  $next = $page+1; 
  echo "<a href=" . $PHP_SELF . "?page=$next\">next</a>"; 
} 
?>      
</html> 

thanks a lot

EDIT

Further details

alt text

I want to the code as in the picture ..

So that if you click on the number 1 to turn to a new page containing the values 4 and No. 2 if you also turn to a new page containing the 4 other values and so on.

What is wrong with this code even shows me output as in the picture

(((Can anyone help me how can I make code works like the picture ..... Please ... Please

Code works, but not like what I want))))))

A: 

Try using the dictionary with quotes and correct spelling:

echo $row['MemberName']
echo $row['UploadName']

For any better answer, you'd need to include some more information, like Felix already commented...

maligree
What sandy is doing is bad practice for sure, but it should work fine (besides the typo). Constants like MemberName default to their string equivalent; "MemberName" in this case. You do get a notice about it though:PHP Notice: Use of undefined constant MemberName - assumed 'MemberName'
crimson_penguin
A: 

One major problem I'm seeing in this code is that include ("connect.php"); is inside the if(!isset($_GET["page"])) - but you're running mysql_query regardless.

crimson_penguin
+1  A: 

Also :

if(!isset($_GET["page"])) 
{ 
    $page=1; 

    include ("connect.php");  
} 
else 
{ 
    $page= intval($_GET['page']); 
}

You include the 'connect.php' script only when the page isn't specified in the query string. Is this correct?

Stephen Curran
Seems like this is the answer.
Typeoneerror
A: 

alt text

I want to the code as in the picture ..

So that if you click on the number 1 to turn to a new page containing the values 4 and No. 2 if you also turn to a new page containing the 4 other values and so on.

What is wrong with this code even shows me output as in the picture

sandy
@sandy - when you have additional material that explains your question, please edit your original question and add it there - adding this material as an answer is less concise and can be confusing. I've added it to your question for you, so you can feel free to delete this answer.
Peter Bailey