bo select a

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Deddog
Forum Commoner
Posts: 55
Joined: Thu Sep 26, 2002 6:05 am
Location: Brighton

bo select a

Post by Deddog »

Help! Below code should select at least 1200 rows. But my echo statement display the figure 0. Where am i going wrong? Using the latest version of PHP and MYSQL.

cheers,

lee.

Code: Select all

<?php 
Connectlistmail();
$sql = "SELECT user1 FROM lm_users WHERE user2 IN ('BB%', 'BL%', 'CA%', 'CH%', 'CW%', 'FY%', 'L1%', 'L2%', 'L3%', 'L4%', 'L5%', 'L6%', 'L7%', 'L8%', 'L9%', 'LA%', 'LL%', 'M1%', 'M2%', 'M3%', 'M4%', 'M5%', 'M6%', 'M7%', 'M8%', 'M9%', 'OL%', 'PR%', 'WA%', 'WN%') ";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
$total = mysql_num_rows($result);
echo $total;
?>

// OR 

<?php 
Connectlistmail();
$sql = "SELECT user1 FROM lm_users WHERE user2 IN ('BB', 'BL', 'CA', 'CH', 'CW', 'FY', 'L1', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7', 'L8', 'L9', 'LA', 'LL', 'M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'M8', 'M9', 'OL', 'PR', 'WA', 'WN') ";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
$total = mysql_num_rows($result);
echo $total;
?>
[Edit: Added PHP tags for eyecandy. --JAM]
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

I'm not entirely sure, but;

Code: Select all

$sql = "SELECT sum(user2) IN ('BB', 'BL', 'CA', 'CH', 'CW', 'FY', 'L1', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7', 'L8', 'L9', 'LA', 'LL', 'M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'M8', 'M9', 'OL', 'PR', 'WA', 'WN') FROM lm_users";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>'); 
echo mysql_result($result,0);
In returns 0 or 1. So sum() would sum up the results.
Post Reply