Closed Thread Icon

Topic awaiting preservation: need help with PHP script Pages that link to <a href="https://ozoneasylum.com/backlink?for=12533" title="Pages that link to Topic awaiting preservation: need help with PHP script" rel="nofollow" >Topic awaiting preservation: need help with PHP script\

 
Author Thread
CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 11-27-2002 23:14

Hello all

Its been a few months since I first asked you guys where I could get assistance writing a PHP script for my client (search for dealers by state and zip on web site). DevShed was great and helped me get started, but still could not figure out why this script skips through the code and displays the "We apologize, at this present time we do not have a dealer in your area but are expanding very quickly. Please . . ." that appears in the else {} at the very end.

I looked through php.net and mysql.com and double-checked the functions I used and could not find the problem. My intention is not for the Asylumites to hold my hand . . but rather point me in the correct direction. I have no idea why this is not working. Maybe I need to incorporate or die(); so at least I know either I have an error with mysql_connect or mysql_select_db or mysql_query functions. Or maybe it has something to do with my database? I built it with phpmyadmin.

What do you think?

Thanks.
CRO8

---------------------------------------------------------------------------------------------------------------

<!-- begin form--> <?php


mysql_connect ("66.84.26.254","planters","xxxxxx");


mysql_select_db ("/usr/local/apache/htdocs/Dealers");


$result = mysql_query ("SELECT Company_Name,Address,City,State,Zip,Contact_Name,Phone,Fax,email,Web_Site,Map
FROM Contact_Info
WHERE state LIKE '".$State."'");


$count = mysql_query ("SELECT COUNT(*)
FROM Contact_Info
WHERE state LIKE '".$State."'");


$countresult = mysql_fetch_array($count);


print "<font color=red><strong>".$countresult[0]."</strong></font> results found:<br><br>";


if ($row = mysql_fetch_array($result)) {

do {
print "<hr noshade width=300 align=left>";
print "<strong>".$row["Company_Name"]."</strong><br>\r";
print $row["Address"]."<br>\r";
print $row["City"].", ".$row["State"]." ".$row["Zip"]."<br>\r";
print $row["Contact_Name"]."<br>\r";
print $row["Phone"]."<br>\r";
print $row["Fax"]."<br>\r";
print $row["Email"]."<br>\r";
print $row["Web_Site"]."<br>\r";
print $row["Map"]."<br>";
} while($row = mysql_fetch_array($result));

} else {print "We apologize, at this present time we do not have a dealer in your area but are expanding very quickly. Please check back in a few weeks or call 914-939-8500 to speak to a representative at Madison Fielding Inc, the manufacturer of PlanterSpeakers.";}

echo "<hr noshade width=300 align=left>";
?> <!-- end form-->

---------------------------------------------------------------------------------------------------------------

[This message has been edited by CRO8 (edited 11-27-2002).]

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 11-27-2002 23:25

CRO8: I think you need to add some od dies in there to help with the troubleshooting.

I also prefer getting my results this way:

code:
$result_row_count = mysql_num_rows ($result);

if ($result_row_count < 1) {
DO SOMETHING
}
else {
while ($row = mysql_fetch_array($result)) {
DO SOMETHING ELSE
}
}




___________________
Emps

FAQs: Emperor

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 11-27-2002 23:44

I think you may have a problem with this line:

mysql_select_db ("/usr/local/apache/htdocs/Dealers");

That function just wants the name of the database that you want to use, not a path to a directory.

You can also get rid of your second database call for $count as it;s something you can do in your first query. Just add COUNT(*) as count to your first query and you will have that value with the field name of (you'll never believe this) count.


-Butcher-

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 11-29-2002 19:22

Thanks- I will get back to you later . . .

CRO8

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-29-2002 23:16

I'm not sure what's in $state,
but the string for a like query must look like:
'%searchterm%' (the % are wildcards and mean that anything could stand to the left or right of it).
So, if the % are not in $state, adjust your query to be like
[...] "%'. $state . %" [...]

so long,

Tyberius Prime

« BackwardsOnwards »

Show Forum Drop Down Menu