Jump to content

How to display my images along with mysql database table


mpsn

Recommended Posts

Hi, here's my problem: I am trying to make a simple online buying website and I want to display a table with all the fields for each item. So I got that part down which is to just use mysql_fetch_assoc("SELECT * FROM myTable") and use the html table tags stuff, but now I want to display my images in the table, so here's my code to display my mysql database table in html's table tag along w/ php:

 

 

<html>

<head>

<title>My Online buying website project</title>

</head>

 

<body>

<?php 

  mysql_connect("localhost","root");

  mysql_select_db("myTable");

  $imagesArray=array("Apple_iPhone3GS.jpg","Apple_iPhone4.jpg","product3.jpg","product4.jpg","product5.jpg");

 

  $result=mysql_query("SELECT Name, Manufacturer, Price, Description, SimSupport FROM myTable");

 

  if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table

  {

      print "<table border='border'>";

      print "<tr>

        <th>Name</th>

        <th>Manufacturer</th>

        <th>Price</th>

        <th>Description</th>

        <th>SimSupport</th>

          </tr>";

         

      //NB: now output each row of records

      while($row=mysql_fetch_assoc($result))

    {

        extract($row);

        print "<tr>

        <td>$Name</td>

        <td>$Manufacturer</td>

        <td>$Price</td>

        <td>$Description</td><td>$SimSupport</td>

        </tr>";

     

    }//END WHILE

           

  }//END IF

 

  ?>

</table>

</body>

</html>

 

*So how do I go about adding my images in this table?

$sql = mysql_query("SELECT [i]things you are trying to query[/i], FROM [i]Your table[/i]  WHERE [i]array='array'[/i] ORDER BY id looking_for ASC");

{/PHP]

replace where needed for you to complete your query (id, username,firstname[i]this should be replaced with the items you are querying[/i] then put in your table, finally your where should be equal to your array ORDER by ASC)

Thanks for replying and this is what I added but I'm still stuck:

<table border="border">

<?php 

  mysql_connect("localhost","root");

  mysql_select_db("bell");

  $bellProductsArray=array("Apple_iPhone3GS.jpg","Apple_iPhone4.jpg", "BB_Bold9780.jpg", "BB_Curve3G.jpg",

  "BB_PlayBook.jpg","BB_Torch9800.jpg","BB_Pearl3G.jpg","EricssonW35TurboHub.jpg","HTC_DesireZ.jpg",

  "HTC_HD7.jpg","HTC_IncredibleS.jpg","LG_OptimusChic.jpg","LG_OptimusQUantum.jpg",

  "LG_RumourPlus.jpg","Mot_Atrix.jpg","Mot_M800.jpg","Nokia_2730.jpg","Nokia_C6_01.jpg".

  "Palm_Pre.jpg","Samsung_Galaxy551.jpg","Samsung_GalaxyTab.jpg","Samsung_Rugby2.jpg",

  "Samsung_Entro.jpg","Sanyo_PRO700.jpg","Novatel_MiFi2372.jpg","Novatel_U547.jpg",

  "MicroSimCard.jpg","SimCard.jpg","ReceiverBasic.jpg","ReceiverHD.jpg","ReceiverHDPVR.jpg");

 

  $result=mysql_query("SELECT Name, Manufacturer, Price, Description, SimSupport FROM bellProducts WHERE array=$bellProductsArray");

  $indx=0;

 

  //NB: print table headings

  if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table

  {

    print "<table border='border'>";

    print "<tr>

      <th>Name</th>

      <th>Manufacturer</th>

      <th>Price</th>

      <th>Description</th>

      <th>SimSupport</th>

          </tr>";

     

         

    //NB: now output each row of records

    while($row=mysql_fetch_assoc($result))

    {

      extract($row);

     

      print

      "<tr>

        <td><img src='$bellProductsArray[$indx]' /></td>//***NEW CODE ADDED

        <td>$Name</td>

        <td>$Manufacturer</td>

        <td>$Price</td>

        <td>$Description</td>

        <td>$SimSupport</td>

      </tr>";

      $indx++; //***NEW CODE ADDED

     

    }//END WHILE

           

  }//END BIG IF

 

?>

 

</table>

 

</body>

</html>

 

**plz help, thx

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.