Jump to content

custom php script a lil fudgy


Jaguar75

Recommended Posts

i cant get the next button to fire on this php page, however it works on everything other than this page

 

 

 

<?php

require_once('include/b3connect.php');

$requiredlevel = lvl_clients;

require_once('include/authorize.php');

require_once('include/navbar.php');

//set page vars and defaults

$currentpage = $http_server_vars["php_self"];

$pagenumber = 0;

$orderby = "id";

$sort = "desc";

$mode = 0;

//find out what we are seaching and how

$field = get_val("field");//what

$search = get_val("search");//how

//need to adjust sql depending upon how we are searching

if($search)

{

//change the mode to 1 or 3, if its alias then its 3

if($field == "alias")

{

//since we changed the sql to rename the alias to name, we want to swtch

$field = "name";

$mode = 3;

}

else

$mode = 1;

 

//the search field could be numeric or text, this changes the sql

if(is_numeric($search))

$value = $search;

else

$value = "'%".$search."%'";

}

//find out about the field, if its a level search that comes from tbl2

if($field != 'level')

$field = "t1.$field";

else

$field = "t2.$field";

//check post values we want to know the page number

if ($_GET['pagenumber'])

  $pagenumber = $_GET['pagenumber'];

//check where we are starting

$startrow = $pagenumber * $display_rows;

//check post values we want to know the order by in sql clause

if ($_GET['orderby'])

{ $orderby = (get_magic_quotes_gpc()) ? $_GET['orderby'] : addslashes($_GET['orderby']);

 

//find out about the order by, if its level then that comes from tbl2

if($orderby != 'level')

$orderby = "t1.$orderby";

else

$orderby = "t2.$orderby"; 

}

//check post values we want to know the sort method (asc or desc)

if ($_GET['sort'])

  $sort = (get_magic_quotes_gpc()) ? $_GET['sort'] : addslashes($_GET['sort']);

//check post values we want to know the mode is (0,1,2)

if ($_GET['mode'])

  $mode = (get_magic_quotes_gpc()) ? $_GET['mode'] : addslashes($_GET['mode']);

//make these global vars

global $mode, $sort, $orderby, $pagenumber;

//build the sql statement

switch ($mode)

{

case 0:

 

//build the sql statement for all possible entries

$sql = "select

t1.*,

t2.level

from clients t1

 

left join groups t2

on t2.id = t1.group_bits

";

break;

 

case 1:

 

//build the sql statement for search entry

$sql = "select

t1.*,

t2.level

from clients t1

 

left join groups t2

on t2.id = t1.group_bits

 

where $field  like $value

";

break;

 

case 2:

 

//build the sql statement aliases

$sql = "select

t1.*,

t2.level

from

(select

s2.id,

s1.alias name,

s2.ip,

s2.guid,

s2.pbid,

s2.connections,

s1.time_add,

s1.time_edit,

s2.group_bits

 

from aliases s1

 

inner join clients s2

on s2.id = s1.client_id

) t1

 

left join groups t2

on t2.id = t1.group_bits

";

break;

 

case 3:

 

//build the sql statement aliases

$sql = "select

t1.*,

t2.level

from

(select

s2.id,

s1.alias name,

s2.ip,

s2.guid,

s2.pbid,

s2.connections,

s1.time_add,

s1.time_edit,

s2.group_bits

 

from aliases s1

 

inner join clients s2

on s2.id = s1.client_id

) t1

 

left join groups t2

on t2.id = t1.group_bits

 

where $field  like $value

";

break;

}

//put into resource

$results = mysql_query($sql, $b3_connect) or die(mysql_error());

//calc number of rows from resource

$totalrows = mysql_num_rows($results);

//find out total number of pages by getting the rows

$totalpages= ceil($totalrows/$display_rows)-1;

//again, but this time limit the return

$limit = " order by $orderby $sort limit $startrow , $display_rows";

//put into resource again, this time with limits

$results = mysql_query($sql.$limit, $b3_connect) or die(mysql_error());

 

?>

<script language="javascript">

<!--

//tmtc_winopen

var aliasresults;

//tmtc_winopenend

 

function tmt_winopen(u,id,f,df){

if(eval(id)==null||eval(id+".closed")){

eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}

else if(df){eval(id+".focus()");}

else{eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}

}

//-->

</script>

</head>

<body>

<table>

<tr>

  <td>

<form action="clients.php" method="get" name="search" id="search">

  search by:

<select name='field'>

<option value='name'  <?php if ($mode == 0) echo 'SELECTED' ?> >Name</option>

<option value='alias' <?php if ($mode == 1) echo 'SELECTED' ?> >Alias</option>

<option value='id'   <?php if ($mode == 2) echo 'SELECTED' ?> >B3ID</option>

<option value='ip'   <?php if ($mode == 3) echo 'SELECTED' ?> >IP</option>

<option value='level' <?php if ($mode == 4) echo 'SELECTED' ?> >Level</option>

<option value='pbid'  <?php if ($mode == 5) echo 'SELECTED' ?> >PB Guid</option>

<option value='guid'  <?php if ($mode == 6) echo 'SELECTED' ?> >Guid</option>

 

</select>

<input name="search" type="text" id="search">

<input type="submit" name="submit" value="search">   

[<a href="clients.php?">clear search</a>]

</form>

</td>

</tr>

</table>

<table>

<?php

//build the headers at top w/ sort and order methods

echo "<tr>";

buildcolumn("Client ID:", "id");

buildcolumn("Name:", "name");

buildcolumn("IP:", "ip");

buildcolumn("Level:", "level");

buildcolumn("Connections:", "connections");

buildcolumn("First Join:", "time_add");

buildcolumn("Last Logon:", "time_edit");

echo "</tr>";

 

//build the detail

while ($rowdata = mysql_fetch_array($results))

{ //change a null to 0 value

if(!$rowdata['level']) $rowdata['level'] = 0;

?>       

<tr>

  <td><?php echo $rowdata['id']; ?></td>

  <td><a href='clientdetails.php?&id=<?php echo $rowdata['id']; ?>'><?php echo $rowdata['name']; ?></a></td>

  <td><?php echo $rowdata['ip']; ?></td>

  <td><?php echo $rowdata['level']; ?></td>

  <td><?php echo $rowdata['connections']; ?></td>

  <td title='<?php echo date('l, m/d/y (h:i)',$rowdata['time_add']); ?>'><?php echo datediff('h',date("Y-m-d H:i:s",$rowdata['time_add']),date("Y-m-d H:i:s"), FALSE); ?></td>  

  <td title='<?php echo date('l, m/d/y (h:i)',$rowdata['time_edit']); ?>'><?php echo datediff('h',date("Y-m-d H:i:s",$rowdata['time_edit']),date("Y-m-d H:i:s"), FALSE); ?></td>

</tr>

<?php

}

?>

</table>

<table>

<tr>         

<td width="100%" colspan="4" align="center">records: <?php echo ($startrow + 1) ?> to <?php echo min($startrow + $display_rows, $totalrows) ?> from <?php echo $totalrows ?> </td>

</tr>

<tr>

<?php

//build the page up page down stuff

if ($pagenumber > 0)           

echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=0'>first</a></td>";

 

if ($pagenumber > 0)

echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=".($pagenumber - 1)."'>previous</a></td>";

 

    if ($pagenumber < $totalpages)

echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=".($pagenumber + 1)."'>next</a></td>";

 

 

      if ($pagenumber < $totalpages)

echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order$sort&pagenumber=$totalpages'>last</a></td>";

?>

</tr>

</table>

</body>

</html>

<?php mysql_free_result($results); ?>

Link to comment
https://forums.phpfreaks.com/topic/151869-custom-php-script-a-lil-fudgy/
Share on other sites

<?php
require_once('include/b3connect.php'); 
$requiredlevel = lvl_clients;
require_once('include/authorize.php');
require_once('include/navbar.php');
//set page vars and defaults
$currentpage = $http_server_vars["php_self"];
$pagenumber = 0;
$orderby = "id";
$sort = "desc";
$mode = 0;
//find out what we are seaching and how
$field = get_val("field");//what
$search = get_val("search");//how
//need to adjust sql depending upon how we are searching
if($search)
   {   
      //change the mode to 1 or 3, if its alias then its 3         
      if($field == "alias")
      {   
         //since we changed the sql to rename the alias to name, we want to swtch         
         $field = "name";
         $mode = 3;
      }
      else
         $mode = 1;
      
      //the search field could be numeric or text, this changes the sql      
      if(is_numeric($search))
         $value = $search;
      else
         $value = "'%".$search."%'";
   }
//find out about the field, if its a level search that comes from tbl2
if($field != 'level')
   $field = "t1.$field";
else
   $field = "t2.$field";
//check post values we want to know the page number
if ($_GET['pagenumber'])
  $pagenumber = $_GET['pagenumber'];
//check where we are starting
$startrow = $pagenumber * $display_rows;
//check post values we want to know the order by in sql clause
if ($_GET['orderby'])
   { $orderby = (get_magic_quotes_gpc()) ? $_GET['orderby'] : addslashes($_GET['orderby']);
   
   //find out about the order by, if its level then that comes from tbl2   
   if($orderby != 'level')
      $orderby = "t1.$orderby";
   else
      $orderby = "t2.$orderby";  
   }
//check post values we want to know the sort method (asc or desc)
if ($_GET['sort'])
  $sort = (get_magic_quotes_gpc()) ? $_GET['sort'] : addslashes($_GET['sort']);
//check post values we want to know the mode is (0,1,2)
if ($_GET['mode'])
  $mode = (get_magic_quotes_gpc()) ? $_GET['mode'] : addslashes($_GET['mode']);
//make these global vars
global $mode, $sort, $orderby, $pagenumber;
//build the sql statement
switch ($mode)
   {
      case 0:
      
      //build the sql statement for all possible entries      
      $sql = "select 
            t1.*, 
            t2.level
         from clients t1

         left join groups t2
         on t2.id = t1.group_bits          
         ";
      break;
   
      case 1:
      
      //build the sql statement for search entry         
      $sql = "select 
            t1.*, 
            t2.level
         from clients t1

         left join groups t2
         on t2.id = t1.group_bits 

         where $field  like $value
         ";
      break;
      
      case 2:
      
      //build the sql statement aliases         
      $sql = "select 
            t1.*,
            t2.level
         from 
            (select 
               s2.id,
               s1.alias name, 
               s2.ip,               
               s2.guid, 
               s2.pbid, 
               s2.connections, 
               s1.time_add, 
               s1.time_edit,
               s2.group_bits
               
            from aliases s1 
            
            inner join clients s2
            on s2.id = s1.client_id
            ) t1

         left join groups t2
         on t2.id = t1.group_bits
         ";
      break;
      
      case 3:
      
      //build the sql statement aliases         
      $sql = "select 
            t1.*,
            t2.level
         from 
            (select 
               s2.id,
               s1.alias name, 
               s2.ip,               
               s2.guid, 
               s2.pbid, 
               s2.connections, 
               s1.time_add, 
               s1.time_edit,
               s2.group_bits
               
            from aliases s1 
            
            inner join clients s2
            on s2.id = s1.client_id
            ) t1

         left join groups t2
         on t2.id = t1.group_bits
         
         where $field  like $value
         ";
      break;
   }
//put into resource
$results = mysql_query($sql, $b3_connect) or die(mysql_error());
//calc number of rows from resource
$totalrows = mysql_num_rows($results);
//find out total number of pages by getting the rows
$totalpages= ceil($totalrows/$display_rows)-1;
//again, but this time limit the return
$limit = " order by $orderby $sort limit $startrow , $display_rows";
//put into resource again, this time with limits
$results = mysql_query($sql.$limit, $b3_connect) or die(mysql_error());

?>
<script language="javascript">
<!--
//tmtc_winopen
var aliasresults;
//tmtc_winopenend

function tmt_winopen(u,id,f,df){
   if(eval(id)==null||eval(id+".closed")){
   eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
   else if(df){eval(id+".focus()");}
   else{eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}
//-->
</script>
</head>
<body>
<table>
   <tr>
     <td>      
      <form action="clients.php" method="get" name="search" id="search">
        search by:
         <select name='field'>
            <option value='name'  <?php if ($mode == 0) echo 'SELECTED' ?>   >Name</option>
            <option value='alias' <?php if ($mode == 1) echo 'SELECTED' ?>   >Alias</option>
            <option value='id'     <?php if ($mode == 2) echo 'SELECTED' ?>   >B3ID</option>
            <option value='ip'     <?php if ($mode == 3) echo 'SELECTED' ?>   >IP</option>
            <option value='level' <?php if ($mode == 4) echo 'SELECTED' ?> >Level</option>
            <option value='pbid'  <?php if ($mode == 5) echo 'SELECTED' ?> >PB Guid</option>
            <option value='guid'  <?php if ($mode == 6) echo 'SELECTED' ?> >Guid</option>
            
         </select>
         <input name="search" type="text" id="search">
         <input type="submit" name="submit" value="search">    
         [<a href="clients.php?">clear search</a>]
      </form>
      </td>
   </tr>
</table>
<table> 
<?php       
   //build the headers at top w/ sort and order methods   
   echo "<tr>";
   buildcolumn("Client ID:", "id");
   buildcolumn("Name:", "name");
   buildcolumn("IP:", "ip");
   buildcolumn("Level:", "level");
   buildcolumn("Connections:", "connections");
   buildcolumn("First Join:", "time_add");
   buildcolumn("Last Logon:", "time_edit");
   echo "</tr>";
   
   //build the detail   
   while ($rowdata = mysql_fetch_array($results))
   {   //change a null to 0 value
      if(!$rowdata['level']) $rowdata['level'] = 0;
?>        
   <tr>
     <td><?php echo $rowdata['id']; ?></td>
     <td><a href='clientdetails.php?&id=<?php echo $rowdata['id']; ?>'><?php echo $rowdata['name']; ?></a></td>
     <td><?php echo $rowdata['ip']; ?></td>
     <td><?php echo $rowdata['level']; ?></td>
     <td><?php echo $rowdata['connections']; ?></td>
     <td title='<?php echo date('l, m/d/y (h:i)',$rowdata['time_add']); ?>'><?php echo datediff('h',date("Y-m-d H:i:s",$rowdata['time_add']),date("Y-m-d H:i:s"), FALSE); ?></td>     
     <td title='<?php echo date('l, m/d/y (h:i)',$rowdata['time_edit']); ?>'><?php echo datediff('h',date("Y-m-d H:i:s",$rowdata['time_edit']),date("Y-m-d H:i:s"), FALSE); ?></td>
   </tr>
<?php 
   } 
?>
</table>
<table>
<tr>          
   <td width="100%" colspan="4" align="center">records: <?php echo ($startrow + 1) ?> to <?php echo min($startrow + $display_rows, $totalrows) ?> from <?php echo $totalrows ?> </td>
</tr>
<tr>
<?php    
   //build the page up page down stuff   
   if ($pagenumber > 0)             
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=0'>first</a></td>";
   
   if ($pagenumber > 0) 
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=".($pagenumber - 1)."'>previous</a></td>";
   
      if ($pagenumber < $totalpages) 
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=".($pagenumber + 1)."'>next</a></td>";


      if ($pagenumber < $totalpages) 
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order$sort&pagenumber=$totalpages'>last</a></td>";
?>
</tr>
</table>
</body>
</html>
<?php mysql_free_result($results); ?>

probably doesn't have anything to do with your issue, but why do you repeat your IF statements twice instead of using brackets ?

 

change

<?php
   if ($pagenumber > 0)             
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=0'>first</a></td>";
   
   if ($pagenumber > 0) 
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=".($pagenumber - 1)."'>previous</a></td>";
   
      if ($pagenumber < $totalpages) 
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=".($pagenumber + 1)."'>next</a></td>";


      if ($pagenumber < $totalpages) 
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order$sort&pagenumber=$totalpages'>last</a></td>";
?>

to

<?php
   if ($pagenumber > 0)             
   {
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=0'>first</a></td>";
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=".($pagenumber - 1)."'>previous</a></td>";
   }
   if ($pagenumber < $totalpages) 
   {
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order=$sort&pagenumber=".($pagenumber + 1)."'>next</a></td>";
      echo "<td><a href='$currentpage?mode=$mode&orderby=".$_GET['orderby']."&order$sort&pagenumber=$totalpages'>last</a></td>";
   }
?>

i just tried using your code portion and that did not work. it advances to the next page, but the entire page is blank, theres nothing on there. my other pages work just fine when i hit next. its just this clients.php page that doesnt function properly

 

any other ideas?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.