Jump to content

array help with integration into e-commerce catalog


sheeps

Recommended Posts

I have an array that needs to display all titles and allow for a user to view titles based on the category, title, etc . I tried using the print_r() function but it didn't display the titles in a clean list. The only tutorials I've found utilize sql and i need to complete this without using SQL.

$books = array();
array_push($books,array("category" => "Nonfiction","title" => "The Innocent Man","author" => "Grisham","publisher" => "McGraw-Hill","price" => "34.99","isbn" 
=> "5985420166"));
array_push($books,array("category" => "Business","title" => "How to Make Money","author" => "Richy","publisher" => "Prentice-Hall","price" => "49.99","isbn" 
=> "8754739342"));
array_push($books,array("category" => "Romance","title" => "Twice Kissed","author" => "Jackson","publisher" => "McGraw-Hill","price" => "14.99","isbn" 
=> "5671230987"));

This is not an easy task. You do need to give more time to what you means by

allow for a user to view titles based on the category, title, etc .

Is it an alphabetical order of authors and are you committed to doing this in php only? Does view  by category mean only Romance novels or alphabetical listing of the categorizes?

 

Anyway the display is probably easier to do with a table. You echo out the table heading and css info. Here is how to get the info out of the array and into a row:

<?php
$category = $books[1]["category"];
$title = $books[1]["title"];
$author = $books[1]["author"];
$publisher = $books[1]["publisher"];
$price = $books[1]["price"];
$isbn = $books[1]["isbn"];

echo <<<EOD
<tr>
<td>$category</td>
<td>$title</td>
<td>$author</td>
<td>$publisher</td>
<td>$price</td>
<td>$isbn</td>
</tr>
EOD;
?>

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.