Stalingrad Posted December 1, 2011 Share Posted December 1, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/252245-i-want-to-display-my-result-in-rows-of-4/ Share on other sites More sharing options...
scootstah Posted December 1, 2011 Share Posted December 1, 2011 Something like this: $maxColumns = 4; $i = 1; while($tir = mysql_fetch_array($tiquery)) { if ($i == ($maxColumns + 1)) { echo '<br />'; $i = 1; } // echo image $i++ } Quote Link to comment https://forums.phpfreaks.com/topic/252245-i-want-to-display-my-result-in-rows-of-4/#findComment-1293222 Share on other sites More sharing options...
Zane Posted December 1, 2011 Share Posted December 1, 2011 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++; } Quote Link to comment https://forums.phpfreaks.com/topic/252245-i-want-to-display-my-result-in-rows-of-4/#findComment-1293223 Share on other sites More sharing options...
Zane Posted December 1, 2011 Share Posted December 1, 2011 If you want to put text underneath each image, then you'll need to either create a span element with some CSS modifications or... use a table. Quote Link to comment https://forums.phpfreaks.com/topic/252245-i-want-to-display-my-result-in-rows-of-4/#findComment-1293224 Share on other sites More sharing options...
Stalingrad Posted December 1, 2011 Author Share Posted December 1, 2011 thanks! how would i put the text underneath it? Quote Link to comment https://forums.phpfreaks.com/topic/252245-i-want-to-display-my-result-in-rows-of-4/#findComment-1293228 Share on other sites More sharing options...
Bazzaah Posted December 2, 2011 Share Posted December 2, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252245-i-want-to-display-my-result-in-rows-of-4/#findComment-1293402 Share on other sites More sharing options...
Drongo_III Posted December 2, 2011 Share Posted December 2, 2011 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++; } Quote Link to comment https://forums.phpfreaks.com/topic/252245-i-want-to-display-my-result-in-rows-of-4/#findComment-1293464 Share on other sites More sharing options...
Drongo_III Posted December 2, 2011 Share Posted December 2, 2011 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++; } Quote Link to comment https://forums.phpfreaks.com/topic/252245-i-want-to-display-my-result-in-rows-of-4/#findComment-1293471 Share on other sites More sharing options...
Zane Posted December 2, 2011 Share Posted December 2, 2011 yes, my bad.. You are supposed to compare it to zero. IOW, $count % 4 == 0 Quote Link to comment https://forums.phpfreaks.com/topic/252245-i-want-to-display-my-result-in-rows-of-4/#findComment-1293474 Share on other sites More sharing options...
Drongo_III Posted December 2, 2011 Share Posted December 2, 2011 Ahh sry wasn't trying to be pedantic i was just wondering if i was doing something wrong...as seems to happen every ten lines of code i write haha yes, my bad.. You are supposed to compare it to zero. IOW, $count % 4 == 0 Quote Link to comment https://forums.phpfreaks.com/topic/252245-i-want-to-display-my-result-in-rows-of-4/#findComment-1293475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.