MDanz Posted August 5, 2009 Share Posted August 5, 2009 i'd like to echo my search results into a table.. but say there is multiple results e.g. echo <table><td><tr>$results</tr></td> </table> say i had two results it would be echo <table><td><tr>$results</tr><tr>$results</tr></td> </table> how do i do this 1 column, multiple rows for multiple results? Link to comment https://forums.phpfreaks.com/topic/169005-solved-echo-search-results-into-a-table/ Share on other sites More sharing options...
smerny Posted August 5, 2009 Share Posted August 5, 2009 if it's just one column i'd probably do something besides a table, like divs. but you just have to start the table before the loop and end it after... echo "<table>"; while ($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['results']."</td></tr>"; } echo "</table>"; edit: i'm assuming you mean results from a database, guess you never specified where you are getting them from Link to comment https://forums.phpfreaks.com/topic/169005-solved-echo-search-results-into-a-table/#findComment-891703 Share on other sites More sharing options...
MDanz Posted August 5, 2009 Author Share Posted August 5, 2009 hi, while ($runrows = mysql_fetch_assoc($run)) { //get data $name = $runrows['name']; $image = $runrows['image']; $hyperlink = $runrows['hyperlink']; $currency = $runrows ['currency']; $info = $runrows ['info']; echo " <b>$name</b><br> <img src='$image'> <br> <a href='$hyperlink'>$hyperlink</a><p> "; this is what i'm echoing at the moment.. i trying for the image in the column 1 row and the next row a new image. so i changed to this while ($runrows = mysql_fetch_assoc($run)) { //get data $name = $runrows['name']; $image = $runrows['image']; $hyperlink = $runrows['hyperlink']; $currency = $runrows ['currency']; $info = $runrows ['info']; echo "<table>"; while ($runrows = mysql_fetch_array($run)) { echo "<tr><td>".$runrows['image']."</td></tr>"; } echo "</table>"; it is working but not displaying image, any idea why? Link to comment https://forums.phpfreaks.com/topic/169005-solved-echo-search-results-into-a-table/#findComment-891718 Share on other sites More sharing options...
machiavelli1079 Posted August 5, 2009 Share Posted August 5, 2009 is image a hyperlink? how is the image field stored in the db? you would probably need to echo the appropriate <img> tag inside the <td>. I may be oversimplifying - please let me know. thanks, b Link to comment https://forums.phpfreaks.com/topic/169005-solved-echo-search-results-into-a-table/#findComment-891719 Share on other sites More sharing options...
MDanz Posted August 5, 2009 Author Share Posted August 5, 2009 yeh the image is a hyperlink.. before i displayed it like this <img src='$image'> Link to comment https://forums.phpfreaks.com/topic/169005-solved-echo-search-results-into-a-table/#findComment-891721 Share on other sites More sharing options...
MDanz Posted August 5, 2009 Author Share Posted August 5, 2009 i changed it to this while ($runrows = mysql_fetch_assoc($run)) { //get data $name = $runrows['name']; $image = $runrows['image']; $hyperlink = $runrows['hyperlink']; $currency = $runrows ['currency']; $info = $runrows ['info']; echo "<table> while ($runrows = mysql_fetch_array($run)) { <tr><td><img src='$image'></td></tr>; } </table>"; its showing the image, i have no idea if its in a table but before the image i get this message "while (Array = mysql_fetch_array(Resource id #2)) { ; } " :'( Link to comment https://forums.phpfreaks.com/topic/169005-solved-echo-search-results-into-a-table/#findComment-891727 Share on other sites More sharing options...
machiavelli1079 Posted August 5, 2009 Share Posted August 5, 2009 If you want to PM me the code I can take a look. I find tables really irritating because they are hard for me to keep track of. I usually CSS border the td element in the table for troubleshooting and formatting purposes. You are getting the "while (Array = " because it is contained in your echo statement from the previous line. try this: //start table output here otherwise you will be writing a <table> tag for every mysql_fetch_assoc echo '<table>'; //one row at a time while($runrows=mysql_fetch_assoc($run)) { $name=$runrows['name']; $image=$runrows['image']; $hyperlink=$runrows['hyperlink']; $currency=$runrows['currency']; $info=$runrows['info']; echo '<tr>'; echo '<td><img src='.$image.'></td>'; echo '<tr />'; } echo '</table>'; Link to comment https://forums.phpfreaks.com/topic/169005-solved-echo-search-results-into-a-table/#findComment-891748 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.