Jump to content

Recommended Posts

Hi

 

I am creating an e commerce website and I have been using a php dummies book to help me as I am a beginner. I am creating an e commerce website and I have created a page which consists of radio buttons where a user will be able to choose what type of shoe they would like to view. Once they have chosen the radio button and then clicked onto the show me button the type of shoe shown should be the same as the type they have chosen but no shoes are showing on the webpage. I am unsure if i have not entered the format correct in the image section of the database. Here is the code which i have created so far:

 

/* Select shoes the type specified*/

$query = "SELECT * FROM products

            WHERE prod_type=\"{$_POST['interest']}\"";

$result = mysqli_query($cxn,$query)

          or die ("Couldn't execute query.");

 

/* Display results in a table */

echo "<table cellspacing='10' border='1' cellpadding='87'

              width='100%'>";

echo "<tr><td colspan='5' style='text-align: right'>

            Click on any picture to see a larger

                version. <hr /></td></tr>\n";

while($row = mysqli_fetch_assoc($result))           

{

  $f_price = number_format($row['product_price'],2);

 

 

             

 

  /* display row for each shoe */

  echo "<tr>\n";

  echo " <td>{$row['product_id']}</td>\n";

  echo " <td style='font-weight: bold;

            font-size: 1.1em'>{$row['product_name']}</td>\n";

  echo " <td>{$row['product_description']}</td>\n";

 

  echo "<tr><td colspan='5'><hr /></td></tr>\n";

}

echo "</table>\n";

echo "<div style='text-align: center'>

      <a href='shoes_list.php'>

            <h3>See more shoes</h3></a></div>";

?>

 

in my database the product_image column the field just contains the file name e.g: heels.jpg.

 

please can anyone help me to get the images displayed.. thank you

I don't see anyhing in your output that would generate an image in the output. Typically, the image path/name of the image is stored in the database and then when generating the output you would do something such as

echo "<img str='{$row['product_image']}' />

 

But, again, I don't even see a field referenced in the output that would seem to be an image. Also, you *can* store the actual image data in the DB and dynamically create the images, but that's a little more complicated and not what I think you want at this time.

 

So, what is the field in the DB where you are storing the image info and what do those contents contain?

here is my revisted code:

 

<?php

 

include("connect_db.inc");

 

$cxn = mysqli_connect($host,$user,$password,$dbname)

        or die ("couldn't connect to server");

 

/* Select shoes the type specified*/

$query = "SELECT * FROM products

            WHERE prod_type=\"{$_POST['interest']}\"";

$result = mysqli_query($cxn,$query)

          or die ("Couldn't execute query.");

 

/* Display results in a table */

echo "<table cellspacing='10' border='1' cellpadding='87'

              width='100%'>";

echo "<tr><td colspan='5' style='text-align: right'>

            Click on any picture to see a larger

                version. <hr /></td></tr>\n";

while($row = mysqli_fetch_assoc($result))           

{

  $f_price = number_format($row['product_price'],2);

/* check whether shoes comes in colors */

  $query = "SELECT * FROM Colour

                  WHERE product_name='{$row['product_name']}'";

  $result2 = mysqli_query($cxn,$query)

              or die(mysqli_error($cxn));           

  $ncolors = mysqli_num_rows($result2);             

 

  /* display row for each shoe */

  echo "<tr>\n";

  echo " <td>{$row['product_id']}</td>\n";

  echo " <td style='font-weight: bold;

            font-size: 1.1em'>{$row['product_name']}</td>\n";

  echo " <td>{$row['product_description']}</td>\n";

  /* display picture if shoe does not come in colours */

  if( $ncolors <= 1 )                               

  {

      echo "<td><a href='/images/{$row['product_image']}'

                          border='0'>

                  <img src='/images/{$row['product_image']}'

                  border='0' width='100' height='80' />

                </a></td>\n";

  }

  echo "<td align='center'>\$$product_price</td>\n

        </tr>\n";

  /* display row for each colour  */

  if($ncolors > 1 )                                 

  {

      while($row2 = mysqli_fetch_assoc($result2))   

      {

        echo "<tr><td colspan=2> </td>

                  <td>{$row2['product_colour']}</td>

                  <td><a href='/images/{$row2['product_image']}'

                            border='0'>

                      <img src='/images/{$row2['product_image']}'

                        border='0' width='100'

                        height='80' /></a></td>\n";

      }

  }

  echo "<tr><td colspan='5'><hr /></td></tr>\n";

}

echo "</table>\n";

echo "<div style='text-align: center'>

      <a href='shoes_list.php'>

            <h3>Display more shoes</h3></a></div>";

?>

 

im not sure if the <a href..... link to my image is correct im not sure how to format it. my image directory is:        C:\inetpub\wwwroot\shop\images

You can use either absolute file paths or relative file paths.

 

Example:

<?php
echo "<img src=\"http://www.mysite.com/shop/images/{$row['product_image']}\" />"; //absolute path.

echo "<img src=\"shop/images/{$row['product_image']}\" />"; //relative path.

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.