|
-
Jul 3rd, 2008, 05:04 PM
#1
Thread Starter
Hyperactive Member
Query Result Issue
I'm having difficulties in this. Here's a shortened version of my code:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
$con = mysql_connect("","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("kjv", $con);
$sql = "SELECT count(*) AS totalrows FROM bible WHERE 1=1 AND";
$sql .= " CASE WHEN text_data LIKE '%angel%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%appeared%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%flame%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%midst%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%looked%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%behold%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%burned%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%consumed%' THEN 1 ELSE 0 END > 3";
//$sql .= " LIMIT 0, 10";
$result = mysql_query($sql) OR exit( 'Error: ' . mysql_error());
function highlight ( $str, $words )
{
if ( is_array( $words ) ) {
rsort($words);
$words = array_map( 'preg_quote', $words );
$words = join( $words, '|' );
} else {
$words = preg_quote( (string)$words );
}
//$re = '<span style="color: red; font-weight:bold;">$1</span>';
$color[0] = "red";
$color[1] = "blue";
//for($c=0; $c < 8; $c++){
//echo $color[$c]."<br />";
$re = '<span style="color: '.$color[0].'; font-weight:bold;">$1</span>';
//}
return preg_replace( '/\b(' . $words . ')\b/i', $re, $str );
}
echo $row['totalrows']."<br />";
$recCount = 1;
while($row = mysql_fetch_array($result)){
echo "<span id='regular[]' style='padding: 5px; background-color: #D2C5A0; display: block; border: 1px solid #7C7C7C; color: black;'>";
echo "<span style='font-weight: bold; color: black; background-color: #B4B3A9; display: block; border: 1px solid #7C7C7C;'>"."<span style='font-weight: normal;'> ".$recCount."</span> ".$row["book_title"]." ".$row["chapter"].":".$row["verse"]." ";
echo "</span>\n";
$str = $row['text_data'];
//var_dump( highlight( $str, $newSearchTheseArr));
echo highlight( $str, $newSearchTheseArr);
echo "</span><br />\n";
$recCount++;
}
mysql_close($con);
?>
</body>
</html>
It's returning "1:" instead of the total count of the query.
-
Jul 4th, 2008, 04:19 AM
#2
Re: count() vs. mysql_num_rows()
Your query is WAY too complicated. Consider shortening it.
-
Jul 4th, 2008, 11:24 AM
#3
Re: Query Result Issue
Posts split to separate new thread
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|