m1a2x3x7
06-18-2007, 08:37 PM
A little background. I've created a site when I can post blogs. Really simple, really generic. I have an admin login page where I can type in the title and the blog.
All this works great I also created a page that displays the blogs. All that works great.
I'm trying to create a search page. I can type a keyword in and it brings up the search page and it tells what I'm searching for. I just can't get the database to retrieve any of the blogs.
I’m doing a like statement in my query but I’m having problems figuring out the syntax for using a PHP variable in the sql statement. Any help would be great.
<?php
ob_start();
require_once("connections/connect.php");
session_start();
$query = sprintf("SELECT title FROM blogs WHERE (title) LIKE values ('$keyword') DESC");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
$numResults = mysql_num_rows($result);
$keyword = $_GET['Keyword'];
?>
<!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>Schultz | Studio - Blog</title>
<link href="blogcss.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
background-color: #CCCCCC;
}
.style2 {color: #98D05B}
-->
</style></head>
<body>
<div id="wrapper">
<div id="banner">
<div id="loginlink"><a href="login.php"><img src="images/login.gif" width="55" height="10" border="0" /></a></div>
</div>
<div id="search">
<table width="796" height="30" border="0">
<tr>
<td width="454" class="font-date"><?php
echo date('F j, Y');
?></td>
<td align="right" valign="top"><img src="images/search.gif" width="72" height="20" /></td>
<td align="right" valign="top"><form id="form1" name="form1" method="get" action="search.php">
<input name="Keyword" type="text" id="Keyword"/>
<input name="Search" type="submit" id="Search" value="Find"/>
</form></td>
</tr>
</table>
</div>
<div id="body">
<p class="font-date">Your search for <b><?php echo $keyword; ?></b> has turned up <?php if (empty$numResults); {
echo $numResults; ?> results.</p>
<p class="font-date"> <table width="526" border="0">
<?php do { ?>
<tr>
<td width="385" class="blog_title"><?php echo $row['title'];?></td>
</tr>
<tr>
<td class="date"><?php echo $row['date'];?></td>
</tr>
<tr>
<td class="blog"><?php echo nl2br($row['blog']);?></td>
</tr>
<tr>
<td class="blog">.................................................. .................................................. ....</td>
</tr>
<?php } while ($row = mysql_fetch_array($result));
?>
</table> </p>
</div>
<div id="footer">
<div id="footerinfo">Copyright © 2007 Schultz | Studio. All Rights Reserved.</div>
</div>
</div>
</body>
</html>
ps I've searched, and found may different ways how mysql would read a PHP variable but none of them have worked right so IDK
Thanks
All this works great I also created a page that displays the blogs. All that works great.
I'm trying to create a search page. I can type a keyword in and it brings up the search page and it tells what I'm searching for. I just can't get the database to retrieve any of the blogs.
I’m doing a like statement in my query but I’m having problems figuring out the syntax for using a PHP variable in the sql statement. Any help would be great.
<?php
ob_start();
require_once("connections/connect.php");
session_start();
$query = sprintf("SELECT title FROM blogs WHERE (title) LIKE values ('$keyword') DESC");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
$numResults = mysql_num_rows($result);
$keyword = $_GET['Keyword'];
?>
<!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>Schultz | Studio - Blog</title>
<link href="blogcss.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
background-color: #CCCCCC;
}
.style2 {color: #98D05B}
-->
</style></head>
<body>
<div id="wrapper">
<div id="banner">
<div id="loginlink"><a href="login.php"><img src="images/login.gif" width="55" height="10" border="0" /></a></div>
</div>
<div id="search">
<table width="796" height="30" border="0">
<tr>
<td width="454" class="font-date"><?php
echo date('F j, Y');
?></td>
<td align="right" valign="top"><img src="images/search.gif" width="72" height="20" /></td>
<td align="right" valign="top"><form id="form1" name="form1" method="get" action="search.php">
<input name="Keyword" type="text" id="Keyword"/>
<input name="Search" type="submit" id="Search" value="Find"/>
</form></td>
</tr>
</table>
</div>
<div id="body">
<p class="font-date">Your search for <b><?php echo $keyword; ?></b> has turned up <?php if (empty$numResults); {
echo $numResults; ?> results.</p>
<p class="font-date"> <table width="526" border="0">
<?php do { ?>
<tr>
<td width="385" class="blog_title"><?php echo $row['title'];?></td>
</tr>
<tr>
<td class="date"><?php echo $row['date'];?></td>
</tr>
<tr>
<td class="blog"><?php echo nl2br($row['blog']);?></td>
</tr>
<tr>
<td class="blog">.................................................. .................................................. ....</td>
</tr>
<?php } while ($row = mysql_fetch_array($result));
?>
</table> </p>
</div>
<div id="footer">
<div id="footerinfo">Copyright © 2007 Schultz | Studio. All Rights Reserved.</div>
</div>
</div>
</body>
</html>
ps I've searched, and found may different ways how mysql would read a PHP variable but none of them have worked right so IDK
Thanks