php - Allow user to enter comma separated values into input and return unique items -


i using php amazon's product advertising api have user enter isbn number search form , have return product info.

is there way allow user enter multiple isbn numbers, separated comma, , return product info each number entered?

here have far works:

//allow users enter multiple isbn, separated comma $myvalue = $_post['isbnnum']; $arrs = explode(", ", $myvalue);  $similar = array(     'operation'     => 'itemlookup',     'idtype'        => 'isbn',     'itemid'        => $myvalue,     'searchindex'   => 'books',     'responsegroup' => 'medium'     );  $result = $amazon->queryamazon($similar); $similar_products = $result->items->item;  //arrays $aws_items = array();  //array counter $i = 0;  foreach($similar_products $si){     $item_url = $si->detailpageurl; //get amazon url     $img = $si->mediumimage->url; //get image url      $title  = $si->itemattributes->title;    //product title     $isbn   = $si->itemattributes->isbn;    //product title     $price  = $si->offersummary->lowestnewprice->formattedprice;     //product price     $weight = $si->itemattributes->itemdimensions->weight;      //product weight      //item array     $item = [];     $item['title']  = $title;     $item['price']  = $price;     $item['weight'] = $weight;     $item['isbn']   = $isbn;      //add decimal point 2 spaces right of product dimensions     $length = number_format(($si->itemattributes->itemdimensions->length/100),2);  //item length     $width  = number_format(($si->itemattributes->itemdimensions->width/100),2);    //item width     $height = number_format(($si->itemattributes->itemdimensions->height/100),2);  //item height      //print html     echo '<div class="isbn-item">';         echo '<img src="' . $img . '" />';         echo '<h2>' . $title . '</h2>';         echo '<p>' . $item['isbn'] . '</p>';   //isbn         /*echo '<p>' . $si->itemattributes->listprice->formattedprice . '</p>'; //item price*/         echo '<p>' . $item['price'] . '</p>';         echo '<p>' . $length . ' x ' . $width . ' x ' . $height . ' inches</p>';         echo '<p>' . $weight . ' ounces</p>';         echo '<input name="submit" type="submit" value="add cart">';     echo '</div>';      //increment counter 1     $i++; } 

edit: added the explode part @ top, , returning multiple items. however, in html, since outputting $myvalue, each item getting isbn values entered, instead of 1 associated them. understand need access $arrs array (right?), i'm no sure where/how.

edit 2: why wouldn't echo '<p>' . $arrs[$myvalue] . '</p>'; work?

edit 3: updated code working code adds each books isbn corresponding book.

$myvalue string of isbns right?

so, $arrs[$myvalue] won't work because because need access elements integer index.

if change loop use $key=>$val syntax, can this:

foreach($similar_products $index=>$si){       ...         echo '<p>' . $arrs[$index] . '</p>';    //isbn    ... } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -