Blätterfunktion für eBay Ergebnisseite

mediamacher

Mitglied
Hallo,
ich verwende folgendes Skript zur Auflistung meiner Ebay-Auktionen:
Code:
<html <?php echo HTML_PARAMS; ?>
<head>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<table border="0" width="100%" cellspacing="3" cellpadding="3">
  <tr>

    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
          </tr>
        </table></td>
      </tr>
      <tr>
      </tr>
      <tr>
        <td class="main">
<!-- ------------------------ ----------------- ebay anfang //-->
<?php


// Your Ebay Member Name
$ebayid = "MEMBERNAME";

// Display Thumbnails?
$thumbs = "1";  // 1 = yes 0 = no

// Path to Footer File - blank for none
$header = "header.php";

// Path to Footer File - blank for none
$footer = "footer.php";

// Table Border Color
$table_border_color = "#4C6B9C";

// Table Header Row Color
$table_header_color = "#E5E1D2";

// Table Alt Color Row 1
$table_row1_color = "#F0F3F8";

// Table Alt Color Row 2
$table_row2_color = "#DAE1EF";

// Ebay uses Pacific time zone use this to add hours for your time zone
$timezone = "9";

// Display Ended Auctions (-1 = Current, 1 - 30 = Up to 30 Days in the past)
$since = "-1";

//Sort By (Item Number = 1, Auction Start = 2, Auction End = 3, Current Price = 4, Newest First = 8,)
$sort = "3";

// Display how many per page - Set to a very high number like 999999 for all your listings
$limit = "9999999";

// Start our border table
echo "
	<TABLE border=\"0\" cellPadding=\"10\" cellSpacing=\"0\" width=\"430\">


";


// Build the ebay url
$URL = "http://cgi6.ebay.com/ws/eBayISAPI.dll?MfcISAPICommand=ViewListedItems&userid=$ebayid&since=$since&sort=$sort&rows=0";

// Where to Start grabbing and where to End grabbing
$Start = "Click on the column headers to sort";
// $End = "</p><SCRIPT SRC=\"http://include.ebay.com/aw/pics/js/stats/ss.js\"></SCRIPT><SCRIPT SRC=\"http://include.ebay.com/aw/pics/js/stats/ss2.js\"></SCRIPT><p>" or "indicates that auction has ended.";

// Open the file
$file = fopen("$URL", "r");

// Read the file

if (!function_exists('file_get_contents')) {
     $r = fread($file, 80000);
}
else {
    $r = file_get_contents($URL);
}


// Grab just the contents we want
$stuff = eregi("$Start(.*)$End", $r, $content);

// Get rid of some rubbish we don't need.
// And set things up to be split into lines and items.

$content[1] = ereg_replace("</a><table border=\"1\" cellpadding=\"3\".*</td><br></tr>","",$content[1]);
$content[1] = ereg_replace("<tr bgcolor=\"#CCCCFF\">.*High Bidder \/ Status","",$content[1]);
$content[1] = ereg_replace("<tr bgcolor=\"#CCCCFF\">.*High Bidder \/ Status","",$content[1]);
$content[1] = str_replace("</table>", "", $content[1]);
$content[1] = str_replace("</th>", "", $content[1]);
$content[1] = str_replace("\r\n", "", $content[1]);
$content[1] = str_replace("\n", "", $content[1]);
$content[1] = str_replace("\r", "", $content[1]);
$content[1] = str_replace("<td align=\"center\">", "", $content[1]);
$content[1] = str_replace("<td>", "", $content[1]);
$content[1] = str_replace("<td align=\"right\">", "", $content[1]);
$content[1] = str_replace("<font color=\"\">", "", $content[1]);
$content[1] = str_replace("</font>", "", $content[1]);
$content[1] = str_replace("<tr bgcolor=\"#F9F9F7\">", "", $content[1]);
$content[1] = str_replace("<tr bgcolor=\"#efefef\">", "", $content[1]);
$content[1] = str_replace("<tr bgcolor=\"#efefef\">", "", $content[1]);
$content[1] = str_replace("</td>", "[ITEMS]", $content[1]);
$content[1] = str_replace("</tr>", "[LINES]\n", $content[1]);


// Line used during debug
// echo "<hr>$content[1]<br><br> <hr>";


// Close the file
fclose($file);

$stuff = $content[1];

// Build our first array for EOF
$items = explode("[LINES]",$stuff);

// Loop through our lines

$count = "0";

foreach ($items as $listing) {
	// Break apart each line into individual items

	list($Item,$Start,$End,$Price,$Title ) = explode("[ITEMS]",$listing);

	//Use a countdown to get Time Left
	//We first need to break apart End and convert the months to numbers
	$seperate = split('[- :]', $End);

	$seperate[0] = str_replace("Jan", "1", $seperate[0]);
	$seperate[0] = str_replace("Feb", "2", $seperate[0]);
	$seperate[0] = str_replace("Mar", "3", $seperate[0]);
	$seperate[0] = str_replace("Apr", "4", $seperate[0]);
	$seperate[0] = str_replace("May", "5", $seperate[0]);
	$seperate[0] = str_replace("Jun", "6", $seperate[0]);
	$seperate[0] = str_replace("Jul", "7", $seperate[0]);
	$seperate[0] = str_replace("Aug", "8", $seperate[0]);
	$seperate[0] = str_replace("Sep", "9", $seperate[0]);
	$seperate[0] = str_replace("Oct", "10", $seperate[0]);
	$seperate[0] = str_replace("Nov", "11", $seperate[0]);
	$seperate[0] = str_replace("Dec", "12", $seperate[0]);

    	$month = $seperate[0];
    	$day = $seperate[1];
    	$year = $seperate[2];
    	$hour = $seperate[3]+$timezone;
    	$minute = $seperate[4];
	$second = $seperate[5];

	// mktime is the marked time, and time() is the current time.
	$target = mktime($hour,$minute,$second,$month,$day,$year);
	$diff = $target - time();

	$days = ($diff - ($diff % 86400)) / 86400;
	$diff = $diff - ($days * 86400);
	$hours = ($diff - ($diff % 3600)) / 3600;
	$diff = $diff - ($hours * 3600);
	$minutes = ($diff - ($diff % 60)) / 60;
	$diff = $diff - ($minutes * 60);
	$seconds = ($diff - ($diff % 1)) / 1;

	// next we put it into a presentable format
	$Time_Left =  $days . "T" . " &nbsp; " . $hours . "Std" . " &nbsp; " . $minutes . "Min";

	// and last we want to print auction ended when the auction has ended
	if ($seconds <= 0) {
		$TimeLeft = "Auction ended";
		}
	else {
		$TimeLeft = $Time_Left;
		}

		// Make sure we have content to print out and print it
		if ($Start && $End && $Title && ($count < $limit)) {

			$count++;

			$colour = ( $colour == "$table_row1_color" ) ? "$table_row2_color" : "$table_row1_color";

					$line = "<TR><TD bgcolor=\"$colour\" align=\"center\">$Item</TD><TD bgcolor=\"$colour\">$Title</TD><TD bgcolor=\"$colour\"><b>$Price</b></TD><TD bgcolor=\"$colour\"><div align=\"center\"><font color=\"#C9671C\"><b>$TimeLeft</b></font></TD></div></TR>\n";
                    preg_match('/item=([^"&]*)/', $line, $match);
					$itemnum=$match[1];


				// If Thumbnails are enabled show them
				 if ($thumbs == 1) {
	                echo "<TR><TD bgcolor=\"$colour\" align=\"center\"><a href=\"http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&item=$itemnum\" target=\"_blank\"><img src=\"http://thumbs.ebay.com/pict/$itemnum.jpg\" width=\"64\" height=\"64\" border=\"1\" style=\"border-color:#666666\"></a></TD><TD class=massTxt bgcolor=\"$colour\">$Title</TD><TD class=massTxt bgcolor=\"$colour\"><b>$Price</b></TD><TD class=massTxt bgcolor=\"$colour\"><div align=\"center\"></div></TD></TR>\n";
				 }

				// Otherwise just show the Bid Now link
				 else {
	                echo "<TR><TD bgcolor=\"$colour\" align=\"center\">$Item</TD><TD class=massTxt bgcolor=\"$colour\">$Title</TD><TD class=massTxt bgcolor=\"$colour\"><b>$Price</b></TD><TD class=massTxt bgcolor=\"$colour\"><div align=\"center\"><font color=\"#C9671C\"><b>$TimeLeft</b></font></div></TD></TR>\n";
				 }



		}

	}

// Wrap up the border table
echo "</TABLE></td></tr> </table>";



?>
<!-- ------------------------------------------ ebay ende //-->
        </td>
      </tr>

    </table></td>
    </table></td>
  </tr>
</table>

<!-- footer_eof //-->
<br>
</body>
</html>

Nun würde ich jedoch gerne das Ergebnis nicht auf einmal angezeigt bekommen, sondern mit einer Blätterfunktion, das z.B immer nur 8 Artikel angezeigt werden. Ist sas für einen Anfänger umsetzbar, oder soll ich lieber die Finger davon lassen...? Danke für jeden Tip!

Grüsse :-)
 
Ich hab mir den Code nicht durchgesehen (sorry, aber dazu ist er mir zu lang). Ich hab nur deine foreach()-Schleife gesehen. Ich weiß zwar nicht, was in $items steht, aber wenn du für jeden Eintrag einen Index hast (davon geh ich jetzt aus), kannst du folgenden Code einfügen:
PHP:
$pro_seite = 8;
$total_pages = ceil(count($items)/$pro_seite);
if(!(isset($_GET["site"]) AND $_GET["site"] < $total_pages))
   $_GET["site"] = 0;
$_GET["site"] = (int)$_GET["site"];
$counter = -1;

#Hier ist deine foreach
foreach($items as $listnings) {

   # Code für Blätterfunktion
   $counter++;
   if(!($counter >= ($_GET["site"] * $pro_seite)
      AND $counter < ($_GET["site"] * $pro_seite + $pro_seite)))
        continue;

   # dein restlicher Code

}
Mit dem Parameter $_GET["site"] kannst du steuern, welche Seite angezeigt werden soll. index.php?site=0 wäre die erste Seite, index.php?site=(seitenanzahl-1) wäre die letzte Seite. Wird der Parameter site nicht übergeben oder erhält einen ungültigen Wert (z.B. zu hoch), so wird die erste Seite angezeigt.
 
Zurück