Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SEARCH NOT RETURNING ANYTHING

Status
Not open for further replies.

dadms

Technical User
Joined
Mar 8, 2003
Messages
67
Location
US
I am querying twice into the same database. The first query returns results fine. I am using the ID on the first query ($variable1) to make a hyperlink to get more information and display the selected ID in a new page. It does not work...please help.

PHP first query ->works
<HTML>
<HEAD>
<meta HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=windows-1252&quot;>
<meta http-equiv=&quot;Content-Language&quot; content=&quot;en-us&quot;>
<TITLE>INPUT FORM</TITLE>
</HEAD>
<BODY>
<center>
<table border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; bordercolor=&quot;#000000&quot;>
<tr>
<td width=&quot;60&quot;><b>ID</b></td>
<td width=&quot;60&quot;><b>AUTHOR</b></td>
<td width=&quot;100&quot;><b>DATE</b></td>
<td width=&quot;70&quot;><b>CATEGORY</b></td>
<td width=&quot;150&quot;><b>TITLE</b></td>
<!---------------------------<td width=&quot;150&quot;><b>INFORMATION</b></td>------------>
</tr>
<tr>
<td>

<?php

$dbh=mysql_connect (&quot;localhost&quot;, &quot;xxxx&quot;, &quot;xxxxx&quot;) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db (&quot;db_store&quot;);
?>

<?php
//error message (not found message)begins
$XX = &quot;No Record Found, to search again please close this window&quot;;
//query details table begins
$query = mysql_query(&quot;SELECT * FROM sbmtdfrms WHERE $metode LIKE '%$search%' LIMIT 0, 50&quot;);
while ($row = @mysql_fetch_array($query))
{
$variable1=$row[&quot;id&quot;];
$variable2=$row[&quot;name&quot;];
$variable3=$row[&quot;date&quot;];
$variable4=$row[&quot;category&quot;];
$variable5=$row[&quot;title&quot;];
$variable6=$row[&quot;information&quot;];
//table layout for results

print (&quot;<tr>&quot;);
print (&quot;<td valign='top'><a href=search.php?id=$variable1>$variable1</a></td>&quot;);
print (&quot;<td valign='top'>$variable2</td>&quot;);
print (&quot;<td valign='top'><pre>$variable3<pre></td>&quot;);
print (&quot;<td valign='top'>$variable4</td>&quot;);
print (&quot;<td valign='top'>$variable5</td>&quot;);
//print (&quot;<td valign='top'><pre>$variable5</pre></td>&quot;);

print (&quot;</tr>&quot;);
}
//below this is the function for no record!!
if (!$variable1)
{
print (&quot;$XX&quot;);
}
//end
?>
</table>
</center>
</body>


SECOND QUERY RETURNS NO RECORD FOUND->QUERY IS RAN BY SELECTING AN ID NUMBER FROM FIRST QUERY
<?php

$dbh=mysql_connect (&quot;localhost&quot;, &quot;XXXX&quot;, &quot;XXXXXX&quot;) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db (&quot;db_store&quot;);
?>

<?php
//error message (not found message)begins
$XX = &quot;No Record Found, to search again please close this window&quot;;

//query details table begins
$query = mysql_query(&quot;SELECT * FROM sbmtdfrms WHERE 'id' = '%$variable1%'&quot;);
while ($row = @mysql_fetch_array($query))

{
$variable1=$row[&quot;id&quot;];
$variable2=$row[&quot;name&quot;];
$variable3=$row[&quot;date&quot;];
$variable4=$row[&quot;category&quot;];
$variable5=$row[&quot;description&quot;];
$variable6=$row[&quot;information&quot;];
//table layout for results

}
//below this is the function for no record!!
if (!$variable2)
{
print (&quot;$XX&quot;);
}
//end
?>
<HTML>
<HEAD>
<TITLE>FORM RESPONSE</TITLE>
</HEAD>
<BODY>
<table width=&quot;100%&quot; border=&quot;0&quot; align=&quot;center&quot; style=&quot;border-left-width: 0; border-right-width: 0; border-top-width: 0&quot;>
<tr>
<td colspan=&quot;5&quot; style=&quot;border-bottom-style: solid; border-bottom-width: 1&quot; width=&quot;941&quot;>
<p align=&quot;center&quot;>RECORD SELECTED</td>
</tr>
<tr> <td><b>AUTHOR:</b></td>
<?php print (&quot;<td>$variable2</td>&quot;); ?>
</tr>
<tr>
</tr>
<tr> <td><b>DATE:</b></td>
<?php print (&quot;<td>$variable3</td>&quot;); ?>
</tr>
<tr>
</tr>
<tr> <td><b>CATEGORY:</b></td>
<?php print (&quot;<td>$variable4</td>&quot;); ?>
</tr>
<tr>
</tr>
<tr> <td VALIGN=&quot;TOP&quot;><b>TITLE:</b></td>
<?php print (&quot;<td>$variable5</td>&quot;); ?>
</tr>
<tr>
</tr>
<tr> <td VALIGN=&quot;TOP&quot;><b>INFORMATION:</b></td>
<?php print (&quot;<td><pre>$variable6</pre></td>&quot;); ?>
<tr>
</tr>
</table>
<table>
<table width=&quot;100%&quot; border=&quot;0&quot; align=&quot;center&quot; style=&quot;border-left-width: 0; border-right-width: 0; border-top-width: 0&quot;>
<hr></hr>
</table>
</body>
 
Code:
$query = mysql_query(&quot;SELECT * FROM sbmtdfrms WHERE 'id' = '%$id%'&quot;);


you pass id as variable name. not variable1

;)
 
I have made the following change but get the same results.

//query details table begins
$query = mysql_query(&quot;SELECT * FROM sbmtdfrms WHERE 'id' = '%$id%'&quot;);
while ($row = @mysql_fetch_array($query))

url- No Record Found, to search again please close this window
 
if anybody would like to try it:
got to and enter MATT in the text box
when you get the results click on the id number.

Also MySQL fields are:
id |author |date |category |title |description

ID IS AN INT
 
CHANGE

$query = mysql_query(&quot;SELECT * FROM sbmtdfrms WHERE 'id' = '%$variable1%'&quot;);

TO

$query = mysql_query(&quot;SELECT * FROM sbmtdfrms WHERE 'id' = '$variable1'&quot;);

I believe that the wildcard character '%' is for like clauses only, not =.

See if that worx
 
ah you just said it. you can only use wildcards with the like statement. sorry missed that the first time ;)
 
I have tried the following:

//query details table begins
$query = mysql_query(&quot;SELECT * FROM sbmtdfrms WHERE 'id' = '$variable1'&quot;);
while ($row = @mysql_fetch_array($query))

//query details table begins
$query = mysql_query(&quot;SELECT * FROM sbmtdfrms WHERE 'id' = '$id'&quot;);
while ($row = @mysql_fetch_array($query))
 
don't put single quotes around id in the where statement

//query details table begins
Code:
$query = mysql_query(&quot;SELECT * FROM sbmtdfrms WHERE id= '$id'&quot;);
while ($row = @mysql_fetch_array($query))
 
thanx that did it. I thought I tried that before but must not of. I really appreciate everybodies help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top