mdburden Posted March 18, 2009 Share Posted March 18, 2009 I am using PHPP 5 an an Apache Server 2, and a mySQL database. Each row of the database contains all of the information on a single item. I can display each item just fine with each item on a new row of the display table. What I want to do is display a 3 column table with all the data from one item in each cell. Using the php code below, I am able to display a 3 column table, however the same item displays in each cell of the same row. Can anyone helb me? // Setup and run query $query = "select * from items where name like '%".$searchterm."%'"; $result = $db->query($query); $num_results = $result->num_rows; echo "<p>Number of items found: ".$num_results."</p>"; // Display results echo "<table border= 1>"; for ($i=0; $i <$num_results; $i++) { $row = $result->fetch_assoc(); $Imge = stripslashes($row['imge']); echo "<tr>"; for ($c=0; $c < 3; $c++) { echo "<td>"; echo "<p><strong>Number: "; echo stripslashes($row['number']); echo "\t \t"; echo htmlspecialchars(stripslashes($row['title'])); echo stripslashes($row['name']); echo "</strong><br /></p>"; echo "<p align='center'><img border=\"0\" src=\"images/".$Imge."\"><br /></p>"; echo stripslashes($row['description']); echo "<br />Price: "; echo stripslashes($row['price']); echo "</p>"; echo "</td>"; } echo "</tr>"; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/150055-multi-column-tables/ Share on other sites More sharing options...
Stephen68 Posted March 18, 2009 Share Posted March 18, 2009 Looks like your not loop through each row that you have? is that what you are trying to do? shouldn't be something like this in there some place. while ($row = $result->fetch_assoc()) { } not sure since I don't code the OOP way as of yet Quote Link to comment https://forums.phpfreaks.com/topic/150055-multi-column-tables/#findComment-788089 Share on other sites More sharing options...
samshel Posted March 18, 2009 Share Posted March 18, 2009 is this a duplicate post? check my reply here..let me know if thats what ur looking for. http://www.phpfreaks.com/forums/index.php/topic,243735.0.html Quote Link to comment https://forums.phpfreaks.com/topic/150055-multi-column-tables/#findComment-788096 Share on other sites More sharing options...
mdburden Posted March 19, 2009 Author Share Posted March 19, 2009 Sorry, yes this is a duplicate post. computer froze and I was not sure if it had posted. Unfortunately, neither suggestion helped. The first, adding the WHILE loop produced invalid code. The second put thr script in an endless loop. any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/150055-multi-column-tables/#findComment-788436 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.