Jump to content

Recommended Posts

Hey guys! I've been having trouble with this all day. I'm wanting to display my results in rows. Like, 4 results in 1 row, then another 4, then another 4, etc. like this:

IMAGE  IMAGE IMAGE IMAGE

IMAGE IMAGE IMAGE IMAGE

IMAGE IMAGE IMAGE IMAGE

 

I'm nto sure how to do that. I want to display pictures. Here is my code for the page:

bag.php:

<?php
session_start();
include("config536.php");
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<?php
if(!isset($_SESSION['username'])) {
echo "<ubar><a href=login.php>Login</a> or <a href=register.php>Register</a></ubar><content><center><font size=6>Error!</font><br><br>You are not Logged In! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue!</center></content><content><center><font size=6>Inventory</font><br><br></center></content>";
}

if(isset($_SESSION['username'])) {
echo "<nav>$shownavbar</nav><ubar><img src=/images/layout/player.gif><a href=status.php>$showusername</a>.......................<img src=/images/layout/coin.gif> $scredits</ubar><content><center><font size=6>Inventory</font><br><br>";

$action = $_GET['action'];
$gid = $_GET['itemid'];

$irow = "SELECT * FROM uitems WHERE username='$showusername'";
$iquery = mysql_query($irow);
while($ir = mysql_fetch_array($iquery)) {
$uid = $ir['uitemid'];
$iid = $ir['theitemid'];
$iun = $r['username'];
$il = $ir['location'];


$tirow = "SELECT * FROM items WHERE itemid='$iid'";
$tiquery = mysql_query($tirow);
while($tir = mysql_fetch_array($tiquery)) {
$tiid = $tir['itemid'];
$tin = $tir['name'];
$tiim = $tir['image'];
$tid = $tir['description'];
$tirr = $tir['rarity'];
$tit = $tir['type'];
$tiu = $tir['uses'];
$tis = $tir['strength'];
$tide = $tir['defense'];
$tih = $tir['heals'];

echo "<img src=/images/items/$tiim><br>$tin<br><br>";
}
}

}
?>

</html>

I have no errors, everything works great! It's just I'm not sure how to display them the way I want them. Right now they are displayed like this:

IMAGE

IMAGE

IMAGE

IMAGE

 

Any help is greatly appreciated, thank you!

Something like this:

$maxColumns = 4;

$i = 1;

while($tir = mysql_fetch_array($tiquery)) {
     if ($i == ($maxColumns + 1)) {
          echo '<br />';
          $i = 1;
     }
     
     // echo image

     $i++
}

For this effect you use the modulus operator along with a counter

 

Example, using part of your code

$count = 0;
while($tir = mysql_fetch_array($tiquery)) {
$tiid = $tir['itemid'];
$tin = $tir['name'];
$tiim = $tir['image'];
$tid = $tir['description'];

echo "";
if($count % 4) echo "
\n";

$count++;
}

have a look at this thread

 

http://www.phpfreaks.com/forums/index.php?topic=348868.msg1646003#msg1646003

 

I read the other day that you can semantically associate tags with images in HTML5 so have a hunt around on Google and see what you can find.

Sorry to jump in on this one. What does the modulus evaluate to in your if statement?

 

Is it looking for a division by four that has no remainder and if it finds it the statement is true?

 

 

 

 

For this effect you use the modulus operator along with a counter

 

Example, using part of your code

$count = 0;
while($tir = mysql_fetch_array($tiquery)) {
$tiid = $tir['itemid'];
$tin = $tir['name'];
$tiim = $tir['image'];
$tid = $tir['description'];

echo "<img src=/images/items/$tiim>";
if($count % 4) echo "<br />\n";

$count++;
}

Sorry the reason i asked my question is because I thought you had to say something like

 

 

if ($count % 4 == 0) {

// Do the new line
}


When I tried using just

[code] 
if($count % 4){
// Do the new line
}

 

 

It didn't work for me and just echoes the new line constantly :/ So trying to figure out if I'm doing something wrong or misundestanding the way it works. Or whether the code should have ==0 for this sort of function.

 

For this effect you use the modulus operator along with a counter

 

Example, using part of your code

$count = 0;
while($tir = mysql_fetch_array($tiquery)) {
$tiid = $tir['itemid'];
$tin = $tir['name'];
$tiim = $tir['image'];
$tid = $tir['description'];

echo "<img src=/images/items/$tiim>";
if($count % 4) echo "<br />\n";

$count++;
}

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.