you can see the image that i upload to see what this code below is dowing. it make 3 cols and 6 rows table.

echo"
            <div id = 'index_content_page_wrapper'>
                <br/> <br/>
                <table border='1px'  cellspacing='0' cellpadding='0'>
                      <tr width='1075' height='250px'>
                        <td width='355'>image 1</td>
                        <td width='355'>image 2</td>
                        <td width='355'>image 3</td>
                      </tr>
                      <tr>
                        <td>random text 1</td>
                        <td>random text 2</td>
                        <td>random text 3</td>
                      </tr>
                      <tr>
                        <td>random text 4</td>
                        <td>random text 5</td>
                        <td>random text 6</td>
                      </tr>
                     <tr width='1075' height='250px'>
                        <td>image 4</td>
                        <td>image 5</td>
                        <td>image 6</td>
                      </tr>
                      <tr>
                        <td>random text 10</td>
                        <td>random text 11</td>
                        <td>random text 12</td>
                      </tr>
                      <tr>
                        <td>random text 13</td>
                        <td>&random text 14</td>
                        <td>random text 15</td>
                      </tr>
                    </table>

                ";

this php code is printing all images inside a folder. bc i dont know how many images are in folder, that why iam doing inside a while loop. and it does print all images in folder.

$user_name_c = $_COOKIE['username'];
$item_query = mysql_query("SELECT * FROM item");
while($row = mysql_fetch_assoc($item_query))
{   
    $image_user_name_db = $row['image_user_name'];
    $image_folder_name_db = $row['image_folder_name'];
    $price_db = $row['price'];

    echo"<img src='IMAGE/ITEMS/$image_folder_name_db' />";
}

the problem is that i want to print images inside this:

    <td wid <td width='355'>image 2</td>
     <td='355'>image 1</td>
      <td width='355'>image 3</td>
     <td>image 4</td>
     <td>image 5</td>
       td>image 6</td>

and i can print its name "$image_user_name_db" inside

 <td>random text 1</td>
                        <td>random text 2</td>
                        <td>random text 3</td>
                         <td>random text 10</td>
                        <td>random text 11</td>
                        <td>random text 12</td>

and print its price "$price_db" inside this

 <td>random text 4</td>
                        <td>random text 5</td>
                        <td>random text 6</td>
                        <td>random text 13</td>
                        <td>&random text 14</td>
                        <td>random text 15</td>

any ides's how can i do this task?

Recommended Answers

All 13 Replies

it's quite fuzzy what you wanted to do, but the way you have sorted the TDs and separated each column I'm guessing if this is what you wanted.

Initialize table_image_names, table_item_prices, table_username

Prepare DB Connection

Get DB Result

Get each DB result row
    table_image_names   .= DB_Result[IMAGE_NAME]
    table_item_prices   .= DB_Result[ITEM_PRICE]
    table_username      .= DB_Result[USERNAME]

Table_Content = Concatenate(table_image_names, table_item_prices, table_username)

is it something like this?

ops i forgot to upload the image. hope it helps what the code is doing. i am trying to print image inside image box. i was thinking this:

echo"
            <div id = 'index_content_page_wrapper'>
                <br/> <br/>
                <table border='1px'  cellspacing='0' cellpadding='0'>
                ";


    $user_name_c = $_COOKIE['username'];
    $item_query = mysql_query("SELECT * FROM item");
    while($row = mysql_fetch_assoc($item_query))
    {   
        $image_user_name_db = $row['image_user_name'];
        $image_folder_name_db = $row['image_folder_name'];
        $price_db = $row['price'];

        echo"<img src='IMAGE/ITEMS/$image_folder_name_db' />";
    }



echo"
</table>
</div>";

Your HTML code for your image is correct, but I want to know if your
$image_folder_name_db
says what it is, just a folder? or misnamed vatiable of image filename?

you have to have this as an output, for you to view an image. (example in JPEG format)
<img src='IMAGE/ITEMS/someImageFilename.jpeg' />

i am storing this image name in $image_folder_name_db. les say there are 3 images(a.png, b.jpg, c.jepg) in side a folder. ("src='IMAGE/ITEMS/$image_folder_name_db"). than $image_folder_name_db will be a.png, than b.jpg, than c.jepg sice its inside a while loop.

Member Avatar for diafol

So you've only got a path, not actual filenames in the DB? So all files in a single 'path' will have the same price? If otherwise, please say, as it's a looking a bit confusing.

So what you mean is it contains the actual filename of the images. And once $image_folder_name_db is resolved, example $image_folder_name_db = "myImage.jpeg". The src='IMAGE/ITEMS/$image_folder_name_db would echo this src='IMAGE/ITEMS/myImage.jpeg"?

If so, you have to check and access your image with a relative path in your Browser like this:
http://yourdomain.com/IMAGE/ITEMS/myImage.jpeg

Make sure to change the filename. Then if you can't access it, be sure the path and your image exist in your Web Doc Root. Otherwise, you have a problem of either, a misplaced or non-existent images or worse having a misconfigured server.

Tell us your findings, though. So we can help. :)

when user upload a image. i am storing that image in folder. and i am storing image name(a.png), price, etc.. in database.(all image information in database but not image.)

than i am getting that image name from database by $image_folder_name_db. than i am checking that name in folder and print that image. so for ex:

//check user in loged in
    $user_name_c = $_COOKIE['username'];            
         //item(table) where image info is store ex(image name, price etc.. )
         //but image is not store in database
    $item_query = mysql_query("SELECT * FROM item");
    //loop so i can get all image info one by one
    //1st time ill get 1st image name, 2nd time ill get 2nd name etc...
    while($row = mysql_fetch_assoc($item_query))
    {   
                //get image name from database
        $image_folder_name_db = $row['image_folder_name']; 
        $price_db = $row['price'];                          //get price of image
               //now look for  $image_folder_name_db(a.png) in my 
               //folder where the image is store. and print it
        echo"<img src='IMAGE/ITEMS/$image_folder_name_db' />"; 
    }

Please use "and" than "than" in you sentence, especially when you're not comparing. Sorry if I sound rude, but I just want to help you out so people will be able to better understand and help you as well.

Anyway, I do understand that you wanted to place the path of your image in your image tag. But what we need to know if you were able to access the images using the path you provided in your image tag. Say if your path is "/IMAGE/ITEMS/" and your image filename is "a.png", you can access your image in your browser through:
http://localhost/IMAGE/ITEMS/a.png
See the difference?
Now, if you can access the image, you shouldn't have any problem displaying it in the IMG tag. By the way, put the '/' before your image path: from this src='IMAGE/ITEMS/$image_folder_name_db' to this src='/IMAGE/ITEMS/$image_folder_name_db'

Let us know what happened.

sorry, just bear with me plz. i am not good at explaing things. let me try again.

printing images and place the path(src) is not the problem. this code below seem to be working fine and bc its in while loop it prints all the images inside the folder.

echo"<img src='IMAGE/ITEMS/$image_folder_name_db' />";

the problem is that i was to organization the images and its information in a tables tag. i upload a image file for a ex table. in table i want to print 3 images and below its informations. than 3 images and its information.

this begining of table is fine. here i am just getting image information from database.

    echo"<table border='1px'  cellspacing='0' cellpadding='0'>";

        /***main page content ***/
        $user_name_c = $_COOKIE['username'];
        $item_query = mysql_query("SELECT * FROM item");
        while($row = mysql_fetch_assoc($item_query))     
        {   
            $image_user_name_db = $row['image_user_name'];
            $image_folder_name_db = $row['image_folder_name'];
            $price_db = $row['price'];

this is where the problem starts. ith <tr>'s and <td>'s. if you look at 2nd image that i upload. that is what this code below is doing. there is only one col. but i want 3 col's.

    echo"<tr width='1075' height='250px'>";
    echo"<td> <img src='IMAGE/ITEMS/$image_folder_name_db'/> </td>";
    echo"</tr>";

    echo"<tr width='1075' height='250px'>";
        echo"<td> $image_user_name_db </td>";
    echo"</tr>";

    echo"<tr width='1075' height='250px'>";
        echo"<td> $price_db </td>";
    echo"</tr>";
}


echo"
        </table>
    ";
Member Avatar for LastMitch

@hwoarang69

this is where the problem starts. ith <tr>'s and <td>'s. if you look at 2nd image that i upload. that is what this code below is doing. there is only one col. but i want 3 col's.

This shopping cart is very unorganized. You want 3 columns?

This is how you echo 3 columns:

echo"<tr width='1075' height='250px'>";
echo"<td> <img src='IMAGE/ITEMS/$image_folder_name_db'/> </td>";
echo"<td> $image_user_name_db </td>";
echo"<td> $price_db </td>";
echo"</tr>";

It's ok. :)

Anyway, the problem with how you echo your table is it really wanted to show a one column table. It's structure looks like this:

<table>
<tr>
    <td>... [IMAGE] ...</td>
</tr>
<tr>
    <td>... [USERNAME] ...</td>
</tr>
<tr>
    <td>... [PRICE] ...</td>
</tr>
<tr>
    <td>... [IMAGE] ...</td>
</tr>
<tr>
    <td>... [USERNAME] ...</td>
</tr>
<tr>
    <td>... [PRICE] ...</td>
</tr>
<tr>
    <td>... [IMAGE] ...</td>
</tr>
<tr>
    <td>... [USERNAME] ...</td>
</tr>
<tr>
    <td>... [PRICE] ...</td>
</tr>
</table>

And this is what you currently have.

What you need is a structure like this one
Sample Structure in Table 1
Sample Structure in Table 2

thanks for the links. it was alot helpfull

You're most welcome :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.