Multiple listings
Posted: Thu Sep 23, 2004 11:08 pm
If I'm getting multiple (same) listings with a PHP search/results, is the bug in my MySQL/Recordset, or in the PHP?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
<?php require_once('../../Connections/hungryusaconnection.php'); ?>
<?php
$colname_rsmenu = "1";
if (isset($HTTP_GET_VARS['namefield'])) {
$colname_rsmenu = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['namefield'] : addslashes($HTTP_GET_VARS['namefield']);
}
mysql_select_db($database_hungryusaconnection, $hungryusaconnection);
$query_rsmenu = sprintf("SELECT menus.id, menus.item, menus.restaurant, menus.description, restaurants.website, restaurants.webbutton FROM menus, restaurants WHERE item LIKE '%%%s%%' ORDER BY item ASC", $colname_rsmenu);
$rsmenu = mysql_query($query_rsmenu, $hungryusaconnection) or die(mysql_error());
$row_rsmenu = mysql_fetch_assoc($rsmenu);
$totalRows_rsmenu = mysql_num_rows($rsmenu);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../css/hungrycss01.css" rel="stylesheet" type="text/css">
<link href="../css/hungrycss02.css" rel="stylesheet" type="text/css">
<link href="../css/links01.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php do { ?>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"><?php echo $row_rsmenu['id']; ?></td>
<td width="300"><span class="bigbrown"><?php echo $row_rsmenu['item']; ?></span><br>
<span class="medblack"><?php echo $row_rsmenu['restaurant']; ?></span><br>
<span class="smallblacknorm"><?php echo $row_rsmenu['description']; ?></span></td>
<td width="80"><a href="<?php echo $row_rsmenu['website']; ?>" target="_blank"><?php echo $row_rsmenu['webbutton']; ?></a></td>
</tr>
</table>
<?php } while ($row_rsmenu = mysql_fetch_assoc($rsmenu)); ?>
<?php
mysql_free_result($rsmenu);
?>
</body>
</html>
?>Code: Select all
select a.userId, b.name FROM users a, details b WHERE a.userId=b.userIdCode: Select all
<?php
<?php require_once('../../Connections/hungryusaconnection.php'); ?>
<?php
$colname_rsmenu = "1";
if (isset($HTTP_GET_VARS['namefield'])) {
$colname_rsmenu = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['namefield'] : addslashes($HTTP_GET_VARS['namefield']);
}
mysql_select_db($database_hungryusaconnection, $hungryusaconnection);
$query_rsmenu = sprintf("SELECT menus.id, menus.item, menus.restaurant, menus.description, menus.price_lg, restaurants.restaurant, restaurants.website, restaurants.webbutton FROM menus left join restaurants on restaurants.restaurant = menus.restaurant WHERE menus.item LIKE '%%%s%%' ORDER BY item ASC", $colname_rsmenu);
$rsmenu = mysql_query($query_rsmenu, $hungryusaconnection) or die(mysql_error());
$row_rsmenu = mysql_fetch_assoc($rsmenu);
$totalRows_rsmenu = mysql_num_rows($rsmenu);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../css/hungrycss01.css" rel="stylesheet" type="text/css">
<link href="../css/hungrycss02.css" rel="stylesheet" type="text/css">
<link href="../css/links01.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php do { ?>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20" class="smallblacknorm"><?php echo $row_rsmenu['id']; ?></td>
<td width="300"><span class="bigbrown"><?php echo $row_rsmenu['item']; ?></span><br>
<span class="medblack"><?php echo $row_rsmenu['restaurant']; ?></span><br>
<span class="smallblacknorm"><?php echo $row_rsmenu['description']; ?></span></td>
<td width="80"><a href="<?php echo $row_rsmenu['website']; ?>"><?php echo $row_rsmenu['webbutton']; ?></a></td>
</tr>
</table>
<?php } while ($row_rsmenu = mysql_fetch_assoc($rsmenu)); ?>
<?php
mysql_free_result($rsmenu);
?>
</body>
</html>
?>Code: Select all
SELECT menus.id, menus.item, menus.restaurant, menus.description, menus.price_lg, restaurants.rest_name, restaurants.website, restaurants.webbutton FROM menus left join restaurants on restaurants.rest_name = menus.restaurant WHERE menus.item LIKE '%%%s%%' ORDER BY item ASC", $colname_rsmenu);Code: Select all
tag.[/color]Code: Select all
SELECT menus.id, menus.item, menus.restaurant,
menus.description, menus.price_lg, restaurants.rest_name,
restaurants.website, restaurants.webbutton FROM menus inner join
restaurants on restaurants.rest_name = menus.restaurant WHERE
(menus.restaurant LIKE '%%%s%%' OR menus.description LIKE
'%%%s%%' OR menus.item LIKE '%%%s%%' OR menus.sub_item LIKE
'%%%s%%' OR menus.sub_1 LIKE '%%%s%%') ORDER BY RAND()