Avatar billede volturex Nybegynder
09. juli 2008 - 20:47 Der er 1 kommentar

Udprintning af sql uden resten af siden vises.

Hejsa.

Jeg står med et mindre problem her. Jeg vil gerne kunne udskrive mine søge resultater/detaljer til min printer uden resten af siden bliver skrevet med. Nedenståemde er min kode. et eksempel på indfletning af sådan ville være rart, tak ;)

<?php
session_start();

require("brugtemotorer_connect.php");

$Link = mysql_connect ($Host, $User, $Password);
mysql_select_db($DBName, $Link);


// hardwired stuff here --------------------------
$THISuniqueID = "brugtemotorer_3317";
$lineIndex = 0;
$linkCount = 0;
$itemNumber = 0;
$get = 0;
$post = 0;
$newID = 0;
$prefix = "";
$suffix = "";
$RFvar = "";

$rows_per_page = 50;
$asapPages = 1;
$screen = 1;
$preOrder = " ORDER BY brugtemotorer.";

$thumb_suffix = "";

//below gets the ascending / descending going
//below is for the first time
if(!isset($HTTP_SESSION_VARS['ASCDESC_brugtemotorer_3317']))
{
    $ASCDESC = " ASC";
    $HTTP_SESSION_VARS['ASCDESC_brugtemotorer_3317'] = $ASCDESC;
}
else
{
  //below is if session is set and we have clicked on a heading
  if(isset($HTTP_GET_VARS['asapSB']))
  {
        if($HTTP_GET_VARS['asapSB'] == $HTTP_SESSION_VARS['asapSB_brugtemotorer_3317'])
      {
        // below is if we have clicked on the same heading
          if($HTTP_SESSION_VARS['ASCDESC_brugtemotorer_3317'] == " ASC")
              $ASCDESC = " DESC";
            else
              $ASCDESC = " ASC";

            $HTTP_SESSION_VARS['ASCDESC_brugtemotorer_3317'] = $ASCDESC;
      }
        else
      {
        // below is if we have clicked on a different heading
            $ASCDESC = " ASC";
            $HTTP_SESSION_VARS['ASCDESC_brugtemotorer_3317'] = $ASCDESC;
        }
  }
    else
    {
      $ASCDESC = $HTTP_SESSION_VARS['ASCDESC_brugtemotorer_3317'];
    }
}

if ($ASCDESC == " ASC")
  $asapWD = "&#x25BC;";
else
  $asapWD = "&#x25B2;";

// below gets the sortby going
if(isset($HTTP_GET_VARS['asapSB']))
{
  $asapSB = $HTTP_GET_VARS['asapSB'];
    $HTTP_SESSION_VARS['asapSB_brugtemotorer_3317'] = $asapSB;
}
else
{
  if(!isset($HTTP_SESSION_VARS['asapSB_brugtemotorer_3317']))
  {
      $asapSB = "field2";
      $HTTP_SESSION_VARS['asapSB_brugtemotorer_3317'] = $asapSB;
  }
    else
    {
      $asapSB = $HTTP_SESSION_VARS['asapSB_brugtemotorer_3317'];
    }
}
// keyword functions here ------------------------
function Exact($whereclause,$fieldname,$strInput,$selCrit)
{
  $whereclause = $whereclause . " (" . $fieldname . " LIKE '";
    $whereclause = $whereclause . $strInput . "') AND ";
    //echo "<br>" . $whereclause;
    return $whereclause;
}

function Keywrd($whereclause,$fieldname,$strInput,$selCrit)
{
  $arrSearch = explode(" ",$strInput);
    $strCombine = implode("%') " . $selCrit . " (" . $fieldname . " LIKE '%",$arrSearch);
  $whereclause = $whereclause . " (" . $fieldname . " LIKE '%" . $strCombine . "%') AND ";
    //echo "<br>" . $whereclause;
    return $whereclause;
}
// end keyword functions
// iframe stuff here ------------------------------
if (isset($HTTP_GET_VARS['asapIfr']))
{
    $asapIfr = $HTTP_GET_VARS['asapIfr'];
    $HTTP_SESSION_VARS['asapIfr_brugtemotorer_3317'] = $asapIfr;
}

if (isset($HTTP_SESSION_VARS['asapIfr_brugtemotorer_3317']))
    $asapIfr = $HTTP_SESSION_VARS['asapIfr_brugtemotorer_3317'];

if(isset($HTTP_GET_VARS['asapNOIfr']))
{
        unset($asapIfr);
        unset($HTTP_SESSION_VARS['asapIfr_brugtemotorer_3317']);
}

// looking for uniqueID information here ---------------------------
if (!isset($HTTP_SESSION_VARS['uniqueID_brugtemotorer_3317']))
{
    $uniqueID = "brugtemotorer_3317";
    $uniqueID_brugtemotorer_3317 = $uniqueID;
    $HTTP_SESSION_VARS['uniqueID'] = $uniqueID;
}
if (isset($HTTP_SESSION_VARS['uniqueID_brugtemotorer_3317']))
{
    if ($HTTP_SESSION_VARS['uniqueID_brugtemotorer_3317'] <> $THISuniqueID)
    {
        $newID = 1;
        $HTTP_SESSION_VARS['uniqueID_brugtemotorer_3317'] = $THISuniqueID;
    }
}

// looking for related field here
if (isset($HTTP_GET_VARS['asapRF']))
{
  $asapRF = $HTTP_GET_VARS['asapRF'];
  if ($asapRF <> "")
  {
      $RFvar = $HTTP_GET_VARS['RFvar'];
      switch ($asapRF) {
        case "field1";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field2";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field3";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field4";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field5";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field6";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field7";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field8";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field9";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field10";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field11";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field12";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "field13";
        $RFvar = "'" . $RFvar . "'";
          break;
        case "ID";
        $RFvar = $RFvar;
        break;
    }
      $get = 1;
  }
}

// looking for variables from url HTTP_GET_VARS ------------------------------
if (isset($HTTP_GET_VARS['begin_search']))
{
    $get = 1;
}
if (isset($HTTP_GET_VARS['field2']))
{
    $field2 = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['field2'] : addslashes($HTTP_GET_VARS['field2']);
    $get = 1;
}

if ($get == 1)
{
    $whereclause = "WHERE ";

    //this is strictly for a related field
    if ($asapRF <> "")
      $whereclause = $whereclause . "brugtemotorer." . $asapRF . " = " .  $RFvar . " AND ";

    if (isset($field2))
        $whereclause = $whereclause . "brugtemotorer.field2 LIKE '%" . $field2 . "%' AND ";
    if ( substr($whereclause,-5) == " AND ")
        $whereclause = substr_replace($whereclause,"",-5);  // strip off ' AND'
    elseif ( substr($whereclause,-4) == " OR ")
        $whereclause = substr_replace($whereclause,"",-4);  // strip off ' OR'
    else
        $whereclause = substr_replace($whereclause,"",-6);  // strip off 'WHERE '

        $whereclause_brugtemotorer_3317 = $whereclause;  // sets unique whereclause
    if (!isset($HTTP_SESSION_VARS['whereclause_brugtemotorer_3317']))
        $HTTP_SESSION_VARS['whereclause_brugtemotorer_3317'] = $whereclause;
    else
        $HTTP_SESSION_VARS['whereclause_brugtemotorer_3317'] = $whereclause;

    $fullOrderBy = " ORDER BY brugtemotorer.field2";

    $fullOrderBy_brugtemotorer_3317 = $fullOrderBy;  // sets unique fullOrderBy

    if (!isset($HTTP_SESSION_VARS['fullOrderBy_brugtemotorer_3317']))
        $HTTP_SESSION_VARS['fullOrderBy_brugtemotorer_3317'] = $fullOrderBy;
    else
        $HTTP_SESSION_VARS['fullOrderBy_brugtemotorer_3317'] = $fullOrderBy;
}

// looking for variables from search form HTTP_POST_VARS -----------------------------
if (isset($HTTP_POST_VARS['field2']))
{
    $field2 = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['field2'] : addslashes($HTTP_POST_VARS['field2']);
    $post = 1;
}

if ($post == 1)
{
    $whereclause = "WHERE ";
    if ($field2 <> "")
        $whereclause = $whereclause . "brugtemotorer.field2 LIKE '%" . $field2 . "%' AND ";
    if ( substr($whereclause,-5) == " AND ")
        $whereclause = substr_replace($whereclause,"",-5);  // strip off ' AND'
    elseif ( substr($whereclause,-4) == " OR ")
        $whereclause = substr_replace($whereclause,"",-4);  // strip off ' OR'
    else
        $whereclause = substr_replace($whereclause,"",-6);  // strip off 'WHERE '

        $whereclause_brugtemotorer_3317 = $whereclause;  // this sets unique whereclause

    if (!isset($HTTP_SESSION_VARS['whereclause_brugtemotorer_3317']))
        $HTTP_SESSION_VARS['whereclause_brugtemotorer_3317'] = $whereclause;
    else
        $HTTP_SESSION_VARS['whereclause_brugtemotorer_3317'] = $whereclause;

    $fullOrderBy = " ORDER BY brugtemotorer.field2";

    $fullOrderBy_brugtemotorer_3317 = $fullOrderBy;  // this sets unique fullOrderBy

    if (!isset($HTTP_SESSION_VARS['fullOrderBy_brugtemotorer_3317']))
        $HTTP_SESSION_VARS['fullOrderBy_brugtemotorer_3317'] = $fullOrderBy;
    else
        $HTTP_SESSION_VARS['fullOrderBy_brugtemotorer_3317'] = $fullOrderBy;
}

// looking to see if we've received some commands to orderby a certain field //
if (isset($HTTP_GET_VARS['asapSB']))
{
    $asapSB = $HTTP_GET_VARS['asapSB'];
    $fullOrderBy = $preOrder . $asapSB . $ASCDESC;
    $HTTP_SESSION_VARS['fullOrderBy_brugtemotorer_3317'] = $fullOrderBy;
    $whereclause = $HTTP_SESSION_VARS['whereclause_brugtemotorer_3317'];
}

// looking to see if search without search form and reusing session if set //
if ($get == 0 && $post == 0)
{
    if (!isset($HTTP_SESSION_VARS['fullOrderBy_brugtemotorer_3317']))
    {
        $fullOrderBy = " ORDER BY brugtemotorer.field2";
        $fullOrderBy_brugtemotorer_3317 = $fullOrderBy;  // sets unique fullOrderBy
        $HTTP_SESSION_VARS['fullOrderBy_brugtemotorer_3317'] = $fullOrderBy;
    }
    else
    {
        if($newID == 1)
        {
            $fullOrderBy = " ORDER BY brugtemotorer.field2";
            $HTTP_SESSION_VARS['fullOrderBy_brugtemotorer_3317'] = $fullOrderBy;
        }
        else
            $fullOrderBy = $HTTP_SESSION_VARS['fullOrderBy_brugtemotorer_3317'];
    }

    if (!isset($HTTP_SESSION_VARS['whereclause_brugtemotorer_3317']))
    {
        $whereclause = "WHERE ";
        if ( substr($whereclause,-5) == " AND ")
            $whereclause = substr_replace($whereclause,"",-5);  // strip off ' AND'
        elseif ( substr($whereclause,-4) == " OR ")
            $whereclause = substr_replace($whereclause,"",-4);  // strip off ' OR'
        else
            $whereclause = substr_replace($whereclause,"",-6);  // strip off 'WHERE '

            $whereclause_brugtemotorer_3317 = $whereclause;  // sets unique whereclause

            $HTTP_SESSION_VARS['whereclause_brugtemotorer_3317'] = $whereclause;
    }
    else
    {
        if($newID == 1)
        {
            $whereclause = "WHERE ";
            if ( substr($whereclause,-5) == " AND ")
                $whereclause = substr_replace($whereclause,"",-5);  // strip off ' AND'
            elseif ( substr($whereclause,-4) == " OR ")
                $whereclause = substr_replace($whereclause,"",-4);  // strip off ' OR'
            else
                $whereclause = substr_replace($whereclause,"",-6);  // strip off 'WHERE '
                $HTTP_SESSION_VARS['whereclause_brugtemotorer_3317'] = $whereclause;
        }
        else
            $whereclause = $HTTP_SESSION_VARS['whereclause_brugtemotorer_3317'];
    }
}

// for deleting multiple records
if(isset($HTTP_POST_VARS['Delete']))
{
  $remove = $HTTP_POST_VARS['Delete'];
  $n        = count($remove);
  $i        = 0;

  while ($i < $n)
  {
      $delQuery = "DELETE FROM brugtemotorer WHERE brugtemotorer.ID = " . $remove[$i];
      if ($Result = mysql_query($delQuery, $Link))
    {
          $i++;
    }
  }
}
$Count = "SELECT ID,field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11,field12,field13 FROM brugtemotorer " . $whereclause;
$Recordset = mysql_query($Count, $Link);

if (!isset($total_records))
{
    $total_records = mysql_num_rows($Recordset);
    $total_results = $total_records - 1;
    $total_results_brugtemotorer_3317 = $total_results;  // sets unique total_results

    if (!isset($HTTP_SESSION_VARS['total_results_brugtemotorer_3317']))
            $HTTP_SESSION_VARS['total_results_brugtemotorer_3317'] = $total_results;
    else
            $HTTP_SESSION_VARS['total_results_brugtemotorer_3317'] = $total_results;
}
$asapPages = ceil($total_records / $rows_per_page);
mysql_free_result($Recordset);


//  looking for request of screen number (alias Page Number) //
if (!isset($HTTP_GET_VARS['screen']))
    $screen = 1;
else
    $screen = $HTTP_GET_VARS['screen'];

// loooking for screen number from delete function
if (isset($HTTP_POST_VARS['screen']))
    $screen = $HTTP_POST_VARS['screen'];

$start = ($screen - 1) * $rows_per_page;

// Querying database here //

$Query = "SELECT ID,field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11,field12,field13";
$Query = $Query . " FROM brugtemotorer " . $whereclause . $fullOrderBy . " LIMIT $start, $rows_per_page";
$Recordset = mysql_query($Query, $Link);
$rows = mysql_num_rows($Recordset);

// this is the total number of chapters holding the pages //
$asapChapters = ceil($asapPages / 10);

// this is the current chapter //
$asapChapter = ceil($screen * .1);

// this would be the first page in the current chapter //
$start10 = ($asapChapter * 10) - 9;

// this would be the last page in the current chapter //
$stop10 = $asapChapter * 10;
if ($stop10 > $asapPages)
{
  $stop10 = $asapPages;
}

$next1 = $stop10 + 1;
$previous1 = $start10 - 1;

$Next = "brugtemotorer_search_results.php?screen=" . $next1;
$Previous = "brugtemotorer_search_results.php?screen=" . $previous1;
    $prefix = "location.href='";
    $suffix = "'";
?>
<html>
<head>
<title>Havnens Marine Center A/S</title>

<SCRIPT LANGUAGE=JAVASCRIPT>
<!-- Hide script form old browsers
var win=null;
function newWindow(url) {
var winl = (screen.width-500)/2;
var wint = (screen.height-500)/2;
mapWindow = window.open(url, 'ASaP','left='+winl+',top='+wint+',width=500,height=500,scrollbars=yes')
}

// End hiding script from old browsers -->
</SCRIPT>

<meta name="generator" content="Data ASap v3.3.85">
<link rel="stylesheet" href="brugtemotorer_styles.css" type="text/css">
</head>
<body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0 link='##4E5B70' alink='##4E5B70' vlink='##4E5B70'>
<?php
    require("brugtemotorer_header.inc");
?>
<div align="center">
<table width="650" cellpadding="0" cellspacing="0">
<tr>
<td align="left">
<a href="/brugtemotorer_search_results.php?begin_search"><font size="2" color="#FFFFFF">Klik her for at komme tilbage til alle brugte motorer.</a>
</td>
<td align="right">
<a href="java script:window.close()"><font size="2" color="#FFFFFF">Luk</a>
</td>
</tr>
</table>
<table width="950px" cellpadding="0" cellspacing="0">
<tr>
<td>

<table width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="2" cellspacing="0">
        <tr>
          <td width="10" class="strip">&nbsp;</td>
          <td width="10" class="strip">&nbsp;</td>
          <td class="strip" onmouseover="this.className='strip',this.style.cursor='pointer'" onclick="location.href='brugtemotorer_search_results.php?asapSB=field1&screen=<?php echo $screen; ?>',this.className='strip'">
          <?php
          if ($asapSB == 'field1')
          {
          ?>
          <?php echo $asapWD; ?>
          <?php
          }
          ?>
          </td>
          <td class="strip" onmouseover="this.className='strip',this.style.cursor='pointer'" onclick="location.href='brugtemotorer_search_results.php?asapSB=field2&screen=<?php echo $screen; ?>',this.className='strip'">
          <?php
          if ($asapSB == 'field2')
          {
          ?>
          <?php echo $asapWD; ?>
          <?php
          }
          ?>
          <span class='strip'>Model</span>
          </td>
          <td class="strip" onmouseover="this.className='strip',this.style.cursor='pointer'" onclick="location.href='brugtemotorer_search_results.php?asapSB=field3&screen=<?php echo $screen; ?>',this.className='strip'">
          <?php
          if ($asapSB == 'field3')
          {
          ?>
          <?php echo $asapWD; ?>
          <?php
          }
          ?>
          <span class='strip'>Pris i Kr. incl. moms</span>
          </td>
</tr>
<?php
for ($i = 0; $i < $rows; $i++)
{
    while ($Row = mysql_fetch_assoc($Recordset))
    {
        $newitemNumber = (($screen - 1) * $rows_per_page) + $itemNumber;
        $resultLink = $prefix . "brugtemotorer_detail.php?key=" . $Row['ID'] . "&itemNumber=" . $newitemNumber . $suffix;
        if ($lineIndex % 2 == 0)
        {
?>
<tr class="data1" onmouseover="this.style.cursor='pointer'" onmouseout="this.className='data1'" onclick="<?php echo $resultLink; ?>">
          <td width="10">&nbsp;</td>
          <td width="100" class="data1">
        <img src='<?php echo $thumb_prefix?><?php echo $Row['field1']; ?><?php echo $thumb_suffix?>' width='90' border='1'>
        </td>
          <td>&nbsp;</td>
          <td><?php echo $Row['field2']; ?></td>
          <td><?php echo $Row['field3']; ?></td>
</tr>
<?php
}
else
{
?>
<tr class="data2" onmouseover="this.style.cursor='pointer'" onmouseout="this.className='data2'" onclick="<?php echo $resultLink; ?>">
          <td width="10">&nbsp;</td>
          <td width="100" class="data2">
        <img src='<?php echo $thumb_prefix?><?php echo $Row['field1']; ?><?php echo $thumb_suffix?>' width='90' border='1'>
        </td>
          <td>&nbsp;</td>
          <td><?php echo $Row['field2']; ?></td>
          <td><?php echo $Row['field3']; ?></td>
</tr>
<?php
  }
  $itemNumber = $itemNumber + 1;
  $lineIndex = $lineIndex + 1;
}
}
?>
</table>
    </td>
  </tr>
  <tr>
    <td class="strip">&nbsp;Antal =&nbsp;<?php echo $total_records; ?></td>
  </tr>
</table>





<?php
$previousurl = "brugtemotorer_search_results.php?" . SID . "&screen=" . ($screen - 1);
$nexturl = "brugtemotorer_search_results.php?" . SID . "&screen=" . ($screen + 1);
?>

<div align="center">
<table width="650" cellpadding="0" cellspacing="0">
<tr>
<td align="left">
<a href="/brugtemotorer_search_results.php?begin_search"><font size="2" color="#FFFFFF">Klik her for at komme tilbage til alle brugte motorer.</a>
</td>
<td align="right">
<a href="java script:window.close()"><font size="2" color="#FFFFFF">Luk</a>
</td>
</tr>
</table>

<div align="center">
<table border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="35%">
        <div align="center">
                  <?php
if ($screen > 1 && $screen < $asapPages)
{
?>
                <div align="center">
                  <p><a class="button" href="<?php echo $previousurl; ?>">Forrige</a></p>
                </div>
         
        </div>
      </td>
      <td width="30%">
        <div align="center"> </div>
      </td>
      <td width="35%">
        <div align="center">
<?php
}
elseif ($screen > 1 && $screen == $asapPages)
{
?>
                <div align="center">
                  <p><a class="button" href="<?php echo $previousurl; ?>">Forrige</a></p>
                </div>
<?php
}
elseif ($screen < $asapPages && $screen == 1)
{
?>
                <div align="center">
                  <p><a class="button" href="<?php echo $nexturl; ?>">Næste</a></p>
                </div>
<?php
}
if ($screen < $asapPages && $screen > 1)
{
?>
                <div align="center">
                  <p><a class="button" href="<?php echo $nexturl; ?>">Næste</a></p>
                </div>
<?php
}
?>
        </div>
      </td>
    </tr>
  </table>
  <br>
<?php
if ($total_records == 0)
{
?>
  <b><span class='pagetext'>Undskyld, ingen detaljer matcher dine søge kriterier. Klik tilbage og prøv igen. </span></b>
<?php
}
?>
</div>
<div align="center">
<table cellpadding="0" cellspacing="2">
<?php
if ($asapChapter > 1)
{
?>
<td>
<a class='links' href='<?=$Previous?>'>10 Forrige</a>
</td>
<?php
}
// loops through entire range of numbers

for ($i = $start10; $i <= $stop10; $i++)
{
$URL = "brugtemotorer_search_results.php?screen=" . $i;
  if ($i == $screen)
    {
    ?>
    <td>
    <table border="1" bordercolor="#000000" cellpadding="0" cellspacing="0">
    <tr>
    <td class="pageselected" bgcolor="#cccccc" valign="bottom" width="15"><?php echo $i; ?></td>
    </tr>
    </table>
    </td>
    <?php
    }
    else
    {
    ?>
  <td valign="bottom"><b>
  <a class='links' href='<?=$URL?>'><?=$i?></a></b>
    </td>
    <?php
    }
}
if ($asapChapter < $asapChapters)
{
?>
<td>
<a class='links' href='<?=$Next?>'>Næste 10</a>
</td>
<?php
}
?>
</tr>
</table>
<?php
mysql_free_result($Recordset);
?>
</td>
</tr>
</table>
</div>
</body>
</html>
Avatar billede jakobdo Ekspert
10. juli 2008 - 08:30 #1
Ikke at jeg gider kaste mig over så lang en kode.
Men jeg ville jo mene du burde lave noget i stil med:

side.php?print=yes

Og så nede igennem siden lave:

if(!isset($_GET['print'])){
//ALT DET SOM IKKE SKAL VISES VED PRINT
}else{
//DET SOM SKAL VISES VED PRINT
}
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester