damion Posted October 6, 2009 Share Posted October 6, 2009 Hi All, When I run this script it works pretty well but there are 2 things that bug me about it. First off, when the results are displayed after selecting a state from the menu the page focus zips up to the top of the page rather than the focus remaining within the form results. Kind of annoying when you have to scroll back down to see the locations. Secondly, how can the "xx stores found" be not present until the results are displayed? At the moment that statement is always there but reads "0 stores found" until results are displayed then it gives the number. Thanks for the support! btw... If anyone has any other suggestions or finds other issues I will be interested in knowing about them. <?php include_once('includes/db_connect.php'); if($_POST['state']){ $vstore = $_POST['store']; $vcity = $_POST['city']; $vstate = $_POST['state']; //$vzip = $_POST['zip']; $q=''; if($vstore != null || $vstore != '') $q .= 'strname="' . $vstore . '"'; if($vcity != null || $vcity != '') $q .= ' and city="' . $vcity . '"'; if($vstate != null || $vstate != '') $q .= ' and state="' . $vstate . '"'; //if($vzip != null || $vzip != '') $q .= ' and zipcode="' . $vzip . '"'; if(substr($q,0,4)==' and') $q=substr($q,5,strlen($q)-5); //if($vzip != null || $vzip != '') $ob .= 'strname'; if($vstate != null || $vstate != '') $ob = 'city'; if($vcity != null || $vcity != '') $ob = 'strname'; if($vstore != null || $vstore != '') $ob = 'city,state'; $query = "SELECT * FROM stores WHERE " . $q . " ORDER BY " . $ob; $result = mysql_query($query); while($row = @mysql_fetch_array($result)){ $b_name = stripslashes($row[strName]); $b_addr = stripslashes($row[address]); $b_city = stripslashes($row[city]); $b_state = stripslashes($row[state]); $b_zip = stripslashes($row[zipcode]); $b_phone = stripslashes($row[phone]); $resultArray[] = array("name"=>$b_name,"address"=>$b_addr,"city"=>$b_city,"state"=>$b_state,"zip"=>$b_zip, "phone"=>$b_phone); } } ?> <!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=utf-8" /> <title>Untitled Document</title> </head> <body> <div class="stores"> <span>You must fill out at least 1 of the search fields below.</span> <br /><br /> <form id="search_form" name="search_form" action="about.php" method="POST"> <script type="text/javascript"> function reset_form(){ document.getElementById('state').value=''; document.getElementById('city').value=''; } </script> <span style="margin-bottom:22px">Search by</span><br /> <label class="contactAdr">State: </label> <select id="state" name="state" onchange="this.form.city.value=''; document.getElementById('city').disabled='disabled'; document.getElementById('result').innerHTML='Searching...'; this.form.submit();" style="background-color:#AFCB91; border:0px;font-family:Arial,sans-serif;font-size:14px;color:#FFFFFF; font-weight:bold;height:20px;padding:2px;"> <option selected="selected" value="">Select State</option> <?php $squery = "SELECT state FROM stores GROUP BY state ORDER BY state"; $sresult = mysql_query($squery); while($srow = @mysql_fetch_array($sresult)) { if($srow[state]!=''){ ?> <option value="<?php echo $srow[state]; ?>" <?php if($_POST['state']==$srow[state]) echo'selected="selected"' ; ?>><?php echo $srow[state]; ?></option> <?php } } ?> </select> <label class="contactAdr">City: </label><select <?php if(!$_POST['state']) echo 'disabled="disabled"' ?> id="city" name="city" onchange="document.getElementById('result').innerHTML='Searching...'; this.form.submit();" style="background-color:#AFCB91; border:0px;font-family:Arial,sans-serif;font-size:14px;color:#FFFFFF;font-weight:bold;height:20px;padding:2px;"> <option selected="selected" value="">All Cities</option> <?php if(!$_POST['state']) echo '<option selected="selected">Select a State first</option>' ?> <?php $squery = "SELECT city FROM stores"; if($_POST['state']) $squery .= " where state='" . $_POST['state'] . "'"; $squery .= " GROUP BY city ORDER BY city"; $sresult = mysql_query($squery); while($srow = @mysql_fetch_array($sresult)) { if($srow[city]!=''){ ?> <option value="<?php echo $srow[city]; ?>" <?php if($_POST['city']==$srow[city]) echo 'selected="selected"' ; ?>><?php echo $srow[city]; ?></option> <?php } } ?> </select> <?php if(0){ ?> <br /> <div> <label class="contactAdr">Store: </label><select id="store" name="store" style="background-color:#996600; border:0px;font-family:Arial,sans-serif;font-size:14px;color:#FFFFFF;height:20px;padding:2px;"> <option selected="selected" value="">Any Store</option> <?php $squery = "SELECT strName FROM stores GROUP BY strname ORDER BY strname"; $sresult = mysql_query($squery); while($srow = @mysql_fetch_array($sresult)) { ?> <option value="<?php echo $srow[strName]; ?>" <?php if($vstore==$srow[strName]) echo 'selected="selected"' ; ?>><?php echo $srow[strName]; ?></option> <?php } ?> </select> <input name="zip" size="5" style="background-color:#996600; font-family:Arial,sans-serif;font-size:14px;color:#FFFFFF;width:75px;height:20px;padding:2px;"> <input type="submit" value="Search" style="background-color:#DFDFDF; border:0px;font-family:Arial,sans-serif;font-size:14px;color:#000000;width:60px;height:20px;border:1px solid #999999"> <input type="button" value="Reset" onclick="Javascript: reset_form();" style="background-color:#DFDFDF; border:0px;font-family:Arial,sans-serif;font-size:14px;color:#000000;width:60px;height:20px;border:1px solid #999999"/> <?php } ?> </div> </form> <div id='result' name='result' style="text-align:center"><? echo count($resultArray)." stores found.";?></div> <br /><br /> <div> <? for($i=0;$i<count($resultArray);$i++){?> <div style="width:200px;float:left;margin-bottom:10px"> <span class="feedname"><? echo $resultArray[$i]['name']; ?></span><br /> <span class="small"><? echo $resultArray[$i]['address']; ?></span><br /> <span class="small"><? echo $resultArray[$i]['city']; ?>,<?=$resultArray[$i]['state']; ?>,<?=$resultArray[$i]['zip']; ?></span><br /> <span class="small" style="font-weight:bold"><? echo $resultArray[$i]['phone']?></span><br /> </div> <?php }?> <br style="clear:both" /> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/176685-solved-can-i-please-get-help-on-my-store-finder-two-small-issues/ Share on other sites More sharing options...
Bricktop Posted October 6, 2009 Share Posted October 6, 2009 Hi damion, To get the page to focus on the results after clicking the submit button, do the following: Add a <a name=> attribute to the results DIV. e.g.: <div id='result' name='result' style="text-align:center"><a name="results"></a><? echo count($resultArray)." stores found.";?></div> Then, change four <form> code to read: <form id="search_form" name="search_form" action="about.php#results" method="POST"> To get the "xx stores found" text to only show when there is a number (other than 0) then a simple way to achieve this would be to change your code to read: <? if($resultArray){count($resultArray)." stores found.";}?> Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/176685-solved-can-i-please-get-help-on-my-store-finder-two-small-issues/#findComment-931487 Share on other sites More sharing options...
damion Posted October 6, 2009 Author Share Posted October 6, 2009 Hi Bricktop, Thank you for your reply and solutions. The scroll is fixed but the results don't show at all now no matter if there are any or not This is what I did.. I replaced this.. <? echo count($resultArray)." stores found.";?> With this.. <? if($resultArray){count($resultArray)." stores found.";}?> Did I do something incorrect? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/176685-solved-can-i-please-get-help-on-my-store-finder-two-small-issues/#findComment-931529 Share on other sites More sharing options...
Bricktop Posted October 6, 2009 Share Posted October 6, 2009 Hi damion, Sorry, I forgot to add the echo command! Change you code to read: <? if($resultArray){echo count($resultArray)." stores found.";}?> Sorry! Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/176685-solved-can-i-please-get-help-on-my-store-finder-two-small-issues/#findComment-931531 Share on other sites More sharing options...
damion Posted October 6, 2009 Author Share Posted October 6, 2009 Yep, that was it. Thanks again for your time Bricktop! Quote Link to comment https://forums.phpfreaks.com/topic/176685-solved-can-i-please-get-help-on-my-store-finder-two-small-issues/#findComment-931560 Share on other sites More sharing options...
damion Posted October 29, 2009 Author Share Posted October 29, 2009 Hi everyone, Now that my script is on a server that does not allow short tags, I'm having trouble when making them full tags. I get an unexpected $end error which I can understand would happen if I have an open statement somewhere. But how it happens when changing the tags is what I don't understand? Can I please get help by reviewing this part of my code which is where it breaks? It happens on the very first short tag below. I don't know if the error will continue if I get that first one to work because there are a few more that follow? <? for($i=0;$i<count($resultArray);$i++){?> <div style="width:200px;float:left;margin-bottom:10px"> <span class="feedname"><? echo $resultArray[$i]['name']; ?></span><br /> <span class="small"><? echo $resultArray[$i]['address']; ?></span><br /> <span class="small"><? echo $resultArray[$i]['city']; ?>,<?=$resultArray[$i]['state']; ?>,<?=$resultArray[$i]['zip']; ?></span><br /> <span class="small" style="font-weight:bold"><? echo $resultArray[$i]['phone']?></span><br /> </div> <?php }?> <br style="clear:both" /> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/176685-solved-can-i-please-get-help-on-my-store-finder-two-small-issues/#findComment-947404 Share on other sites More sharing options...
mikesta707 Posted October 29, 2009 Share Posted October 29, 2009 <?php for($i=0;$i<count($resultArray);$i++){?> <div style="width:200px;float:left;margin-bottom:10px"> <span class="feedname"><? echo $resultArray[$i]['name']; ?></span><br /> <span class="small"><?php echo $resultArray[$i]['address']; ?></span><br /> <span class="small"><?php echo $resultArray[$i]['city']; ?>,<?php=$resultArray[$i]['state']; ?>,<?php=$resultArray[$i]['zip']; ?></span><br /> <span class="small" style="font-weight:bold"><?php echo $resultArray[$i]['phone']?></span><br /> </div> <?php }?> <br style="clear:both" /> </div> </div> </body> </html> you really should just do a find/replace all in your favorite text editor Quote Link to comment https://forums.phpfreaks.com/topic/176685-solved-can-i-please-get-help-on-my-store-finder-two-small-issues/#findComment-947410 Share on other sites More sharing options...
damion Posted October 30, 2009 Author Share Posted October 30, 2009 you really should just do a find/replace all in your favorite text editor Thanks for your help. I have no idea why it didn't work for me before. Time to get some rest I think! Quote Link to comment https://forums.phpfreaks.com/topic/176685-solved-can-i-please-get-help-on-my-store-finder-two-small-issues/#findComment-947580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.