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"));

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.