homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Calling rows based on keyword

5+ Year Member

Msg#: 4186871 posted 1:24 am on Aug 14, 2010 (gmt 0)

I would like to print part of a row. The row is selected by a search with a keyword.

table name: items

item_no name totA totB totC totD totE
01001 house 10 20 30 40 50
01002 food 15 25 35 45 55
01003 work 115 125 135 145 155

I want to print only the columns 'name', 'totA', 'totB', 'totC' and 'totE'

So far, I use this as the search form
<form action="/vitamine/wp-content/themes/twentyten/insert.php" method="post">
Value1: <input type="text" name="value1"><br>
<input type="Submit">

And this to call the data

@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM items WHERE name LIKE '%".mysql_real_escape_string($_POST['value1'])."%'";


<table border="1" align="center" cellpadding="2" cellspacing="2">
<th><font face="Arial, Helvetica, sans-serif">Value1</font></th>

while ($i < $num) {



<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>




But this gives me a list of all search results items and no rows. How can I print the whole row minus the columns I don't want?

Thanks again!



WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4186871 posted 3:23 am on Aug 14, 2010 (gmt 0)

By selecting the columns you want, instead of * which selects all columns. also the "counter method" (I call it) is not needed to step through recordsets unless you specifically need a count of rows. Like so . . .

$results = null; // squelches concatenation errors and makes for a nice if at the end
$query="SELECT name, totA, totB, totC, totD, totE FROM items WHERE name LIKE '%".mysql_real_escape_string($_POST['value1'])."%'";

$result=mysql_query($query) or die("could not execute query: " . mysql_error());
while ($row=mysql_fetch_array($result)) {
$results .= '<tr>
<td>' . $row['name'] . '</td>
<td>' . $row['totA'] . '</td>
<td>' . $row['totB'] . '</td>
<td>' . $row['totC'] . '</td>
<td>' . $row['totE'] . '</td>
if ($results) {
echo "<table border=\"1\" align=\"center\" cellpadding=\"2\" cellspacing=\"2\">
else { echo "<p>No results were found with that search.</p>"; }

May contain typos, but that should give you an idea.


5+ Year Member

Msg#: 4186871 posted 5:42 am on Aug 14, 2010 (gmt 0)

Looks great (and simple)

I got the idea and I want to try it out now, but my wife won't let me :)


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved