Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6886241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:44:05+00:00 2026-05-27T05:44:05+00:00

I am currently working on a loop to display items from a mysql table.

  • 0

I am currently working on a loop to display items from a mysql table. Is there a simple way to display 3 items per row. So far I managed to display all the items in a single row inside an html table . I would appreciate any help;
code (without html table tags) below:

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<?php
$database_name = "vog";
$conn = mysql_connect("localhost","root","toor");
mysql_select_db($database_name);

$sql = "select * from client1";

$result = mysql_query($sql) or die(mysql_error());
$num = mysql_num_rows($result); //Ελεγχος αν υπάρχουν εγγραφές!
?>

<?php
    if($num){
       while ($row = mysql_fetch_array($result))
    {
           echo $img_id = $row['img_id'];
 ?>

<form name="add2cart" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <?php echo $row['img_name'];?>
        <?php echo "<img src=".$row['img_path'].">";?>
<select name="color">
    <option>bnw</option>
    <option>sepia</option>
</select>
<input type="hidden" name="img_name" value="<?php echo $row['img_name']; ?>"> 
<input type="submit" name="add2cart" value="Add to cart"></input>
        <br />
</form> 
<?php
        } 
    }
    else{
        echo "Δεν υπάρχουν εγγραφές με τα κριτήρια που επιλέξατε";
    }
    //add2cart section
if(isset($_POST['add2cart'])){   
$img_name = $_POST['img_name'];
$color = $_POST['color'];
$sql_order ="insert into orders(item_id, img_name, color) 
values(' ', '$img_name',    '$color')";
$result = mysql_query($sql_order);
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:44:05+00:00Added an answer on May 27, 2026 at 5:44 am

    Declare a variable before your loop like: $currentRow = 1 and then inside, and at the end, of your loop add $currentRow++

    You can then check if your row is divisible by 3 if($currentRow % 3 == 0) and put a break in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m currently working out the design for simple graphic editor, who support trivial operations
I'm trying to get a nested loop working that will display 6 posts with
I'm currently working on an SSIS package to load mainframe logs from multiple server/file
I am currently working on an application that launches separate processes which display additional
I'm currently working on a small cute shell script to loop through a specific
I'm currently working on a DNA database class and I currently associate each row
I'm currently working on a project where I hide/show some table rows based on
I've got a fairly simple pagination algorithm here but it's not working the way
I am working on a new blog site, and I am far from seasoned
Currently working on a bespoke ecommerce application using Codeigniter. I have a products table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.