bickyz Posted February 20, 2010 Share Posted February 20, 2010 hi i have this code which displays search results vertically, how do i display results horizontally like 4 records in per row. <?php ini_set('display_errors',1); error_reporting(E_ALL); ?> <php? mysql_connect("localhost","user1","password"); mysql_select_db("dbimages"); $search=$_POST["search"]; $field=$_POST["field"]; if ($search == "") { echo "<p>You forgot to enter a search term"; exit; } $result = mysql_query("SELECT * FROM tblimg WHERE upper($field) LIKE '%$search%'"); while($r=mysql_fetch_array($result)) { $title=$r["firstname"]; $message=$r["surname"]; $imgurl=$r["imgurl"]; echo "$id <br> $title <br> $message <br> $imgurl <br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/192753-display-search-results-horizontally/ Share on other sites More sharing options...
Goat Posted February 20, 2010 Share Posted February 20, 2010 echo "$id $title $message $imgurl "; that should do it. Goat Link to comment https://forums.phpfreaks.com/topic/192753-display-search-results-horizontally/#findComment-1015399 Share on other sites More sharing options...
greatstar00 Posted February 20, 2010 Share Posted February 20, 2010 use table, and a increment counter like $i=1; echo '<table>'; while($r=mysql_fetch_array($q)){ if($i==1) echo '<tr>'; echo '<td>'."$id <br> $title <br> $message <br> $imgurl <br>".'</td>'; if($i==1) echo '</tr>'; if($i==4) $i=1; else $i++; } Link to comment https://forums.phpfreaks.com/topic/192753-display-search-results-horizontally/#findComment-1015406 Share on other sites More sharing options...
bickyz Posted February 21, 2010 Author Share Posted February 21, 2010 thanks greatstar00 but the results are displayed like this: A B C D E J M N O P S U V W X i.e. for example if there are 15 results from the search they displays like this first row displays 1 result second displays 4 results third displays 1 result fourth displays 4 results fifth displays 1 result sixth displays 4 results i dont why they are not displayed 4 results per row. Link to comment https://forums.phpfreaks.com/topic/192753-display-search-results-horizontally/#findComment-1015603 Share on other sites More sharing options...
jl5501 Posted February 21, 2010 Share Posted February 21, 2010 A correction to the code you were given earler $i=1; echo '<table><tr>'; while($r=mysql_fetch_array($q)) { echo '<td>'."$id <br> $title <br> $message <br> $imgurl <br>".'</td>'; if($i % 4 == 0) echo '</tr><tr>'; $i++; } echo '</tr></table>'; Link to comment https://forums.phpfreaks.com/topic/192753-display-search-results-horizontally/#findComment-1015621 Share on other sites More sharing options...
bickyz Posted February 22, 2010 Author Share Posted February 22, 2010 thanks jl5501 it worked perfectly and thanks to greatstar00. Link to comment https://forums.phpfreaks.com/topic/192753-display-search-results-horizontally/#findComment-1016019 Share on other sites More sharing options...
bickyz Posted February 22, 2010 Author Share Posted February 22, 2010 just a quick ques: how do i display text "No Results Found" if search cant find anything. this is my final code: <?php ini_set('display_errors',2); error_reporting(E_ALL); ?> <?php mysql_connect("localhost","user1","password"); mysql_select_db("dbimages"); $search=$_POST["search"]; $field=$_POST["field"]; if ($search == "") { echo "<p>You forgot to enter a search term"; exit; } $result = mysql_query("SELECT * FROM tblimg WHERE upper($field) LIKE '%$search%'"); $i=1; echo '<table><tr>'; while($r=mysql_fetch_array($result)) { $title=$r["firstname"]; $message=$r["surname"]; $imgurl=$r["imgurl"]; $vdourl=$r["vdourl"]; $id=$r["id"]; echo '<td>'."$id <br> $title <br> $message <br> $imgurl <br>".'</td>'; if($i % 4 == 0) echo '</tr><tr>'; $i++; } echo '</tr></table>'; ?> Link to comment https://forums.phpfreaks.com/topic/192753-display-search-results-horizontally/#findComment-1016035 Share on other sites More sharing options...
jl5501 Posted February 22, 2010 Share Posted February 22, 2010 just after you get $result if(mysql_num_rows($result)) { $i=1; echo '<table><tr>'; while($r=mysql_fetch_array($result)) { ........ ........ existing code } } else { echo 'No results found'; } Link to comment https://forums.phpfreaks.com/topic/192753-display-search-results-horizontally/#findComment-1016060 Share on other sites More sharing options...
bickyz Posted February 23, 2010 Author Share Posted February 23, 2010 thanks jl5501 for your support. Link to comment https://forums.phpfreaks.com/topic/192753-display-search-results-horizontally/#findComment-1016677 Share on other sites More sharing options...
bernardmoes Posted February 23, 2010 Share Posted February 23, 2010 i've got a better idea, just turn your display 90 degrees and you will see my answer Link to comment https://forums.phpfreaks.com/topic/192753-display-search-results-horizontally/#findComment-1016735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.