sKunKbad
Members-
Posts
1,832 -
Joined
-
Last visited
-
Days Won
3
Everything posted by sKunKbad
-
OK, so I want to get the city and st info from my form that I used method="get" on. On my program that is receiving the form info, I need to turn the city and st into a variable, so I have been trying: $var1="$_GET[city]"; $var2="$_GET[st]"; but this is not working, or I have more severe problems. Do I need to do something else to get these variables made? Thanks,
-
[!--quoteo(post=361790:date=Apr 4 2006, 05:52 PM:name=dcro2)--][div class=\'quotetop\']QUOTE(dcro2 @ Apr 4 2006, 05:52 PM) [snapback]361790[/snapback][/div][div class=\'quotemain\'][!--quotec--] Besides that, after the first condition and $sql, you are forgetting to put a ")" to the end of mysql_query() [/quote] Thanks for pointing that out. I am really a super n00bie to php, so I need all the help I can get! I'm still hoping somebody can figure out my original error.
-
[!--quoteo(post=361786:date=Apr 4 2006, 05:34 PM:name=dcro2)--][div class=\'quotetop\']QUOTE(dcro2 @ Apr 4 2006, 05:34 PM) [snapback]361786[/snapback][/div][div class=\'quotemain\'][!--quotec--] I'm pretty sure it has something to do with how you get the value of $value1 and $value2: [code]$value1 = "$_GET[subType]"; $value2 = "$_GET[city]";[/code] To get a value from an array ($_GET) you need to put it inside curly brackets ({}) while inside quotes. You also don't need to put it inside quotes, if it's a string, then the $value variable is going to be a string also. [code]$value1 = $_GET[subType]; $value2 = $_GET[city];[/code] [/quote] No, that didn't make any difference. Thanks for trying though.
-
I'm getting this error: Parse error: parse error, unexpected T_STRING in /testbusiness_search.php on line 19, and I can't figure it out. Line 19 is if ($value1 != "All Christian Business" AND $value2 != "All Cities") I'm pretty sure once this is taken care of I'm going to have some more problems with this page, specifically the $num_rows = mysql_num_rows ($sql); Here is the surrounding php: [code]<?php include("./includes/genesis.php"); $value1 = "$_GET[subType]"; $value2 = "$_GET[city]"; echo "<h2>$subType in $city</h2>"; if (!isset($_GET['page'])){ $page = 1; } ELSE { $page = $_GET['page']; } $max_results = 5; $from = (($page * $max_results) - $max_results); if ($value1 != "All Christian Business" AND $value2 != "All Cities") {$sql = mysql_query("SELECT * FROM localdirectory WHERE subType = '$value1' AND city = '$value2' ORDER BY name LIMIT $from, $max_results"); } if ($value1 == "All Christian Business" AND $value2 != "All Cities") {$sql = mysql_query("SELECT * FROM localdirectory WHERE city = '$value2' ORDER BY name LIMIT $from, $max_results"; } if ($value1 != "All Christian Business" AND $value2 == "All Cities") {$sql = mysql_query("SELECT * FROM localdirectory WHERE subType = '$value1' ORDER BY name LIMIT $from, $max_results"; } if ($value1 == "All Christian Business" AND $value2 == "All Cities") {$sql = mysql_query("SELECT * FROM localdirectory ORDER BY name LIMIT $from, $max_results";} if ($value1 == "All Christian Business" AND $value2 == "Riverside County") {$sql = mysql_query("SELECT * FROM localdirectory ORDER BY name LIMIT $from, $max_results";} if ($value1 != "All Christian Business" AND $value2 == "Riverside County") {$sql = mysql_query("SELECT * FROM localdirectory WHERE subtype = '$value1' ORDER BY name LIMIT $from, $max_results";} $num_rows = mysql_num_rows ($sql); if ($num_rows == 0) {echo "<p id=\"warning\">There are currently no matches for your search in the database.<br/>\nPlease try widening your search by choosing \"All Cities\" or \"Riverside County\"<br/>\n<a href=\"http://www.iamsent.com/directory.php\">Go Back</a></p>";} ELSE { while ($row = mysql_fetch_array($sql)) extract ($row); if($type == "business") { //This is where the business listings get called up by the if statement echo "<div class=\"sponsor\">";} if($sponsorStatus == "yes"){echo "<img src=\"images/sponsor.jpg\" alt=\"this Christian owned business is a site sponsor\"/>";} else {echo " ";} echo "</div>"; echo "<div class=\"listing\">"; echo "<strong>$name</strong>"; if($address != ""){echo "<br/>\n$address";} if($city != ""){echo "<br/>\n$city",", ";} if($st != ""){echo "$st"," ";} if($zip != ""){echo "$zip";} if($teleNumber != ""){echo "<br/>\n$teleNumber";} if($webAddress != ""){echo "<br/>\nwebsite: <a href=\"$webAddress\">$webAddress</a>";} if($email != ""){echo "<br/>\nemail: <a href=\"mailto:$email\">$email</a>";} echo "</div>\n";?><div class="hrule76"> </div><?php echo "\n"; } if ($value1 != "All Christian Business" && $value2 != "All Cities"){ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE subType ='$value1' AND city = '$value2'"),0); } if ($value1 == "All Christian Business" && $value2 != "All Cities"){ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'business' AND city ='$value2'"),0); } if ($value1 != "All Christian Business" && $value2 == "All Cities"){ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE subType = '$value1' "),0); } if ($value1 == "All Christian Business" && $value2 == "All Cities"){ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'business' "),0); } if ($value1 == "All Christian Business" && $value2 == "Riverside County"){ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'business' "),0); } if ($value1 != "All Christian Business" && $value2 == "Riverside County"){ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE subType = '$value1' "),0); } $total_pages = ceil($total_results / $max_results); echo "<center><br/><strong>Page<br />"; if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&subType=$value1&city=$value2\"><<Previous</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&subType=$value1&city=$value2\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&subType=$value1&city=$value2\">Next>></a>"; } echo "</strong></center>"; echo "<p><a href=\"http://www.iamsent.com/directory.php\">Back To Directory Home</a></p>"; echo "<p><a href=\"http://www.iamsent.com/directory.php\">Go Back</a></p>"; ?> [/code] Thanks for your help.
-
Did you ever get this fixed? I'm having the same problem right now and trying to work it out.
-
[!--quoteo(post=361487:date=Apr 3 2006, 11:27 PM:name=footballkid4)--][div class=\'quotetop\']QUOTE(footballkid4 @ Apr 3 2006, 11:27 PM) [snapback]361487[/snapback][/div][div class=\'quotemain\'][!--quotec--] Sessions would be easier, and safer to work with if this is going to be a critical project. If it's just a simple search feature then I would suggest using $_GET. If you don't need to use sessions, simply don't do it...it's just more server load. If you are going to use sessions for this, be sure that your php.ini configuration is setup to unset them after they exit the browser...otherwise users might try to come back and search...and then see the same results as their last search. [/quote] I fixed it! I just changed my form method to GET, and added &city=$value1 in back of ?page=$prev, ?page=$i, and ?page=$next. Thanks for you help, now I have a new problem!
-
[!--quoteo(post=361477:date=Apr 3 2006, 10:05 PM:name=footballkid4)--][div class=\'quotetop\']QUOTE(footballkid4 @ Apr 3 2006, 10:05 PM) [snapback]361477[/snapback][/div][div class=\'quotemain\'][!--quotec--] The reason you aren't seeing any results is because you are trying to access a $_POST variable, which is unset after you navigate away from the page that the data was posted to. You can urlencode() it and pass it into the querystring, or use sessions to store the information. [/quote] Well, I have absolutely no idea how to accomplish what you are saying to do, but I will start looking into it. Is one way easier than the other? Sessions vs. urlencode() pass to querystring?
-
Actually what I have now is a link to page 2, but page two doesn't have any results on it. [code]<?php include("./includes/genesis.php"); $value1 = "$_POST[city]"; echo "<h2>Christian Churches in $city</h2>"; if (!isset($_GET['page'])){ $page = 1; } ELSE { $page = $_GET['page']; } $max_results = 5; $from = (($page * $max_results) - $max_results); if ($value1 == "All Cities") {$sql = mysql_query("SELECT * FROM localdirectory WHERE type = 'church' LIMIT $from, $max_results"); } ELSE {$sql = mysql_query("SELECT * FROM localdirectory WHERE city = '$value1' AND type = 'church' LIMIT $from, $max_results"); } while($row = mysql_fetch_array($sql)) { extract ($row); echo "<div class=\"sponsor\">"; if($sponsorStatus == "yes"){echo "<img src=\"images/sponsor.jpg\" alt=\"this church is a site sponsor\"/>";} else {echo " ";} echo "</div>"; echo "<div class=\"listing\">"; echo "<strong>$name</strong>"; if($address != ""){echo "<br/>\n$address";} if($city != ""){echo "<br/>\n$city",", ";} if($st != ""){echo "$st"," ";} if($zip != ""){echo "$zip";} if($teleNumber != ""){echo "<br/>\n$teleNumber";} if($webAddress != ""){echo "<br/>\nwebsite: <a href=\"$webAddress\">$webAddress</a>";} if($email != ""){echo "<br/>\nemail: <a href=\"mailto:$email\">$email</a>";} echo "</div>\n";?><div class="hrule76"> </div><?php echo "\n"; } echo "<p><a href=\"http://www.iamsentme.com/directory.php\">Go Back</a></p>"; if ($value1 == "All Cities"){ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'church'"),0); }ELSE{ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'church' AND city ='$value1'"),0); } $total_pages = ceil($total_results / $max_results); echo "<center><br/><strong>Page<br />"; if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>"; } echo "</strong></center>"; ?>[/code]
-
My pagination works, I have this: [code]if (!isset($_GET['page'])){ $page = 1; } ELSE { $page = $_GET['page']; } $max_results = 10; $from = (($page * $max_results) - $max_results); $sql = mysql_query("SELECT * FROM localdirectory LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ echo $row ['name']."<br/>";[/code] which is all good, but it only outputs the name field of my database, I want to be able to output all of the other fields, like ['address'],['city'],['st'],['zip']. I've tried adding that in various ways, but can't get it to work. I can't figure it out. Please help. Thanks for your help!
-
[!--quoteo(post=360650:date=Apr 1 2006, 09:59 AM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ Apr 1 2006, 09:59 AM) [snapback]360650[/snapback][/div][div class=\'quotemain\'][!--quotec--] There's at least a couple of ways: 1) After the mysql_query() and error checking (or die), you can run a mysql_num_rows(). If it's greater than zero, then you have rows and can do the while loop. Otherwise, display no match message. [a href=\"http://us2.php.net/manual/en/function.mysql-num-rows.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.mysql-num-rows.php[/a] 2) Set a counter variable to zero before the while loop. Increment it in the while loop. Then after the while loop, check to see if it's zero and display no match message. hth. [/quote] AWESOME! It worked. I used an if statement where if $num_rows was "" it gives the no match message> Thanks for your help this morning. I haven't slept well lately, and my brain is fryed.
-
[!--quoteo(post=360644:date=Apr 1 2006, 09:32 AM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ Apr 1 2006, 09:32 AM) [snapback]360644[/snapback][/div][div class=\'quotemain\'][!--quotec--] You forgot the dollar sign on value2 when building the $query variable. [code] if ($value1 != "All" && $value2 != "All") { $query = "SELECT * FROM localdirectory WHERE subType = '$value1' AND city = '$value2' "; // missing $ } else { $query = "SELECT * FROM localdirectory"; } [/code] You may want to display something when there's no match. [/quote] toplay, can you suggest how to display "your search criteria returned no matches" when there is no match. In the last few minutes I made it to where if one $value=="All" and the other $value !="All" then results are displayed correctly, I just need to have a no match message now. Thanks,
-
***Nevermind, I fixed it, I should have stayed in bed*** I have a problem with this program. You can see that if both $value1 and $value2 are "All" that the results are indeed displayed, but if $value1 and $value2 are not both "All" the resulting page comes up totally blank. Please help: <?php $value1 = "$_POST[subType]"; $value2 = "$_POST[city]"; { include("./xxxyyyzzz.php"); if ($value1 != "All" AND $value2 != "All") {$query = "SELECT * FROM localdirectory WHERE subType = '$value1' AND city = 'value2' "; } if ($value1 == "All" AND $value2 == "All") {$query = "SELECT * FROM localdirectory" ;} } $result = mysql_query($query) or die ("Couldn't execute query."); while ($row = mysql_fetch_array($result)) { extract ($row); ?> <?php if($type == "business") { //This is where the business listings get called up by the if statement ?> <div class="sponsor"> <?php if($sponsorStatus == "yes"){echo "<img src=\"images/sponsor.jpg\" alt=\"this Christian owned business is a site sponsor\"/>";} else {echo " ";} ?> </div> <div class="listing"><?php echo "<strong>$name</strong>"; if($address != ""){echo "<br/>\n$address";} if($city != ""){echo "<br/>\n$city",", ";} if($st != ""){echo "$st"," ";} if($zip != ""){echo "$zip";} if($teleNumber != ""){echo "<br/>\n$teleNumber";} if($webAddress != ""){echo "<br/>\nwebsite: <a href=\"$webAddress\">$webAddress</a>";} if($email != ""){echo "<br/>\nemail: <a href=\"mailto:$email\">$email</a>";} echo "</div>\n";?><div class="hrule76"> </div><?php echo "\n"; } } ?> Thanks for any help,
-
Is that the output your were looking for? I'm working on a similar output right now, and being new to php I found the code will work perfectly for what I need to do, except that I will be using a CSS layout. Never really liked table layouts. Good luck.