Jump to content

Please forgive my stupidity.. :\


JohnnyKennedy

Recommended Posts

Okay, so I'm *trying* to build a site where in which one page allows the user to search through a public database of books ISBNDB.com by title, isbn etc.  In this page, the user is allowed to search by title, and what I'd like is for a page to return all of the results so that I can format them, and then link each one to it's own page..

 

What I'm having trouble doing, is finding out how to get the results to repeat, as right now I'm simply getting (what I assume) is the first record in the DB.  Please help me, anything would be appreciated.

 

Here's the code i'm using on the page which is returning results..

---

 

<?php

 

//search books

 

// Access key

$accessKey = "XXXXXXXX";

 

// Get Post variables

$content = $_POST['content'];

$query = $_POST['query'];

$save = $_POST['save'];

 

if ($save):

 

// Save text file

$handle = fopen ("books.txt", 'w');

fwrite($handle, stripslashes($content));

fclose($handle);

 

endif;

 

if ($query):

 

// Check for condition flag

switch (strtolower($query{0})) {

case "a":

    $condition = "Like New";

$query = substr($query, 1);

$adjustment = .50;

    break;

case "b":

    $condition = "Very Good";

$query = substr($query, 1);

    $adjustment = .25;

break;

case "c":

    $condition = "Good";

$query = substr($query, 1);

    $adjustment = .10;

break;

case "d":

    $condition = "Acceptable";

$query = substr($query, 1);

    $adjustment = 0;

break;

case "f":

    $condition = "Poor";

$query = substr($query, 1);

    $adjustment = -.10;

break;

default:

$condition = "Good";

    $adjustment = .10;

}

 

// Urls

$url_details = "http://isbndb.com/api/books.xml?access_key=$accessKey&results=details&index1=title&value1=$query";

$url_texts = "http://isbndb.com/api/books.xml?access_key=$accessKey&results=texts&index1=title&value1=$query";

$url_prices = "http://isbndb.com/api/books.xml?access_key=$accessKey&results=prices&index1=title&value1=$query";

$url_subjects = "http://isbndb.com/api/books.xml?access_key=$accessKey&results=subjects&index1=title&value1=$query";

 

// API lookup

$xml_prices = @simplexml_load_file($url_prices) or die ("File Error: XMLPrice") ;

$xml_details = @simplexml_load_file($url_details) or die ("File Error: XMLDetail") ;

 

// Parse Data

$isbn = $xml_prices->BookList[0]->BookData[0]['isbn'] ;

$title = $xml_prices->BookList[0]->BookData[0]->Title ;

$titleLong = $xml_prices->BookList[0]->BookData[0]->TitleLong ;

$authors = $xml_prices->BookList[0]->BookData[0]->AuthorsText ;

$publisher = $xml_prices->BookList[0]->BookData[0]->PublisherText ;

$dewey = $xml_details->BookList[0]->BookData[0]->Details[0]['dewey_decimal_normalized'] ;

$lcc = $xml_details->BookList[0]->BookData[0]->Details[0]['lcc_number'] ;

 

// Calculate average price (new)

$count = 0;

$total = 0;

$price = $xml_prices->BookList[0]->BookData[0]->Prices[0]->Price ;

foreach ($price as $price) {

    if ((string) $price['is_new']=="1" and (string) $price['currency_code']=="USD" and (string) $price['price']>0.1):

$price = number_format($price['price'],2);

$total = $price + $total;

$count++;

endif;

}

$priceNew = number_format(($total / $count),2);

 

// Calculate average price (used)

$count = 0;

$total = 0;

$price = $xml_prices->BookList[0]->BookData[0]->Prices[0]->Price ;

foreach ($price as $price) {

    if ((string) $price['is_new']=="0" and (string) $price['currency_code']=="USD" and $price['price']>0.1):

$price = number_format($price['price'],2);

$total = $price + $total;

$count++;

endif;

}

$priceUsed = number_format(($total / $count),2);

 

// Calculate estimated value based on current prices and condition

$value = number_format(($priceUsed+($adjustment*($priceNew-$priceUsed))),2);

 

// Write to text file//cancelled

 

endif;

 

?>

 

 

I thought that simply printing the $title variable would work, and it is - but, obviously, that's not repeating it.

 

Thanks in advance you guys. :)

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/256890-please-forgive-my-stupidity/
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

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