Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Calling rows based on keyword

1:24 am on Aug 14, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 26, 2010
posts: 52
votes: 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!
3:23 am on Aug 14, 2010 (gmt 0)

Senior Member

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

joined:Nov 28, 2004
votes: 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:42 am on Aug 14, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 26, 2010
votes: 0

Looks great (and simple)

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