displaying multiple rows from database

Greetings,

I have a search feature that search key words within my database and returns records. My issue is it will only return one record. I have searched specifically for each record and it will return each but not when I keyword both.

I believe my multiple keyword search code is right, but I think my code for displaying all rows has an issue.

Any help to point me in the right direction is appreciated.

*fyi, the data that does display is correct.

<?php..... $count=$dbo->prepare($query); $count->execute(); $no=$count->rowCount(); if($no > 0 ) {echo "No of records = ".$no.""; ?> <?php foreach ($dbo->query($query) as $row);?>
       <tr bgcolor="#FFFFFF">
		  <td width="26%"><span class="result"><img src="Images/<?php echo $row[Businessr]; ?>"></span></td>
            <td width="16%"><span class="result"><a href="<?php echo $row[name]; ?>">View Video</a></span></td>
            <td width="58%"><span class="result"><?php echo $row[sub]; ?></span></td>
		</tr> </table>
        <?php
			}
		}
		 else {

echo " No records found ";
}

For one, this is incorrect

foreach ($dbo->query($query) as $row);

You end the statement on the first round.

I tried removing ; however unable to make it work.

I am able to display it correctly with the following, however I am having trouble setting table colors.

echo “

”;
foreach ($dbo->query($query) as $row){
echo “”;
}
echo “
gender Name sub
$row[gender] $row[name] $row[sub]
”;
}else {
echo " No records found ";
}

Really depends on where you want to set the colors…

You can do it, many different ways, you can set it on an individual cell:

[php]


[/php]

Or an individual Row:

[php]

[/php]

You can do it with CSS or inline like above… So many options.

The way you were doing it below, is no longer supported in HTML5

[php]

[/php]

Easy way,
[php]
$counter = 1;
foreach ($dbo->query($query) as $row){
$class = $counter % 2 == 0 ? “even” : “odd”;

echo “

$row[gender] $row[name] $row ”;

$counter++;
}[/php]

Now designate the style for classes even and odd.

Sponsor our Newsletter | Privacy Policy | Terms of Service