Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Help needed, please read!

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Help needed, please read!

Postby amerrigan » Wed Apr 30, 2003 7:16 am

Hi,

Basically I want to count the number database entries that have a particular word in them.

e.g. I have a database table "food". I want to be able to count the number of times (or number of entries) containing a word like "apple" (static).

HELP!!!

Tony
amerrigan
New php-forum User
New php-forum User
 
Posts: 6
Joined: Thu Apr 10, 2003 8:25 am

Postby bezmond » Wed Apr 30, 2003 8:09 am

Code: Select all
$query = "SELECT * FROM `tablename` Whare `columname` LIKE '%$some_patern%'";
$result = mysql_query($query) or die(mysql_error());
$number = mysql_num_rows($result);
echo $number;


Try that

Andrew
User avatar
bezmond
Moderator
Moderator
 
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK

Postby amerrigan » Wed Apr 30, 2003 10:19 am

Ok thanks. That worked but I need to now advance my coding and have the word dynamically placed from a second database and then the table repeated. I have included my current coding and would appreciate tips/code samples.

By the way I'm using a supe'd version of Dreamweaver MX.

Code: Select all
<?php require_once('Connections/one.php'); ?>
<?php
mysql_select_db($database_, $one);
$query_featured = "SELECT * FROM featured ORDER BY program_name ASC";
$featured = mysql_query($query_featured, $one) or die(mysql_error());
$row_featured = mysql_fetch_assoc($featured);
$totalRows_featured = mysql_num_rows($featured);

mysql_select_db($database_one, $one);
$query_tickets = "SELECT * FROM tickets";
$tickets = mysql_query($query_tickets, $one) or die(mysql_error());
$row_tickets = mysql_fetch_assoc($tickets);
$totalRows_tickets = mysql_num_rows($tickets);
?>
<html>
<head>
<title>One</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/default.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>&</td>
  </tr>
  <tr>
    <td>&</td>
  </tr>
  <tr>
    <td></td>
  </tr>
  <tr>
    <td>&</td>
  </tr>
  <tr>
    <td>&</td>
  </tr>
  <tr>
    <td>
<table border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#000000" background="gif/binary.gif">
        <tr bgcolor="#000000">
          <td width="150"><strong><font color="#FFFFFF" size="2">Name:</font></strong></td>
          <td width="100"><strong><font color="#FFFFFF" size="2">No times in db:</font></strong></td>
          <td width="80">&</td>
        </tr>
        <?php do { ?>
        <tr>
          <td width="150"><font size="2"><strong><?php echo $row_featured['program_name']; ?></strong></font></td>
          <td width="100"><strong><font size="2">$<?php $query = "SELECT * FROM `tickets` Where `th_program` LIKE $row_featured['program_name']";
$result = mysql_query($query) or die(mysql_error());
$number = mysql_num_rows($result);
echo $number; ?></font></strong></td>
          <td width="80">
            <div align="center"><strong><font size="2"><a href="games_details.php?id=<?php echo $row_featured['id']; ?>">Details</a></font></strong></div></td>
        </tr>
        <?php } while ($row_featured = mysql_fetch_assoc($featured)); ?>
      </table></td>
  </tr>
  <tr>
    <td>&</td>
  </tr>
  <tr>
    <td><div align="center"> </div></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($featured);

mysql_free_result($tickets);
?>

amerrigan
New php-forum User
New php-forum User
 
Posts: 6
Joined: Thu Apr 10, 2003 8:25 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron