PHP - Pagination For Xml Nodes
Hi all,
i have a very large xml file containing 2000 child nodes. i am using DOMDocument to read xml data but it shows whole data at once, i want to fetch first 20 or 30 nodes first time and then rest leave for pagination. is there any way to do so. to read only first few records from xml file. Thanks in advance... Similar TutorialsUsing HTML5 and CSS3, and jQuery is available.
I have a form block enclosing several hidden div blocks. jQuery will unhide a div block on selecting a control node -- presented as a tab.
I need to have a form input appear in more than one div block. That is, the HTML has four tabs, each tab making visible one of four div blocks. On one of the four div blocks, a specific form input is present.
I need for this specific input to also appear in one of the other div blocks. I want the one input, coded in one of the div blocks, to be "seen" and be operational in another div block -- but not have the HTML code for it located or duplicated there.
I thought about adding another input tag with the same name and showing the same value, but that is unworkable as it stands. I do not want to replicate or duplicate or otherwise make two separate inputs. But...
My current plan is to have two inputs of the same name, but the input in the hidden div block is disabled. By being disabled, the value of it will not be submitted. When the second div block becomes visible, the first input is disabled and the second is enabled. I would also need to copy the newly entered value into the other same-named input.
Could there be a better way?
Another way would be to move the specific input outside of the div blocks so that it is always visible. But I do not care to have this input visible for all the div blocks when each becomes visible.
Edited by bsmither, 08 January 2015 - 12:21 AM. Hello... I want to draw a nodes with arcs by using PHP. Is there any package available to do this? My nodes values are gene name. Please help me......... Hi I have searched around for a solution to this and either fail to grasp how to get it to work or just cannot find the correct solution. I have the following XML file: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <root> <product> <id>153</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Book 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Book 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Book 3</en> </title> </images> </product> <product> <id>154</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Book 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Book 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Book 3</en> </title> </images> </product> </root> $xml = 'example.xml'; // URL for feed. try{ $feed = new SimpleXMLElement($xml, null, true); }catch(Exception $e){ echo $e->getMessage(); exit; } $sql = 'INSERT INTO images (`id`, `url`) VALUES '; foreach($feed->property as $property){ $sql .= sprintf( "\n('%d', '%s'),", $property->id, mysql_real_escape_string($property->images->image->url) ); } $sql = rtrim($sql, ',') . ';'; What I need to do is loop through each of the image url nodes and insert them into my DB with the relevant id. Can somebody point me in the right direction with this please its driving me nuts! Regards GT Hi! I'm having trouble accessing data with simpleXML_load_file I have a working script that loads an XML-file and outputs in a proprietary format that I've written, but for some reason I can't get it to work with this second set of XML-files. Loading the file seems to work fine. I load the file into a variable, and can print the contents of the file using echo $xml -> asXML(); However, when I try to access a single node using: echo $xml->{'SOAP-ENV:Envelope'}->{'SOAP-ENV:Body'}->Order->OrderHeader->OrderNumber->BuyerOrderNumber;I get the following error: Notice: Trying to get property of non-object in C:\www\convert_uio.php on line 28 XML-file looks as follows: <?xml version="1.0" encoding="utf-8"?> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Header> <nseps:endpoints SOAP-ENV:mustUnderstand="true" xmlns:nseps="urn:schemas-IBX:/docs/endpoint.nsendpoint"> <nseps:to> <nseps:address>8b51fc8c-7aba-1000-bbbe-c0a878330001</nseps:address> </nseps:to> <nseps:from> <nseps:address>1b0ad9d6-7a05-1000-a43c-c0a878330001</nseps:address> </nseps:from> </nseps:endpoints> <nsprop:properties SOAP-ENV:mustUnderstand="true" xmlns:nsprop="urn:schemas-IBX:/docs/property.nsproperty"> <nsprop:identity>fb1797dbb1f14a179482b1bb53bc7c14</nsprop:identity> <nsprop:sentAt>2014-09-02T00:00:00+01:00</nsprop:sentAt> <nsprop:topic>Order</nsprop:topic> </nsprop:properties> </SOAP-ENV:Header> <SOAP-ENV:Body> <Order xmlns="rrn:org.xcbl:schemas/xcbl/v3_5/xcbl35.xsd"> <OrderHeader> <OrderNumber> <BuyerOrderNumber>E14124673</BuyerOrderNumber> </OrderNumber> <OrderIssueDate>20140902T00:00:00+01:00</OrderIssueDate> <OrderReferences> <AccountCode> <Reference> <RefNum>no_unoslo</RefNum> </Reference> </AccountCode> </OrderReferences> <Purpose> <PurposeCoded>Original</PurposeCoded> </Purpose> <RequestedResponse> <RequestedResponseCoded>NoAcknowledgementNeeded</RequestedResponseCoded> </RequestedResponse> <OrderType> <OrderTypeCoded>PurchaseOrder</OrderTypeCoded> </OrderType> <OrderCurrency> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> </OrderCurrency> <OrderLanguage> <Language LanguageDependent="false"> <LanguageCoded>no</LanguageCoded> </Language> </OrderLanguage> <OrderDates> <RequestedDeliverByDate>20140904T00:00:00+01:00</RequestedDeliverByDate> </OrderDates> <OrderParty> <BuyerParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident>no_uio</Ident> </Identifier> </PartyID> <NameAddress> <Name1>xxxxxxxxxxxxx</Name1> <Name2>xxxxxxxxxxxxx</Name2> <POBox>xxxxx</POBox> <PostalCode>NO-0316</PostalCode> <City>Oslo</City> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>Some Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email@email.no</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+4700000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> </Party> </BuyerParty> <BuyerTaxInformation> <PartyTaxInformation> <TaxIdentifier> <Identifier> <Agency> <AgencyCoded>Other</AgencyCoded> <AgencyCodedOther>VAT Number</AgencyCodedOther> </Agency> <Ident>00000000</Ident> </Identifier> </TaxIdentifier> </PartyTaxInformation> </BuyerTaxInformation> <SellerParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident>8b51fc8c-7aba-1000-bbbe-c0a878330001</Ident> </Identifier> </PartyID> <NameAddress> <Name1>Name 2</Name1> <Street>Adress</Street> <PostalCode> 0314</PostalCode> <City>OSLO</City> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>N/A</ContactName> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>47 0000000</ContactNumberValue> <ContactNumberTypeCoded>FaxNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> </Party> </SellerParty> <ShipToParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident /> </Identifier> </PartyID> <NameAddress> <Name1>Name</Name1> <Name2>Name2 </Name2> <Street>Adress</Street> <StreetSupplement1>0318 Oslo</StreetSupplement1> <PostalCode>NO-0562</PostalCode> <City>OSLO</City> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>emamil</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+470000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> <ReceivingContact> <Contact> <ContactName>Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+4700000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </ReceivingContact> </Party> </ShipToParty> <BillToParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident>no_uio</Ident> </Identifier> </PartyID> <NameAddress> <Name1>Name</Name1> <Name2>Adress</Name2> <POBox>adress2</POBox> <PostalCode>NO-0316</PostalCode> <City>Oslo</City> <County /> <District>9908:971035854</District> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+470000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> </Party> </BillToParty> </OrderParty> <OrderTermsOfDelivery> <TermsOfDelivery> <TermsOfDeliveryFunctionCoded>Other</TermsOfDeliveryFunctionCoded> <TermsOfDeliveryFunctionCodedOther>Other</TermsOfDeliveryFunctionCodedOther> <TransportTermsCoded>Other</TransportTermsCoded> <TransportTermsCodedOther>DDP</TransportTermsCodedOther> <ShipmentMethodOfPaymentCoded>Other</ShipmentMethodOfPaymentCoded> <ShipmentMethodOfPaymentCodedOther>Other</ShipmentMethodOfPaymentCodedOther> <TransportDescription /> </TermsOfDelivery> </OrderTermsOfDelivery> <OrderHeaderNote /> </OrderHeader> <OrderDetail> <ListOfItemDetail> <ItemDetail> <BaseItemDetail> <LineItemNum> <BuyerLineItemNum>1</BuyerLineItemNum> </LineItemNum> <LineItemType> <LineItemTypeCoded>Item</LineItemTypeCoded> </LineItemType> <ItemIdentifiers> <PartNumbers> <SellerPartNumber> <PartNum> <PartID>1000000000001</PartID> </PartNum> </SellerPartNumber> <ManufacturerPartNumber> <PartID /> </ManufacturerPartNumber> </PartNumbers> <ItemDescription>Normal frakt, pris 20 NOK</ItemDescription> </ItemIdentifiers> <TotalQuantity> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </TotalQuantity> <OffCatalogFlag>false</OffCatalogFlag> </BaseItemDetail> <PricingDetail> <ListOfPrice> <Price> <UnitPrice> <UnitPriceValue>20</UnitPriceValue> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </UnitPrice> <PriceBasisQuantity> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </PriceBasisQuantity> </Price> </ListOfPrice> <Tax> <TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded> <TaxCategoryCoded>StandardRate</TaxCategoryCoded> <TaxTypeCoded>ValueAddedTax</TaxTypeCoded> <TaxPercent>.00</TaxPercent> <TaxableAmount>20.00</TaxableAmount> <TaxAmount>.00</TaxAmount> </Tax> <TotalValue> <MonetaryValue> <MonetaryAmount>20.00</MonetaryAmount> </MonetaryValue> </TotalValue> </PricingDetail> <DeliveryDetail> <ListOfScheduleLine> <ScheduleLine> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> <RequestedDeliveryDate>20140904T00:00:00+01:00</RequestedDeliveryDate> </ScheduleLine> </ListOfScheduleLine> </DeliveryDetail> </ItemDetail> <ItemDetail> <BaseItemDetail> <LineItemNum> <BuyerLineItemNum>2</BuyerLineItemNum> </LineItemNum> <LineItemType> <LineItemTypeCoded>Item</LineItemTypeCoded> </LineItemType> <ItemIdentifiers> <PartNumbers> <SellerPartNumber> <PartNum> <PartID>9788258312007</PartID> </PartNum> </SellerPartNumber> <ManufacturerPartNumber> <PartID /> </ManufacturerPartNumber> </PartNumbers> <ItemDescription>Hovedtariffavtalen i staten 1. mai 2014 - 30. april 2016 (p.100kr)</ItemDescription> </ItemIdentifiers> <TotalQuantity> <Quantity> <QuantityValue>2</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </TotalQuantity> <OffCatalogFlag>false</OffCatalogFlag> </BaseItemDetail> <PricingDetail> <ListOfPrice> <Price> <UnitPrice> <UnitPriceValue>100</UnitPriceValue> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </UnitPrice> <PriceBasisQuantity> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </PriceBasisQuantity> </Price> </ListOfPrice> <Tax> <TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded> <TaxCategoryCoded>StandardRate</TaxCategoryCoded> <TaxTypeCoded>ValueAddedTax</TaxTypeCoded> <TaxPercent>.00</TaxPercent> <TaxableAmount>100.00</TaxableAmount> <TaxAmount>.00</TaxAmount> </Tax> <TotalValue> <MonetaryValue> <MonetaryAmount>200.00</MonetaryAmount> </MonetaryValue> </TotalValue> </PricingDetail> <DeliveryDetail> <ListOfScheduleLine> <ScheduleLine> <Quantity> <QuantityValue>2</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> <RequestedDeliveryDate>20140904T00:00:00+01:00</RequestedDeliveryDate> </ScheduleLine> </ListOfScheduleLine> </DeliveryDetail> </ItemDetail> </ListOfItemDetail> </OrderDetail> <OrderSummary> <NumberOfLines>2</NumberOfLines> <TotalTax> <MonetaryValue> <MonetaryAmount>.00</MonetaryAmount> </MonetaryValue> </TotalTax> <TotalAmount> <MonetaryValue> <MonetaryAmount>220.00</MonetaryAmount> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> </MonetaryValue> </TotalAmount> </OrderSummary> </Order> </SOAP-ENV:Body> </SOAP-ENV:Envelope> good day dear phpfreaks.
I am new to PHP's SimpleXML. i want to work with SimpleXML on OSM-files. The original version of this question was derived from he OSM Data parsing to get the nodes with child https://stackoverflow.com/questions/16129184/osm-data-parsing-to-get-the-nodes-with-child
I am thankful that hakre offered a great example in the comments that makes a overwhelming goal: how to get more out of it: I want to filter the data to get the nodes with special category. Here is sample of the OSM data I want to get the whole schools within an area. The first script runs well - but now I want to refine the search and add more tags. Finally I want to store all into MySQL. So we need to make some XML parsing with PHP:
The following is a little OSM Overp
Quote
since i am learning - i break down the code into pieces...For my question, the second part is more interesting here. That is querying the XML data we have already. Again - as mentioned above: This is most easily done with xpath, the used PHP XML library is based on libxml which supports XPath 1.0 which covers the various querying needs very well. The following example lists all schools and tries to obtain their names as well.
# get all school nodes with xpath //node[tag[@k = "amenity" and @v = "school"]] This line says: Give me all node elements that have a tag element inside which has the k attribute value "amenity" and the v attribute value "school". Explanation: This is the condition we have to filter out those nodes that are tagged with amenity school. Further on xpath is used again - a second time: now relative to those school nodes to see if there is a name and if so to fetch it: Therefore we use the foreach-syntax:
foreach ($schools as $index => $school)
tag[@k = "name"]/@v'
tag[@k = "name"]/@v' Because not all school nodes have a name, a default string is provided for display purposes by adding it to the (then empty) result array:
list($name) = $school->xpath('tag[@k = "name"]/@v') + ['(unnamed)'];
Query returned 907 node(s) and took 1.10735 seconds. goal: to get out even more important data - see here Key:contact - OpenStreetMap Wiki
Well - we are already extracting the name: If we want to have more data then we just have to run a few more xpath queries inside our loop for all the address keys and the website. So - additionally: we do not have to forget to look for the website key additional to contact:website. cf: https://wiki.openstreetmap.org/wiki/Key:website conclusio: well - i think that i need to extend the xpath requests within the loop where xpath is used again, now relative to those school nodes to see if there is a name and if so to fetch it:
tag[@k = "name"]/@v' i did some further tess and found out very interesting things
$query = 'node
$context = stream_context_create(['http' => [
# please do not stress this service, this example is for demonstration purposes only.
$result = simplexml_load_file($endpoint);
//
# get all school nodes with xpath
$query = 'node
$context = stream_context_create(['http' => [
$endpoint = 'http://overpass-api.de/api/interpreter';
$result = simplexml_load_file($endpoint);
me/martin/dev/php/o1.php on line 68
33 School(s) found:
so far so good : if i add some lines in the part 2 i run into errors... -see below: i want to get more data out of it: - and coded like so;
{ note - within the part 2 that works with the XML-Result.
//
# get all school nodes with xpath
contact:phone I will dig into all documents and come back later the weekend... and report all the findings well - i think that i need to extend the xpath requests within the loop where xpath is used again, now relative to those school nodes to see if there is a name and if so to fetch it:
tag[@k = "name"]/@v'
more infos Hi guys, I'm using PHP Simple DOM, thanks to the good folk her I'm making progress. The html i'm parsing has a bunch of links in a li ul structure. I've managed to get the top layer of links extracted and I would like to have a count of the number of child nodes in the layer below the main links. Here is my code: $html = file_get_html('test/php/book.html'); if(!empty($html)){ $lis = $html->find('.chunklist', 0)->children() ; for ( $i = 0 ; $i < count($lis) ; $i++ ) { $parent_term = $lis[$i]->first_child()->innertext . ', ' ; $parent_node = $lis[$i]->children[0]->attr['href'] . '<br>' ; //echo count($parent_node->children()) ; this gives error Warning: count(): Parameter must be an array or an object that implements Countable echo $parent_term . $parent_node ; $parent_node = $const . $parent_node ; echo $parent_node ; $html2 = file_get_html($parent_node) ; $lis2 = $html2->find('.chunklist', 0)->children() ; } } I don't see anything in the manual regarding counting nodes, any idea how to go about this? Hi, I need to build my own xml validator and was wondering, what are some possible purposes of having multiple text nodes for a given parent node, I ask b/c while I was playing around with W3schools XML validator, I noticed it successfully validated the following: <?xml version="1.0" encoding="utf-8" ?> <note> <to>Joh</to> <from>Frank</from> <body>Hello world</body> Extra text node that is validated! </note> good day dear experts,
<?php /** * OSM Overpass API with PHP SimpleXML / XPath * * PHP Version: 5.4 - Can be back-ported to 5.3 by using 5.3 Array-Syntax (not PHP 5.4's square brackets) */ // // 1.) Something is wrong an OSM Overpass API Endpoint // $Something is wrong = 'node ["addr:postcode"~"RM12"] (51.5557914,0.2118915,51.5673083,0.2369398)->.point; ( node (around.point:100000) ["amenity"~"school"]; way (around.point:100000) ["amenity"~"school"]; ); out;'; $context = stream_context_create(['http' => [ 'method' => 'POST', 'header' => ['Content-Type: application/x-www-form-urlencoded'], 'content' => 'data=' . urlencode($Something is wrong), ]]); # please do not stress this service, this example is for demonstration purposes only. $endpoint = 'http://overpass-api.de/api/interpreter'; libxml_set_streams_context($context); $start = microtime(true); $result = simplexml_load_file($endpoint); printf("Something is wrong returned %2\$d node(s) and took %1\$.5f seconds.\n\n", microtime(true) - $start, count($result->node)); // // 2.) Work with the XML Result // # get all school nodes with xpath $xpath = '//node[tag[@k = "amenity" and @v = "school"]]'; $schools = $result->xpath($xpath); printf("%d School(s) found:\n", count($schools)); foreach ($schools as $index => $school) { # Get the name of the school (if any), again with xpath list($name) = $school->xpath('tag[@k = "name"]/@v') + ['(unnamed)']; printf("#%02d: ID:%' -10s [%s,%s] %s\n", $index, $school['id'], $school['lat'], $school['lon'], $name); }
FATAL ERROR syntax error, unexpected 'is' (T_STRING) on line number 11
well at the moment i try to make up my mind what is going on here So here's what I'm trying to do, and I haven't found any clear tutorials on how to properly navigate a DOMDocument object, at least not in the strict sense of PHP. I'm building a web scraper, I've had it working for some time now using more traditional methods (a combination of string manipulation and clever regex). I've been told xpath can be much faster and more reliable for what I need. Sold. Let's say I'm parsing a forum. This forum separates each reply in a post with a set of <li></li> with a class of "message" Code: [Select] <li class="message"> // Stuff here </li> <li class="message"> // Stuff here </li> So far so good. These list items contain all the formatting for each post, including user info and the message text. Each sitting in it's own div. Code: [Select] <li class="message"> <div class="user info"> User info here </div> <div class="message text"> Message text here </div> </li> <li class="message"> <div class="user info"> User info here </div> <div class="message text"> Message text here </div> </li> Still with me? Good. With this bit of code I can select each message list item block and iterate over all the sub nodes inside. Code: [Select] $items = $xpath->query("//li[starts-with(@class, 'message')]"); for ($i = 0; $i < $items->length; $i++) { echo $items->item($i)->nodeValue . "\n"; } This produces a basic text dump of the entire forum. Close, but not what I need. What I'm trying to do is as follows Select all the class="message" list items [done] Once those have been selected, run another $xpath->query to select the child nodes which contain the user info and message text Step one is done, step two is what is confusing me. How can I run a new query based on the output from the first query? Thanks guys Hi Guys, I tried to put pagination code into my search results but every time I get an ugly error. Can you guys help me please?I just want to put 5 results per page. Why does it have to be so complicated. I am just asking something very simple (Well, it shows that you don't know anything about php dude! ( I am just talking to myself)) <a href="search.php">Search</a><br> <br> <?php include("connect.php"); $first_name = "%" . $_POST["first_name"] . "%"; $last_name = "%" . $_POST["last_name"] . "%"; $age = "%" . $_POST["age"] . "%"; $query= "SELECT * FROM `contacts` WHERE `first_name` LIKE '$first_name' AND `last_name` LIKE '$last_name' AND `age` LIKE '$age' ORDER BY `contacts`.`first_name` ASC LIMIT 0, 30 "; $result = mysql_query($query); $num = mysql_num_rows ($result); mysql_close(); if ($num > 0 ) { $i=0; while ($i < $num) { $first_name = mysql_result($result,$i,"first_name"); $last_name = mysql_result($result,$i,"last_name"); $age = mysql_result($result,$i,"age"); $id = mysql_result($result,$i,"id"); echo "<b>first name:</b> $first_name<br>"; echo "<b>last name:</b> $last_name<br>"; echo "<b>age:</b> $age<br>"; echo "<a href=\"update.php?id=$id\">Update</a> - <a href=\"delete.php?id=$id\">Delete</a>"; echo "<br><br>"; ++$i; } } else { echo "No Results"; }?> I can't get my head around it, no matter how many tutorials I read.. So would anyone be able to put this code into a pagination of 3 per page? Many Thanks Code: [Select] <?php if(!$_GET['id']) { $query = "SELECT * FROM news where published = '1' ORDER by id DESC"; $result = mysql_query($query) or die(mysql_error()); $news = mysql_fetch_assoc($result); ?> <?php do { ?> <table width="590" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2"><h2><? echo $news['title']; ?></h2></td> </tr> <tr> <td width="398"><? echo $news['story']; ?></td> <td width="192"><img src="<? echo $news['image']; ?>" alt="<? echo $news['shortstory']; ?>" width="192" height="108" /></td> </tr> <tr> <td colspan="2"><i><br /> Posted by <? echo $news['author']; ?> on <? echo $news['date']; ?></i></td> </tr> </table><br /> <?php } while ($news = mysql_fetch_assoc($result)); } ?> I need a little help trying to figure this out. I have a page that pulls up data, you can then click on one and go to a page with more detail. On this page you can use the PRrev & Next to go view another detail page on other data. My problem is if my 1st page has 6 sets of data on it but has a total of, say 50, you can only use the Prev & Next to view the 6. I want to be able to use the Prev & Next to go thru all 50. ie Page1 pulls this info data1 data2 data3 data4 data5 data6 < << 1 2 [3] 4 5 6 > >> Page2 Data 1 Lots of info about data 1 < Prev Next > You will only be able to view the 6 data sets in the table above, however there are 50 I want to be able to use the < Prev Next > to go to all of them Can someone help me with this? here is my code Page1 <?php session_start(); // session timing // set timeout period in seconds $inactive = 120; // check to see if $_SESSION['timeout'] is set if(isset($_SESSION['timeout']) ) { $session_life = time() - $_SESSION['timeout']; if($session_life > $inactive) { session_destroy(); } } $_SESSION['timeout'] = time(); // END session timing include('library/login.php'); login(); mysql_select_db('test'); // sets the sessions for all values $_SESSION=array_merge($_SESSION,$_POST); // echoing to verify $gender=$_SESSION[gender]; $genderPref=$_SESSION[genderPref]; echo "Chossen Gender".$_SESSION['gender']; echo "<br><Br>"; echo "GenderPref".$_SESSION['genderPref']; echo "<br><Br>"; // if the user has been timed out or not logged in if (!isset($_SESSION['clientID'])){ echo "You are not a register user - set this to a simple search form"; echo "<br><a href='form.php'>Form</a>"; } // user is logged in else { $clientID = $_SESSION['clientID']; $sql="SELECT * FROM user WHERE userID='$clientID'"; $result=mysql_query($sql); while ($r=mysql_fetch_array($result)) { $exp_date=$r["exp_date"]; $todays_date=date("Y-m-d"); } // verifies billing if ($exp_date >= $todays_date) { // billing is up to date $result = mysql_query("SELECT * FROM user WHERE gender='$gender'") or die(mysql_error()); // ------ Sets the display of data ------ $num_rows = mysql_num_rows($result); // number of rows to show per page $rowsperpage = 8; // find out total pages $totalpages = ceil($num_rows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; $result = mysql_query("SELECT * FROM user WHERE gender='$gender' LIMIT $offset, $rowsperpage")or die(mysql_error()); $num_rows = mysql_num_rows($result); if ($num_rows == 0){ echo "<div id='noResults'><span class='sorry'>Sorry</span>, no results found. <br> Please try again with broader search options.</div>"; } else { // format for search results $cells_wide = 2; echo " <table cellspacing='0' cellpadding='3' border='0' width='700'><tr> "; $c = 0; while ($r=mysql_fetch_array($result)) { $userID=$r["userID"]; $gender=$r["gender"]; $aUserIDs[] = $userID; if (0 < $c && 0 == $c % $cells_wide){ echo " </tr><tr> "; } echo " <td width=175> "; echo "<a href='profileSession.php?userID=$r[userID]'>$userID</a>, $gender</td>"; $c++; } // end of while echo " </tr>"; echo " </table> "; } // -------- BUILD THE PAGINATION LINKS -------------------------------- $_SESSION['userID']=$aUserIDs; $_SESSION['userID2']=$aUserIDs2; echo "<div id='navigation'>"; // range of num links to show $range = 3; // if not on page 1, show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2'>‹‹ </a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2'> ‹ </a> "; } // END if ($currentpage > 1) // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($totalpages == 1) { echo ""; } else{ if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } // END if ($x == $currentpage) else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2'>$x</a> "; } // END else } // END else } // END if (($x > 0) && ($x <= $totalpages)) } // END for loop // if not on last page, show forward and last page links if ($totalpages == 0) { echo ""; } else{ if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2'> › </a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2'>›› </a> "; } // END if ($currentpage != $totalpages) }// END else echo "<br>currentpage=$currentpage&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2"; $link='currentpage='; $link1='&gender='; $link2='&genderPref='; $link3='&ageMin='; $link4='&ageMax='; $link5='&year1='; $link6='&year2='; $total=$link.$currentpage.$link1.$genderPref.$link2.$gender.$link3.$ageMin.$link4.$ageMax.$link5.$year1.$link6.$year2; $_SESSION['pages']=$total; echo "<br>$total"; // -------- END PAGINATION -------------------------------------------- } // END if ($exp_date >= $todays_date) else { // billing has expired echo "Billing has expired<br>"; echo $_SESSION['clientID']; echo "<br><a href='session2.php'>Sesssion2</a>"; echo "<br><a href='form.php'>Form</a>"; } } // END valid session ?> Page2 <?php session_start(); // start up your PHP session! include('library/login.php'); login(); mysql_select_db('test'); $userID=$_GET["userID"]; $link=$_SESSION['pages']; // Sends back to display page echo "<a href='searchSession.php?$link' title='Back to Search'>Back to Search</a> "; // sets the Prev & Next $aUsers = isset($_SESSION['userID']) ? $_SESSION['userID'] : array(); $current = $userID; // Ok our current. $iCurKey = array_search($current, $aUsers); $prev = null; $next = null; if ($iCurKey !== false){ $prev = $iCurKey >= 1 ? $aUsers[$iCurKey - 1] : null; $next = $iCurKey < count($aUsers) - 1 ? $aUsers[$iCurKey + 1] : null; } // Lets do this simple. if ($prev !== null){ echo ' <A href="?userID=' . $prev . '">« Previous</A> '; } else{ echo " <span class='empty'>« Previous</span> "; } if ($next !== null){ echo '<A class=right href="?userID=' . $next . '">Next »</A> '; } else{ echo "<span class='empty'> Next »</span>"; } // END of the Prev & Next $result = mysql_query("SELECT userID, first_name, gender FROM user WHERE userID='$userID'") or die(mysql_error()); while ($r=mysql_fetch_array($result)){ $userID=$r["userID"]; $first_name=$r["first_name"]; $gender=$r["gender"]; } echo "<br>$userID, $first_name, $gender"; ?> Is there a way of doing pagination other than going through the whole big file, like: Code: [Select] $limit = "LIMIT 0, 30"; if ($_GET['page'] == 2) { $limit = "LIMIT 30, 30"; } $sql = "SELECT * FROM table WHERE blah = 'blah' $limit"; $result = mysql_query($sql); But is there a way to do this without having to write an if statement for each page without getting to extensive? Thanks! Sorry to bug yalls with yet another problem, but I tried applying pagination to the page I use to display the news on my website, which is stored within mysql, and I'm having major issues. Here's the code below for both the pagination and getting the news out of the database to display. Not sure what's going on here. I tested the script and it does everything fine except it doesn't display the information stored within the database. Go here to see for yourself: http://www.djsmiley.net/index.php Code: [Select] <?php /* Place code to connect to your DB here. */ include('cms/news/dbconnect.php'); // include your code to connect to DB. $tbl_name="mynews"; //your table name // How many adjacent pages should be shown on each side? $adjacents = 3; /* First get total number of rows in data table. If you have a WHERE clause in your query, make sure you mirror it here. */ $query = "SELECT COUNT(*) as num FROM $tbl_name"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages[num]; /* Setup vars for query. */ $targetpage = "index.php"; //your file name (the name of this file) $limit = 1; //how many items to show per page $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 10 FROM $tbl_name LIMIT $start, $limit"; $result = mysql_query($sql); /* 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\"><img class=\"fltlft2\" src=\"http://www.djsmiley.net/images/Icons/Arrows/Previous.png\" height=\"25\" width=\"25\"></a>"; else $pagination.= "<span class=\"disabled\"><img class=\"fltlft2\" src=\"http://www.djsmiley.net/images/Icons/Arrows/Previous.png\" height=\"25\" width=\"25\"></a></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\">$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\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //in middle; hide some front and some back elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">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\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //close to end; only hide early pages else { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">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\">$counter</a>"; } } } //next button if ($page < $counter - 1) $pagination.= "<a href=\"$targetpage?page=$next\"><img src=\"http://www.djsmiley.net/images/Icons/Arrows/Next.png\" height=\"25\" width=\"25\"></a>"; else $pagination.= "<span class=\"disabled\"><img src=\"http://www.djsmiley.net/images/Icons/Arrows/Next.png\" height=\"25\" width=\"25\"></span>"; $pagination.= "</div>\n"; } ?> <?php while($row = mysql_fetch_array($result)) { echo("<p class=NewsContainer><span class=NewsID>$type</span> <font size=5>$title</font><br><br> <em>posted by <strong>$user</strong> | added on $time</em><br><br> $message<br><br> <label class=fltlft2><img src=../images/Icons/Arrows/Right.png width=20 height=20/></label><a href=$url>Read more - $url</a> <div class=newsLikeShareRate> <table width=100% border=0> <tr> <td width=3% height=21><script src=http://connect.facebook.net/en_US/all.js#xfbml=1></script> <fb:like href='$url' show_faces=true width=450 font=arial></fb:like> </td> <td width=65%><a name=fb_share id=fb_share4 type=icon_link share_url=$url>Share</a> <script src=http://static.ak.fbcdn.net/connect.php/js/FB.Share type=text/javascript></script></td> <td width=32%>Rate this article: </td> </tr> </table> </div></p><br><br>");// Your while loop here } ?> <?=$pagination?> Hello, I am trying to incorporate pagination to only show 20 rows per page but instead the links work but shows all rows on all pages. Link to see: http://webjax.99k.org/ Full Code: Code: [Select] <?php include ("./header.php"); //PAGINATION $sql = "SELECT COUNT(*) FROM servers"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 20; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; //END PAGINATION //======================================================================== Commands If (isSet($_GET['sort'])) { $sortby = $_GET['sort']; If ($sortby=='name' || $sortby=='ip' || $sortby=='votes' || $sortby=='username') { If ($sortby=='name') { $options = "<option value='./index.php?sort=name' selected='selected'>Name</option> <option value='./index.php?sort=ip'>IP Address</option> <option value='./index.php?sort=votes'>Rank</option> <option value='./index.php?sort=username'>Owner</option>"; } If ($sortby=='ip') { $options = "<option value='./index.php?sort=name'>Name</option> <option value='./index.php?sort=ip' selected='selected'>IP Address</option> <option value='./index.php?sort=votes'>Rank</option> <option value='./index.php?sort=username'>Owner</option>"; } If ($sortby=='votes') { $options = "<option value='./index.php?sort=name'>Name</option> <option value='./index.php?sort=ip'>IP Address</option> <option value='./index.php?sort=votes' selected='selected'>Rank</option> <option value='./index.php?sort=username'>Owner</option>"; } If ($sortby=='username') { $options = "<option value='./index.php?sort=name'>Name</option> <option value='./index.php?sort=ip'>IP Address</option> <option value='./index.php?sort=votes'>Rank</option> <option value='./index.php?sort=username' selected='selected'>Owner</option>"; } } else { $sortby = "votes"; $options = "<option value='./index.php?sort=name'>Name</option> <option value='./index.php?sort=ip'>IP Address</option> <option value='./index.php?sort=votes' selected='selected'>Rank</option> <option value='./index.php?sort=username'>Owner</option>"; } } else { $sortby = "votes"; $options = "<option value='./index.php?sort=name'>Name</option> <option value='./index.php?sort=ip'>IP Address</option> <option value='./index.php?sort=votes' selected='selected'>Rank</option> <option value='./index.php?sort=username'>Owner</option>"; } If ($_GET['act']=='see' && isSet($_GET['id'])) { //=================================================================== XSS protection $sid = str_replace("/", "", $_GET['id']); $sid = str_replace(Chr(92), "", $sid); $sid = str_replace("'", "", $sid); $sid = str_replace('"', "", $sid); $sid = str_replace("<", "", $sid); $sid = str_replace(">", "", $sid); $sid = str_replace("-", "", $sid); $sid = str_replace("union", "", $sid); $sid = str_replace("information_schema", "", $sid); $sid = strtolower(trim($sid)); //=================================================================== XSS protection $result = mysql_query("SELECT * FROM servers WHERE id='$sid'") or die (mysql_error()); $nr = mysql_num_rows($result); If ($nr<='0') { $exist = "No"; } else { $exist = "Yes"; while($row = mysql_fetch_array($result)) { If ($row['name']=='') { $servername = "<img src='./banners/" .$row['banner']. "' style='width:468px;height:60px' title='Server details'>"; } else { $servername = $row['name']; } $did = $row['id']; $dname = $row['name']; $dbanner = $row['banner']; $dip = $row['ip']; $ddescription = $row['description']; $dwebsite = $row['website']; $dcountry = $row['country']; $dsponsored = $row['sponsored']; $dvotes = $row['votes']; $mineq = $row['mineq']; $dusername = $row['username']; $ddate = $row['date']; If ($dusername==$username) { $me = "Yes"; } else { $me = "No"; } If ($mineq=='Yes') { If (!$dip=='') { include ("./minequery.class.php"); $mine = array((Minequery::query($dip))); $donlinep = $mine["0"]["playerCount"]; If ($donlinep>0) { for ($i = 0; $i <= $donlinep; $i++) { $playername = $mine["0"]["playerList"][$i]; If (!$playername=='') { $donline .= $playername. ", "; } } $donline = left($donline, strlen($donline)-2); } } else { $donline = "<i>n/a</i>"; } } else { $donline = "<i>n/a</i>"; } } } } If ($_GET['act']=='' || $_GET['act']=='sponsored' || $_GET['act']=='myservers') { $result = mysql_query("SELECT * FROM servers ORDER BY votes DESC") or die (mysql_error()); while($rk_list[] = mysql_fetch_array($result)); If (isSet($username) && $_GET['act']=='myservers') { $result = mysql_query("SELECT * FROM servers WHERE username='$username' ORDER BY id DESC") or die (mysql_error()); } else { If ($_GET['act']=='sponsored') { $result = mysql_query("SELECT * FROM servers WHERE sponsored='Yes' ORDER BY id DESC") or die (mysql_error()); } else { If (isSet($_GET['country'])) { $result = mysql_query("SELECT * FROM servers WHERE country='$_GET[country]' ORDER BY votes DESC") or die (mysql_error()); } else { $result = mysql_query("SELECT * FROM servers ORDER BY $sortby DESC") or die (mysql_error()); } } } $nr = mysql_num_rows($result); If ($nr<='0') { $serverslist = "<tr><td align='center' colspan='6'>There are no servers added yet !</td></tr>"; } else { include ("./minequery.class.php"); $rank = "0"; while($row = mysql_fetch_array($result)){ $data[] = $row; } foreach ($data as $row) { $rank = ($rank + 1); If ($row['banner']=='') { $servername = $row['name']; } else { $servername = "<img src='" .$row['banner']. "' style='width:400px;height:60px' title='Server details'>"; } If ($row['sponsored']=='Yes') { $star = "style='background:url(./images/star.png);background-repeat:no-repeat;'"; } else { $star = ""; } If ($row['mineq']=='Yes') { If (!$row['ip']=='') { $mine = array((Minequery::query($row['ip']))); $onlinep = $mine["0"]["playerCount"]; } else { $onlinep = "<i>n/a</i>"; } } else { $onlinep = "<i>n/a</i>"; } $country = "./flags/" .$row['country']. ".png"; $serverslist .= "<tr><td align='center'>" .(array_search($row, $rk_list) + 1). "</td><td align='center'><a href='./index.php?country=" .$row['country']. "'><img src='" .$country. "' title='" .$row['country']. "' style='width:32px;height:32px;'></a></td><td align='center' valign='middle' style='height:60px;'><a class='nav' href='./index.php?act=see&id=" .$row['id']. "' title='Server details'>" .$servername. "</a></td><td align='center' " .$star. ">" .$row['ip']. "</td><td align='center'>" .$onlinep. "</td><td align='center'>" .$row['votes']. "</td></tr>"; //$serverslist .= "<tr><td align='center'>" .$row['id']. "</td><td align='center' valign='middle' style='height:60px;'><a class='nav' href='./index.php?act=see&id=" .$row['id']. "' title='Server details'>" .$servername. "</a></td><td align='center'><img src='./flags/" .$row['country']. ".ico' title='" .$row['country']. "'> " .$row['ip']. "</td><td align='center'>" .$row['votes']. "</td><td align='center'>" .$row['date']. "</td></tr>"; //$serverslist .= "<tr><td align='center'>" .$row['id']. "</td><td align='center'>" .$servername. "</td><td align='center'>" .country_flag($row['ip']). " " .$row['ip']. "</td><td align='center'>" .$row['votes']. "</td></tr>"; } } } /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ //======================================================================== Strings $countries = "<option>Afghanistan</option> <option>Albania</option> <option>Algeria</option> <option>Andorra</option> <option>Angola</option> <option>Antigua and Barbuda</option> <option>Argentina</option> <option>Armenia</option> <option>Aruba</option> <option>Australia</option> <option>Austria</option> <option>Azerbaijan</option> <option>Bahamas, The</option> <option>Bahrain</option> <option>Bangladesh</option> <option>Barbados</option> <option>Belarus</option> <option>Belgium</option> <option>Belize</option> <option>Benin</option> <option>Bermuda</option> <option>Bhutan</option> <option>Bolivia</option> <option>Bosnia and Herzegovina</option> <option>Botswana</option> <option>Brazil</option> <option>Brunei</option> <option>Bulgaria</option> <option>Burkina Faso</option> <option>Burma</option> <option>Burundi</option> <option>Cambodia</option> <option>Cameroon</option> <option>Canada</option> <option>Cape Verde</option> <option>Cayman Islands</option> <option>Central African Republic</option> <option>Chad</option> <option>Chile</option> <option>China</option> <option>Colombia</option> <option>Comoros</option> <option>Congo, Democratic Republic of the</option> <option>Congo, Republic of the</option> <option>Costa Rica</option> <option>Cote d'Ivoire</option> <option>Croatia</option> <option>Cuba</option> <option>Curacao</option> <option>Cyprus</option> <option>Czech Republic</option> <option>Denmark</option> <option>Djibouti</option> <option>Dominica</option> <option>Dominican Republic</option> <option>Ecuador</option> <option>Egypt</option> <option>El Salvador</option> <option>Equatorial Guinea</option> <option>Eritrea</option> <option>Estonia</option> <option>Ethiopia</option> <option>Fiji</option> <option>Finland</option> <option>France</option> <option>Gabon</option> <option>Gambia</option> <option>Georgia</option> <option>Germany</option> <option>Ghana</option> <option>Greece</option> <option>Grenada</option> <option>Guatemala</option> <option>Guinea</option> <option>Guinea-Bissau</option> <option>Guyana</option> <option>Haiti</option> <option>Holy See</option> <option>Honduras</option> <option>Hong Kong</option> <option>Hungary</option> <option>Iceland</option> <option>India</option> <option>Indonesia</option> <option>Iran</option> <option>Iraq</option> <option>Ireland</option> <option>Israel</option> <option>Italy</option> <option>Jamaica</option> <option>Japan</option> <option>Jordan</option> <option>Kazakhstan</option> <option>Kenya</option> <option>Kiribati</option> <option>Kosovo</option> <option>Kuwait</option> <option>Kyrgyzstan</option> <option>Laos</option> <option>Latvia</option> <option>Lebanon</option> <option>Lesotho</option> <option>Liberia</option> <option>Libya</option> <option>Liechtenstein</option> <option>Lithuania</option> <option>Luxembourg</option> <option>Macau</option> <option>Macedonia</option> <option>Madagascar</option> <option>Malawi</option> <option>Malaysia</option> <option>Maldives</option> <option>Mali</option> <option>Malta</option> <option>Marshall Islands</option> <option>Mauritania</option> <option>Mauritius</option> <option>Mexico</option> <option>Micronesia</option> <option>Moldova</option> <option>Monaco</option> <option>Mongolia</option> <option>Montenegro</option> <option>Morocco</option> <option>Mozambique</option> <option>Namibia</option> <option>Nauru</option> <option>Nepal</option> <option>Netherlands</option> <option>Netherlands Antilles</option> <option>New Zealand</option> <option>Nicaragua</option> <option>Niger</option> <option>Nigeria</option> <option>North Korea</option> <option>Norway</option> <option>Oman</option> <option>Pakistan</option> <option>Palau</option> <option>Panama</option> <option>Papua New Guinea</option> <option>Paraguay</option> <option>Peru</option> <option>Philippines</option> <option>Poland</option> <option>Portugal</option> <option>Qatar</option> <option>Romania</option> <option>Russia</option> <option>Rwanda</option> <option>Saint Kitts and Nevis</option> <option>Saint Lucia</option> <option>Saint Vincent and the Grenadines</option> <option>Samoa</option> <option>San Marino</option> <option>Sao Tome and Principe</option> <option>Saudi Arabia</option> <option>Senegal</option> <option>Serbia</option> <option>Seychelles</option> <option>Sierra Leone</option> <option>Singapore</option> <option>Slovakia</option> <option>Slovenia</option> <option>Solomon Islands</option> <option>Somalia</option> <option>South Africa</option> <option>South Korea</option> <option>South Sudan</option> <option>Spain</option> <option>Sri Lanka</option> <option>Sudan</option> <option>Suriname</option> <option>Swaziland</option> <option>Sweden</option> <option>Switzerland</option> <option>Syria</option> <option>Taiwan</option> <option>Tajikistan</option> <option>Tanzania</option> <option>Thailand</option> <option>Timor-Leste</option> <option>Togo</option> <option>Tonga</option> <option>Trinidad and Tobago</option> <option>Tunisia</option> <option>Turkey</option> <option>Turkmenistan</option> <option>Tuvalu</option> <option>Uganda</option> <option>Ukraine</option> <option>United Arab Emirates</option> <option>United Kingdom</option> <option>Uruguay</option> <option>Uzbekistan</option> <option>Vanuatu</option> <option>Venezuela</option> <option>Vietnam</option> <option>Yemen</option> <option>Zambia</option> <option>Zimbabwe</option>"; $servers = "<table align='center' class='fancy' width='100%'> <tr><th align='left' colspan='6'>Servers list</th></tr> <tr><td align='left' colspan='3'>Servers : " .$nr. "</td><td align='right' colspan='3'>Arrange by : <select name='by' onChange=location.href=this.options[this.selectedIndex].value;>" .$options. "</select></td></tr> <tr><th align='center' width='1%'>#</th><th align='center' width='1%'>Country</th><th align='center' width='47%'>Name / Banner</th><th align='center' width='20%'>IP Address</th><th align='center' width='1%'>Players Online</th><th align='center' width='1%'>Votes</th></tr> " .$serverslist. " </table>"; $addsv = "<table align='center' class='fancy' width='100%'> <tr><th align='left' colspan='2'>Add server</th></tr> <tr><td align='left' width='100px'>Name :</td><td align='left'><input class='field' type='text' name='aname' style='width:100%;'></td></tr> <tr><td align='left'>Banner url :</td><td align='left'><input class='field' type='text' name='abanner' style='width:100%;'></td></tr> <tr><td align='left'>Description :</td><td align='left'><textarea class='textarea' name='adescription'></textarea></td></tr> <tr><td align='left'>IP Address :</td><td align='left'><input class='field' type='text' name='aip'></td></tr> <tr><td align='left'>Website :</td><td align='left'><input class='field' type='text' name='awebsite'></td></tr> <tr><td align='left'>Country :</td><td align='left'><select name='acountry'>" .$countries. "</select></td></tr> <tr><td align='left'>MineQuery :</td><td align='left'><select name='amine'><option selected='selected'>Yes</option><option>No</option></select></td></tr> <tr><td align='left'>Captcha :</td><td align='left'><img src='./captcha.php' title='Captcha'> <input class='field' type='text' name='captcha' style='width:100px;' maxlength='5'></td></tr> <tr><td> </td><td align='left'><input type='submit' name='aok' value='Add'></td></tr> </table>"; $login = "<table align='left' class='fancy' width='40%'> <tr><th align='left' colspan='2'>Login</th></tr> <tr><td align='left' width='30%'>Username :</td><td align='left'><input class='field' type='text' name='lname'></td></tr> <tr><td align='left'>Password :</td><td align='left'><input class='field' type='password' name='lpass'></td></tr> <tr><td> </td><td align='left'><input type='submit' name='lok' value='Login'></td></tr> </table>"; $register = "<table align='left' class='fancy' width='45%'> <tr><th align='left' colspan='2'>Register</th></tr> <tr><td align='left' width='30%'>Username :</td><td align='left'><input class='field' type='text' name='rname'> <font color='red'>*</font></td></tr> <tr><td align='left'>E-mail :</td><td align='left'><input class='field' type='text' name='rmail'> <font color='red'>*</font></td></tr> <tr><td align='left'>Password :</td><td align='left'><input class='field' type='password' name='rpass'> <font color='red'>*</font></td></tr> <tr><td align='left'>Re-Password :</td><td align='left'><input class='field' type='password' name='rrepass'> <font color='red'>*</font></td></tr> <tr><td> </td><td align='left'><input type='submit' name='rok' value='Register'></td></tr> </table>"; $settings = "<table align='left' class='g' width='80%'> <tr><th align='left' colspan='2'>Settings</th></tr> <tr><td width='50%' valign='top'> <table align='left' class='fancy' width='100%'> <tr><th align='left' colspan='2'>My account</th></tr> <tr><td align='left'>E-mail : </td><td align='left'>" .$uemail. "</td></tr> <tr><td align='left'>Servers : </td><td align='left'>" .$uservers. "</td></tr> <tr><td align='left'>Next vote : </td><td align='left'>" .$unextvoted. "</td></tr> <tr><td align='left'>Join date : </td><td align='left'>" .$udate. "</td></tr> </table> </td><td width='50%' valign='top'> <table align='left' class='fancy' width='100%'> <tr><th align='left' colspan='2'>Change password</th></tr> <tr><td align='left'>Current password : </td><td align='left'><input type='password' name='cpass'></td></tr> <tr><td align='left'>New password : </td><td align='left'><input type='password' name='cnpass'></td></tr> <tr><td align='left'>New re-password : </td><td align='left'><input type='password' name='cnrepass'></td></tr> <tr><td> </td><td align='left'><input type='submit' name='cok' value='Change'></td></tr> </table> </td></tr> </table>"; $f = fopen("./mine.txt", "r"); while ($line = fgets($f, 9999)) { $minetext .= $line. ""; } fclose($f); $minequery = "<table align='left' class='fancy' width='100%'> <tr><th align='left' colspan='2'>MineQuery</th></tr> <tr><td align='left'> " .$minetext. " </td></tr> </table>"; $f = fopen("./help.txt", "r"); while ($line = fgets($f, 9999)) { $helptext .= $line. ""; } fclose($f); $help = "<table align='left' class='fancy' width='100%'> <tr><th align='left' colspan='2'>Help</th></tr> <tr><td align='left'> " .$helptext. " </td></tr> </table>"; If ($me=='No') { If ($dname=='') { $dname = "<i>none</i>"; } If ($dbanner=='') { $dbanner = "<i>none</i>"; } else { $dbanner = "<img src='" .$dbanner. "' title='Banner' style='width:468px;height:60px'>"; } $details = "<table align='center' class='fancy' width='100%'> <tr><th align='left' colspan='2'>Server details</th></tr> <tr><td align='left' width='100px'>Name :</td><td align='left'>" .$dname. "</td></tr> <tr><td align='left'>Banner url :</td><td align='left'>" .$dbanner. "</td></tr> <tr><td align='left'>Description :</td><td align='left'>" .$ddescription. "</td></tr> <tr><td align='left'>Players online :</td><td align='left'>" .$donline. "</td></tr> <tr><td align='left'>IP Address :</td><td align='left'>" .$dip. "</td></tr> <tr><td align='left'>Website :</td><td align='left'>" .$dwebsite. "</td></tr> <tr><td align='left'>Sponsored :</td><td align='left'>" .$dsponsored. "</td></tr> <tr><td align='left'>Votes :</td><td align='left'>" .$dvotes. "</td></tr> <tr><td align='left'>Owner :</td><td align='left'>" .$dusername. "</td></tr> <tr><td align='left'>Added at :</td><td align='left'>" .$ddate. "</td></tr> <tr><td align='left'>Vote link :</td><td align='left'><a class='nav' href='" .$siteurl. "/vote.php?id=" .$did. "' title='Vote link'>" .$siteurl. "/vote.php?id=" .$did. "</td></tr> </table>"; } else { $details = "<table align='center' class='fancy' width='100%'> <tr><th align='left' colspan='2'>Server details</th></tr> <tr><td align='left' width='100px'>Name :</td><td align='left'><input class='field' type='text' name='nname' style='width:700px;' value='" .$dname. "'></td></tr> <tr><td align='left'>Banner url :</td><td align='left'><input class='field' type='text' name='nbanner' style='width:700px;' value='" .$dbanner. "'></td></tr> <tr><td align='left'>Description :</td><td align='left'><textarea class='textarea' name='ndescription'>" .$ddescription. "</textarea></td></tr> <tr><td align='left'>Players online :</td><td align='left'>" .$donline. "</td></tr> <tr><td align='left'>IP Address :</td><td align='left'><input class='field' type='text' name='nip' value='" .$dip. "'></td></tr> <tr><td align='left'>Website :</td><td align='left'><input class='field' type='text' name='nwebsite' value='" .$dwebsite. "'></td></tr> <tr><td align='left'>Vote link :</td><td align='left'><a class='nav' href='" .$siteurl. "/vote.php?id=" .$did. "' title='Vote link'>" .$siteurl. "/vote.php?id=" .$did. "</td></tr> <tr><td> </td><td align='left'><input type='submit' name='dok' value='Update'> <input type='submit' name='delok' value='Delete'></td></tr> </table>"; } //======================================================================== Display echo "<form method='post' action='" .curPageURL(). "' style='margin:0px;'>"; If ($sidebar=="Yes") { echo "<table align='center' width='100%'> <tr><td align='left' width='80%' valign='top'>"; } If ($_GET['act']=='add' || $_GET['act']=='see' || $_GET['act']=='login' || $_GET['act']=='register' || $_GET['act']=='settings' || $_GET['act']=='myservers' || $_GET['act']=='minequery' || $_GET['act']=='help') { If ($_GET['act']=='add') { If (!$_SESSION['user']=='') { echo $addsv; } else { echo $login; } } If ($_GET['act']=='login') { If ($_SESSION['user']=='') { echo $login; } else { echo $servers; } } If ($_GET['act']=='register') { If ($_SESSION['user']=='') { echo $register; } else { echo $servers; } } If ($_GET['act']=='see') { If ($exist=='Yes') { echo $details; } else { echo $servers; } } If ($_GET['act']=='settings') { If ($_SESSION['user']=='') { echo $login; } else { echo $settings; } } If ($_GET['act']=='myservers') { echo $servers; } If ($_GET['act']=='minequery') { echo $minequery; } If ($_GET['act']=='help') { echo $help; } } else { echo $servers; } If ($sidebar=="Yes") { echo "</td><td align='right' width='20%' valign='top'> <table align='center' width='100%' class='fancy'> " .$rsidead. " </table> </td></tr> </table>"; } echo "</form>"; include ("./footer.php"); ?> this is where I tried to put pagination in: Code: [Select] If ($_GET['act']=='' || $_GET['act']=='sponsored' || $_GET['act']=='myservers') { $result = mysql_query("SELECT * FROM servers ORDER BY votes DESC") or die (mysql_error()); while($rk_list[] = mysql_fetch_array($result)); If (isSet($username) && $_GET['act']=='myservers') { $result = mysql_query("SELECT * FROM servers WHERE username='$username' ORDER BY id DESC") or die (mysql_error()); } else { If ($_GET['act']=='sponsored') { $result = mysql_query("SELECT * FROM servers WHERE sponsored='Yes' ORDER BY id DESC") or die (mysql_error()); } else { If (isSet($_GET['country'])) { $result = mysql_query("SELECT * FROM servers WHERE country='$_GET[country]' ORDER BY votes DESC") or die (mysql_error()); } else { $result = mysql_query("SELECT * FROM servers ORDER BY $sortby DESC") or die (mysql_error()); } } } $nr = mysql_num_rows($result); If ($nr<='0') { $serverslist = "<tr><td align='center' colspan='6'>There are no servers added yet !</td></tr>"; } else { include ("./minequery.class.php"); $rank = "0"; while($row = mysql_fetch_array($result)){ $data[] = $row; } foreach ($data as $row) { $rank = ($rank + 1); If ($row['banner']=='') { $servername = $row['name']; } else { $servername = "<img src='" .$row['banner']. "' style='width:400px;height:60px' title='Server details'>"; } If ($row['sponsored']=='Yes') { $star = "style='background:url(./images/star.png);background-repeat:no-repeat;'"; } else { $star = ""; } If ($row['mineq']=='Yes') { If (!$row['ip']=='') { $mine = array((Minequery::query($row['ip']))); $onlinep = $mine["0"]["playerCount"]; } else { $onlinep = "<i>n/a</i>"; } } else { $onlinep = "<i>n/a</i>"; } $country = "./flags/" .$row['country']. ".png"; $serverslist .= "<tr><td align='center'>" .(array_search($row, $rk_list) + 1). "</td><td align='center'><a href='./index.php?country=" .$row['country']. "'><img src='" .$country. "' title='" .$row['country']. "' style='width:32px;height:32px;'></a></td><td align='center' valign='middle' style='height:60px;'><a class='nav' href='./index.php?act=see&id=" .$row['id']. "' title='Server details'>" .$servername. "</a></td><td align='center' " .$star. ">" .$row['ip']. "</td><td align='center'>" .$onlinep. "</td><td align='center'>" .$row['votes']. "</td></tr>"; //$serverslist .= "<tr><td align='center'>" .$row['id']. "</td><td align='center' valign='middle' style='height:60px;'><a class='nav' href='./index.php?act=see&id=" .$row['id']. "' title='Server details'>" .$servername. "</a></td><td align='center'><img src='./flags/" .$row['country']. ".ico' title='" .$row['country']. "'> " .$row['ip']. "</td><td align='center'>" .$row['votes']. "</td><td align='center'>" .$row['date']. "</td></tr>"; //$serverslist .= "<tr><td align='center'>" .$row['id']. "</td><td align='center'>" .$servername. "</td><td align='center'>" .country_flag($row['ip']). " " .$row['ip']. "</td><td align='center'>" .$row['votes']. "</td></tr>"; } } } /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ I'm not sure what im doing wrong can anyone help? hi ive simple code. but i would need help how to do pagination. ive followed one tutorial and ive code.but i really dont know how to connect these.or if its even possible to connect. heres the index.php file Code: [Select] <?php include '_class/cms_class.php'; $obj = new modernCMS(); $obj->host = 'localhost'; $obj->username = 'root'; $obj->password = 'root'; $obj->db = 'modernCMS'; $obj->connect(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <link rel="stylesheet" href="style.css" type="text/css" media="screen" title="no title" charset="utf-8"> </head> <body> <div id="page-wrap"> <?php if(isset($_GET['id'])): $obj->get_content($_GET['id']); else: $obj->get_content(); endif; ?> </div> </body> </html> cms_class.php Code: [Select] <?php class modernCMS { var $host; var $username; var $password; var $db; function connect() { $con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } function get_content($id = '') { if($id != ""): $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id = '$id'"; else: $sql = "SELECT * FROM cms_content ORDER BY id DESC"; endif; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)) { echo '<h1><a href="index.php?id=' . $row['id'] . '">' . $row['title'] . '</a></h1>'; echo '<p>' . $row['body'] . '</p>'; } } } ?> Heres the pagination code ihave Code: [Select] <?php include 'db.inc.php'; $per_page = 2; $pages_query = mysql_query("SELECT COUNT(`id`) FROM `cms_content`"); $pages = ceil(mysql_result($pages_query, 0) / $per_page); $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1; $start = ($page - 1) * $per_page; $query = mysql_query("SELECT * FROM `cms_content` LIMIT $start, $per_page"); while ($query_row = mysql_fetch_assoc($query)) { echo '<p>', $query_row['title'] ,'</p>'; echo '<p>', $query_row['body'] ,'</p>'; } if ($pages >=1 && $page <= $pages) { for ($x=1; $x<=$pages; $x++) { echo ($x == $page) ? '<strong><a href="?page=' .$x. '">' .$x. '</a></strong> ' : '<a href="?page=' .$x. '">' .$x. '</a> '; } } ?> thanks. Hi guys, please go to this url , http://mcfly1111.blogspot.com/2011/01/pagination.html . i typed out everything there. ifyou can correct my codes, that will be great but any help will be appreciated, thanks! Hello! I have a database of small image / names that I want to pull into a 3 x 4 table. My current code works perfectly if I have 12 images or less, but I will have more than 12 images. Currently the code is set up to retrieve and display the images in a table, three per table row. I want it so that when it reaches the 4th row in a page it generates a link to another page that has the next 3 x 4 (12 total images) page. I tried to follow the code on http://www.phpfreaks.com/tutorial/basic-pagination, but after I get it to what I think it should be, my page is blank -- but not due to an error, it's just blank. My code so far is: <?php $username = "xxxx"; $password = "xxxxx"; $host = "localhost"; $database = "images"; $conn = mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error()); $db = mysql_select_db($database) or die("Can not select the database: ".mysql_error()); $sql = "SELECT * FROM block_work ORDER BY Name"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); header('Content-type: image/jpg'); $counter = 0; while ($row = mysql_fetch_array($result)) { if($counter==0) print "<tr align='center'>"; ++$counter; print "<td align='center' width='179' height='200'><img src='/management/show.php?id=" . $row['id'] . "&table=block_work' alt='" . $row['name'] . "' /><br/>"; print "<b>" . $row['name'] . "</b></td>"; if($counter==3) { $counter=0; print "</tr>"; }; }; while ($counter>0) { ++$counter; print " <td> </td>"; if($counter==3) { $counter=0; print "</tr>"; } } print "</table>"; mysql_close($con); ?> Thanks very much for any help! -Gerry |