Current location: Hot Scripts Forums » Programming Languages » PHP » Horizontal search results display


Horizontal search results display

Reply
  #1 (permalink)  
Old 07-01-05, 08:14 AM
raggster raggster is offline
New Member
 
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Horizontal search results display

Hi, I found a tutorial for a mysql db search engine and I managed to get it working just fine. My problem is that I can't get the search results (image files) to display in multiple columns, I get one column with all the results instead. I figured out how to display data from the db horizontally but on a different page that has nothing to do with this one, I just can't figure out how to do it here.

Any help would be greatly appreciated!

Here's the code from the db search tutorial I used:
--------------------------------------
<HTML>
<?php
if ($searchstring)
{
$sql="SELECT * FROM personnel WHERE $searchtype LIKE '%$searchstring%' ORDER BY firstname ASC";
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb",$db);
$result = mysql_query($sql,$db);
echo "<TABLE BORDER=2>";
echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Options</B></TR>";
while ($myrow = mysql_fetch_array($result))
{
echo "<TR><TD>".$myrow["firstname"]." ".$myrow["lastname"]."<TD>".$myrow["nick"];
echo "<TD><a href=\"view.php?id=".$myrow["id"]."\">View</a>";
}
echo "</TABLE>";
}
else
{
?>
<form method="POST" action="<?php $PHP_SELF ?>">
<table border="2" cellspacing="2">
<tr><td>Insert you search string here</td>
<td>Search type</td></tr>
<tr>
<td><input type="text" name="searchstring" size="28"></td>
<td><select size="1" name="searchtype">
<option selected value="firstname">First Name</option>
<option value="lastname">Last Name</option>
<option value="nick">Nick Name</option>
<option value="email">Email</option>
</select></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<?php
}
?>
</HTML>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-01-05, 08:32 AM
Vulture Vulture is offline
Newbie Coder
 
Join Date: Dec 2004
Location: Scotland, UK
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
I think its just a matter of sorting out the tables, try this:
PHP Code:

<html>

<?php
if ($searchstring)
{
$sql="SELECT * FROM personnel WHERE $searchtype LIKE '%$searchstring%' ORDER BY firstname";
$db mysql_connect("localhost""root""");
mysql_select_db("learndb",$db);
$result mysql_query($sql,$db);
echo 
"<table border=\"2\">";
echo 
"<tr><td><b>Full Name</b></td><td><b>Nick Name</b></td><td><b>Options</b></td></tr>";
while (
$myrow mysql_fetch_array($result))
{
echo 
"<tr><td>".$myrow["firstname"]." ".$myrow["lastname"]."</td><td>".$myrow["nick"]."</td><td><a href=\"view.php?id=".$myrow["id"]."\">View</a></td></tr>";
}
echo 
"</table>";
}
else
{
?>
<form method="POST" action="<?php $PHP_SELF ?>">
<table border="2" cellspacing="2">
<tr><td>Insert you search string here</td>
<td>Search type</td></tr>
<tr>
<td><input type="text" name="searchstring" size="28"></td>
<td><select size="1" name="searchtype">
<option selected value="firstname">First Name</option>
<option value="lastname">Last Name</option>
<option value="nick">Nick Name</option>
<option value="email">Email</option>
</select></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<?php
}
?>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-01-05, 01:15 PM
raggster raggster is offline
New Member
 
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for your reply!

That doesn't seem to be working for me either though. It displays all the results like this:

<tr>
<td>
result1
</td>
</tr>
<tr>
<td>
result2
</td>
</tr>
<tr>
<td>
result3
</td>
</tr>

I'm trying to get them to be horizontal like this:

<tr>
<td>
result1
</td>
<td>
result2
</td>
<td>
result3
</td>
</tr>

I found out that I need to use the modulus operator. I just can't figure out how to integrate that with this script!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-01-05, 01:57 PM
DetroitGuy DetroitGuy is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Just move the first <tr> in the while loop up to the line before it. Then when it finishes, echo "<tr>.........";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SEO Expert Available nakulgoyal Job Offers & Assistance 2 08-14-04 01:38 PM
Simple search script niceguyonline Script Requests 3 03-08-04 12:09 AM
results page to display prev/next php-learner PHP 11 01-12-04 10:40 AM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 07:33 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.