benji87 Posted September 20, 2006 Share Posted September 20, 2006 Hi all.Im looking for a bit of script that will display some sql results over three columns instead of down rows. For image thumbnails. I know someone has already put up a topic about this i tried to use the script but it was all too much for what im wanting i just want a bare bones script.Any help would be great! Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/ Share on other sites More sharing options...
Barand Posted September 20, 2006 Share Posted September 20, 2006 Have you looked in the forum FAQhttp://www.phpfreaks.com/forums/index.php/topic,95426.0.html Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-95365 Share on other sites More sharing options...
benji87 Posted September 20, 2006 Author Share Posted September 20, 2006 Thanks for the link that was really useful but its telling the that the msql_fetch_array() is an undefined function?? Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-95386 Share on other sites More sharing options...
redarrow Posted September 20, 2006 Share Posted September 20, 2006 This is easy connect database make a while loop get the information then format html properly and echo results.good luck. Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-95387 Share on other sites More sharing options...
benji87 Posted September 20, 2006 Author Share Posted September 20, 2006 Easy for who? Its only easy if you already know it. Why bother posting if your not willing to help.Dont reply as i dont want to flame Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-95391 Share on other sites More sharing options...
redarrow Posted September 20, 2006 Share Posted September 20, 2006 post what you got then then i do it usally users post code Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-95394 Share on other sites More sharing options...
benji87 Posted September 20, 2006 Author Share Posted September 20, 2006 Thanks for the help. I did not post code coz its basicly what barand sent me the link to:[code]<table cellspacing="3" cellpadding="3"><?phpinclude ("db.php");$query = "SELECT img_thumb FROM deck_imgs ORDER BY img_name";$result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0){ $i = 0; $max_columns = 3; while($row = mssql_fetch_array($result)) { // 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_thumb != "" && $img_thumb != null) echo "<td>$img_name</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>";} ?></tr></table>[/code] Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-95403 Share on other sites More sharing options...
redarrow Posted September 20, 2006 Share Posted September 20, 2006 while($row = mssql_fetch_array($result))towhile($row = mssql_fetch_assoc($result))Might work Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-95405 Share on other sites More sharing options...
benji87 Posted September 20, 2006 Author Share Posted September 20, 2006 Nope still the same error :( Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-95414 Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 There's a typo that hasn't been noticed.You're using mysql at the top and then mssql at the bottom... Notice the difference. You need [color=green]m[b][color=red]y[/color][/b]sql_fetch_array[/color]Change this:[code=php:0]while($row = mssql_fetch_array($result))[/code]to[code=php:0]while($row = mysql_fetch_array($result))[/code]RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-95425 Share on other sites More sharing options...
benji87 Posted September 20, 2006 Author Share Posted September 20, 2006 Thanks! Its always the obvious things! It worked fine trouble is now it wont display any data! >:( Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-95452 Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 ok,Try changing this:[code=php:0]while($row = mysql_fetch_array($result))[/code]to:[code=php:0]while($row = mysql_fetch_array($result, MYSQL_ASSOC))[/code]This way, extract($row) will import a variable of $img_name into the namespace, I think by default mysql_fetch_array() gets both names and numbers as an index, but by specifying MYSQL_ASSOC it gets only names, probably less overhead.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-95465 Share on other sites More sharing options...
jerastraub Posted September 27, 2006 Share Posted September 27, 2006 Hello, I am kinda new to php. I read the above posts about how to display results over columns:Here is my code:<table cellspacing="3" cellpadding="3"><?phpinclude ("config.php");?><?php$query = "SELECT Link,Image, Alt from pluswomens_frontimage_rotator ORDER by rand()";$result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0){ $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // 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($product != "" && $product != null) echo "<td><td><img src=$Image alt=$Alt border=0 align=bottom hspace=5 vspace=5></td></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>";} ?></tr></table>This is what displays:<table cellspacing="3" cellpadding="3"><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr><td> </td><td> </td></tr></table>Can someone tell me what I am doing wrong, and yes there is information in pluswomens_frontimage_rotator to pull. Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-99883 Share on other sites More sharing options...
HuggieBear Posted September 28, 2006 Share Posted September 28, 2006 This is the code that's causing problems...[code]// make sure we have a valid productif($product != "" && $product != null) echo "<td><td><img src=$Image alt=$Alt border=0 align=bottom hspace=5 vspace=5></td></td>";[/code]For the time being, remove the condition and see if it works at all... Try this:[code]// make sure we have a valid product// if($product != "" && $product != null) // temporary comment out echo <<<HTML <td><img src="{$Image}" alt="{$Alt}" border="0" align="bottom" hspace="5" vspace=5></td>HTML;[/code]RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-100178 Share on other sites More sharing options...
Barand Posted September 28, 2006 Share Posted September 28, 2006 $product is never set to a value. Try $image instead. Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-100181 Share on other sites More sharing options...
jerastraub Posted September 28, 2006 Share Posted September 28, 2006 You guys are awesome, works like a charm. I have been trying to find a way to do this for months, I guess I just had to come to the right place!!!! Link to comment https://forums.phpfreaks.com/topic/21410-displaying-results-over-columns/#findComment-100294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.