View Full Version : Alphabet Search

07-16-2007, 09:13 PM
Hey All,

I have a bit of a conundrum here.... Trying to set up an alphabet type search but stumped by the SQL query.... Here is what i have so far...

Right now i get this error....

Warning: sprintf() [function.sprintf]: Too few arguments in C:\xxxxxxxx\WAMP\IDAS_CSS\affiliates_alphabet.php on line 4

<?php require_once("include/admin_inc.php"); /////DB Connect

////////////////////////////Query DB
$query = sprintf("SELECT * FROM affiliates WHERE company LIKE '%?letter%' ");
$result = @mysql_query($query);
$row = @mysql_fetch_array($results);

<!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">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>IDAS - CSS </title>
<link href="css/idas.css" rel="stylesheet" type="text/css" />

<div id="wrapper">
<div id="header">
<div align="right"><img src="http://www.idas.ca/images/banners/rotate.php"></div>
<div id="navigation"><?php include("nav_inc.php"); ?></div>
<div id="container">
<div id="content">
<p class="heading">Affiliates</p>
<h3>Affiliates Alphabetical Search</h3>

<form action="affiliates_alphabet.php" method="post" name="affiliates" onclick="submit">
<a href="affiliates_alphabet.php?letter=A">A</a> |
<a href="affiliates_alphabet.php?letter=B">B</a> |
<a href="affiliates_alphabet.php?letter=C">C</a> |
<a href="affiliates_alphabet.php?letter=D">D</a> |
<a href="affiliates_alphabet.php?letter=E">E</a> |
<a href="affiliates_alphabet.php?letter=F">F</a> |
<a href="affiliates_alphabet.php?letter=G">G</a> |
<a href="affiliates_alphabet.php?letter=H">H</a> |
<a href="affiliates_alphabet.php?letter=I">I</a> |
<a href="affiliates_alphabet.php?letter=J">J</a> |
<a href="affiliates_alphabet.php?letter=K">K</a> |
<a href="affiliates_alphabet.php?letter=L">L</a> |
<a href="affiliates_alphabet.php?letter=M">M</a> |
<a href="affiliates_alphabet.php?letter=N">N</a> |
<a href="affiliates_alphabet.php?letter=O">O</a> |
<a href="affiliates_alphabet.php?letter=P">P</a> |
<a href="affiliates_alphabet.php?letter=Q">Q</a> |
<a href="affiliates_alphabet.php?letter=R">R</a> |
<a href="affiliates_alphabet.php?letter=S">S</a> |
<a href="affiliates_alphabet.php?letter=T">T</a> |
<a href="affiliates_alphabet.php?letter=U">U</a> |
<a href="affiliates_alphabet.php?letter=V">V</a> |
<a href="affiliates_alphabet.php?letter=W">W</a> |
<a href="affiliates_alphabet.php?letter=X">X</a> |
<a href="affiliates_alphabet.php?letter=Y">Y</a> |
<a href="affiliates_alphabet.php?letter=Z">Z</a> |
<a href="full.php">View All</a>

<br />

<div class="heading style1"></div>
<div class="textpad">Company Name: <?php echo $row['company']; ?></div>
<div class="textpad">Contact: </div>
<div class="textpad">Location: , , </div>
<div class="textpad">PH: </div>
<div class="textpad">FAX: </div>
<div class="textpad">Cell: </div>
<div class="textpad">Email Address: <a></a> </div>
<div class="textpad">WebSite:<a target="_blank"></a></div>
<div class="textpad"><br />
<br />
<br />

<div id="side-b">
<div id="footer"></div>
<?php include("footer_inc.php"); ?>

07-16-2007, 09:47 PM
an sprint_f writes a formatted string parsing all the variables as it goes

PHP doesnt care what it passes to the database as long as its a string. If the string is shite the database will error and let you know via PHP error handling.

look at the example...
sprint_f is a function which carrys a number of arguments. It works like this..

$query= sprintf("SELECT * FROM affiliates WHERE company LIKE '%s' and field = '%s' and field2='%s'", $var, $var2, $var3);
$result = @mysql_query($query);

it reads in the string until it comes across the first s% then it looks for the first variable outside the string argument and in this case equates to $var. It then progresses through the string parsing every %s it finds with a $var. If you have 3 %s and only 2 $vars it will throw an error...

Too few arguments in .....etc etc