Jump to content

Oracle & PHP Help :)


Recommended Posts

Hi all,

 

I know this is a big ask - but i'm new to all this and I was just wondering if someone could point me in the right direction?

 

It's hard to explain what I want to do - but i'll try.

 

Basically i'm building a catalog. I retrieve all of the information from my Oracle database, including the picture path. As you can see, the code is in a loop, so it just loops from the first entry to the last and puts all the data in a table. When I click on the picture for any given product, it takes me to the product details page based on the books ISBN number. I.e. 'ISBN_NUMBER.html'.

 

This is where i'm stuck. Once I get to the product details page, I need to write a 'SELECT where' statement based on the ISBN number that I just clicked on. So what I need to somehow do is get the ISBN number either from the previous page or from the URL and then insert it in the 'SELECT where' statement so it brings up all of the information about that product.

 

Does that make sense?

 

Here's the current code for the catalog page: I have put ****'s beside the line in question.

 

  <?php
    $db_conn = oci_connect("bookfair", "books", "//127.0.0.1/XE");

    $cmdstr = "select BK_TITLE, BK_PRICE, BK_PHOTO, BK_ISBN from BOOKS";

    $parsed = ociparse($db_conn, $cmdstr);
    ociexecute($parsed);

    $nrows = ocifetchstatement($parsed, $results);

    echo "<table border=1 cellspacing='0' width='80%'>\n<tr>\n";
    echo "<td><font color=white><b>Title -</b></td>\n<td><font color=white><b>Price-</b></td>\n<td><font color=white><b>Photo -</b></td>\n</tr>\n";

    for ($i = 0; $i < $nrows; $i++ )
    {
      echo "<tr>\n"; 
      echo "<td><input type=checkbox name=product> <font color=white>" . $results["BK_TITLE"][$i] . "</td>";
      echo "<td><font color=white>$ " . number_format($results["BK_PRICE"][$i],   2). "</td>";
      *****echo "<td><a href=/details/" . $results["BK_ISBN"][$i] . "><img src=" . $results["BK_PHOTO"][$i] . "></td>";*****
      echo "</tr>\n";
    }

  ?>

 

Any help much appreciated....

Link to comment
Share on other sites

  • 5 weeks later...

Yes, this is a common design.  There are several different paths depending on how you want to approach this.  To tell the truth this is something that isn't Oracle specific at all, but comes down to basic web application design.  In general there are frameworks out there that feature Model View Controller design pattern architectures that handle this.  I'm not going to get into all that, but I figured I'd at least mention it as best practice.

 

Assuming you want to keep it simple, the simplest solution is to write a new script which takes as a URL parameter, the ISBN number, or whatever primary key for the catalog you'd specify in your WHERE clause.

 

So your url should be something like:

 


echo "";

?>

 

In your showdetail.php, the first thing you would do is take this url parameter and set it to a variable you can then inject into your WHERE clause for the detail lookup.

 


$isbn = (int) $_GET['isbn'];

?>

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.