kevdoug Posted July 21, 2006 Share Posted July 21, 2006 [color=green]Sorry if this topics in the wrong place but I am new to this coding.[/color]As the subject say I am retrieving data from two database columns and would like to put it into multi columns. I can retrive it to appear in two columns no problem.The results currently go down the page where as I would like them to go across for say six columns and then automaticaly start a new row. Is there any way of setting the coumnls at six?I know it looks like I am not closing the <a> tag but I am it just shows up like [/url] for some strange reason. Here is the code I am using. [color=blue]while (OCIFetch($stmt)) { $img = OCIResult($stmt,'IMAGE'); $titl = OCIResult($stmt,'TITLE'); echo " <table> <tr> <td><a href=". $img ." target='new'><img src=' " . $img . "' height='75' width='100'></a> </td> </tr> <tr> <td> $titl </td> </tr> </table>"; } [/color] Link to comment https://forums.phpfreaks.com/topic/15217-multi-column-html-table-results-from-two-database-columns/ Share on other sites More sharing options...
trq Posted July 21, 2006 Share Posted July 21, 2006 This topic is covered in the FAQ/Code sepository. [url=http://www.phpfreaks.com/forums/index.php/topic,95426.0.html]Here[/url]. Link to comment https://forums.phpfreaks.com/topic/15217-multi-column-html-table-results-from-two-database-columns/#findComment-61494 Share on other sites More sharing options...
kevdoug Posted July 21, 2006 Author Share Posted July 21, 2006 [quote author=thorpe link=topic=101332.msg400980#msg400980 date=1153452850]This topic is covered in the FAQ/Code sepository. [url=http://www.phpfreaks.com/forums/index.php/topic,95426.0.html]Here[/url].[/quote]As I have said I am new to PHP and coding in general I have tried following the code in the link but have had no success especially as I use Oracle database and the code is for MySQL. I have posted my code below any help would be appreciated. [color=blue]<?php$usrname = $_COOKIE[user_cookie]; $conn = OCILogon("kevin", "kevin", "") or die ("connection failed"); $stmt = OCIParse($conn, "select * from product where user_name = '$usrname' "); OCIExecute($stmt); $img = OCIResult($stmt,'IMAGE'); if($stmt > 0){ $i = 0; $max_columns = 3; while (OCIFetch($stmt)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($img != "" && $img != null) echo "<td>$img</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while} // end if results// clean up table - makes your code valid!if($i < $max_columns){ for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; OCIFreeStatement($stmt); OCILogoff($conn);} ?>[/color] Link to comment https://forums.phpfreaks.com/topic/15217-multi-column-html-table-results-from-two-database-columns/#findComment-61656 Share on other sites More sharing options...
HeyRay2 Posted July 21, 2006 Share Posted July 21, 2006 What problem are you having with the code?Are you getting error messages?Is your table not printing correctly?A little more information is needed before we can truly help... :) Link to comment https://forums.phpfreaks.com/topic/15217-multi-column-html-table-results-from-two-database-columns/#findComment-61672 Share on other sites More sharing options...
kevdoug Posted July 21, 2006 Author Share Posted July 21, 2006 [quote author=HeyRay2 link=topic=101332.msg401221#msg401221 date=1153494471]What problem are you having with the code?Are you getting error messages?Is your table not printing correctly?A little more information is needed before we can truly help... :)[/quote]I am getting a blank page at the moment. The first code I posted returned the data in 2 columns down the page where I would like rows going across the page in say 6 columns and drop down for a new row. Link to comment https://forums.phpfreaks.com/topic/15217-multi-column-html-table-results-from-two-database-columns/#findComment-61676 Share on other sites More sharing options...
HeyRay2 Posted July 21, 2006 Share Posted July 21, 2006 The code for accessing your Oracle database won't change. You're simply changing the logic that prints out the values you pulled from the database, so you will only need the basic layout of the code example you are trying to use. Like so:[code]<?php$usrname = $_COOKIE[user_cookie];$conn = OCILogon("kevin", "kevin", "") or die ("connection failed");$stmt = OCIParse($conn, "select * from product where user_name = '$usrname' ");OCIExecute($stmt); $i = 0; // Your counter for which item in the column you are on$max_columns = 6; // The maximum columns per row// Start your table for your resultsecho "<table>"; // Run your while loop to start printing out your results while (OCIFetch($stmt)) { // Set your values to be printed in each "while" loop $img = OCIResult($stmt,'IMAGE'); $titl = OCIResult($stmt,'TITLE'); // open row if counter is zero if($i == 0){ echo "<tr>"; } echo "<td>"; // This is going to be a nested table to keep your results formatted correctly echo " <table> <tr> <td><a href=". $img ." target='new'><img src=' " . $img . "' height='75' width='100'></a></td> </tr> <tr> <td>$titl</td> </tr> </table>"; // close out the cell for the nested table echo "</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while// clean up table if we didn't fill a while row up to $max_columns - makes your code valid!if($i < $max_columns){ for($j=$i; $j<$max_columns;$j++){ // Print some blank cells to fill up empty space echo "<td> </td>"; } // Close the row if we are on the last column if($j == ($max_columns - 1)){ echo "</tr>"; }}// Release your database results and close the connectionOCIFreeStatement($stmt);OCILogoff($conn);// End the tableecho "</table>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/15217-multi-column-html-table-results-from-two-database-columns/#findComment-61700 Share on other sites More sharing options...
kevdoug Posted July 22, 2006 Author Share Posted July 22, 2006 Cheers HeyRay2 working fine now.I thought it was something to do with converting from MySQL to Oracle. But thats how you grow from being a newbie. Thanks again. Link to comment https://forums.phpfreaks.com/topic/15217-multi-column-html-table-results-from-two-database-columns/#findComment-62022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.