Jump to content

CodeMama

Members
  • Posts

    155
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Female
  • Location
    Springfield, MO

CodeMama's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. one more question about this ... what is the proper syntax to pull the 3 fields while ($r= mysql_fetch_array($bottom10)){ if($counter<=$i){ $_SESSION['bottom10'][$counter]=$r['name']['cviolations']['inDate']; $counter++; } } that causes a fatal error
  2. I am trying to loop through results from my query and store 10 records to an array and then to session: $results = mysql_query($sql) or die(mysql_error()); // Grab results $top10 = $results; $rows = mysql_fetch_array($top10); while ($rows = mysql_fetch_array($top10)){ $rows < 10; $_SESSION['top10'] = $rows; } this is close but not quite right...
  3. wow this is getting tricky...I put the $_POST =['blah'] in there and it just gave me a bunch of undefined variable errors, so I put it like this which got rid of the errors but...doesn't keep the values <tr> <td width="20%" align="right" height="30"><div class="admin_Caption">Name:</div></td> <td width="80%" height="30"><input name="searchname" type="text" size="30" <?php if(isset($_SESSION['searchname'])) { echo " value='" . $_SESSION['searchname'] = $_POST['searchname'] ."'"; } ?> > </td> </tr>
  4. well I added it and now when I reload the page it wouldn't release the sessions, so I put this // Check if there was an empty search sent if(isset($_SESSION['noVarsSent'])) { echo "<p><b>No values were submitted for the search.</b></p>"; // Unset it so a reload of page doesn't redisplay the error unset($_SESSION['noVarsSent']); unset($_SESSION['results']); unset($_SESSION['searchname']); unset($_SESSION['address']); unset($_SESSION['bmonth']); unset($_SESSION['bday']); unset($_SESSION['byear']); unset($_SESSION['emonth']); unset($_SESSION['eday']); unset($_SESSION['eyear']); unset($_SESSION['totalNumberOfRestaurants']); }else{ $_SESSION['searchname'] = $_POST; $_SESSION['address'] = $_POST; $_SESSION['bmonth'] = $_POST; $_SESSION['bday'] = $_POST; $_SESSION['byear'] = $_POST; $_SESSION['emonth'] = $_POST; $_SESSION['eday'] = $_POST; $_SESSION['eyear'] = $_POST; } ?> now when I reload the page it says "Array" in the search text boxes?
  5. Thanks going to change it to smerny suggestion see if on submit it holds the values ...I may be back
  6. I found a couple examples and have tried and they all seem to be based around this but it doesn't work anyone see my error? <tr> <td width="20%" align="right" height="30"><div class="admin_Caption">Name:</div></td> <td width="80%" height="30"><input name="searchname" type="text" size="30" <?php if(isset($_SESSION['searchname'])) { echo " value='" . $_SESSION['searchname'] . " ['searchname'] '"; } ?> > </td> </tr> The session_start() is at the top of my page along with checking for the sessions.... help help
  7. easiest was to just use the javascript function <a href="javascript:history.back()">Back to Previous</a>
  8. this is my alpha links pagination code...is it even called pagination? <?php // Function to create paging. function createPaging($selectedLetter = null) { $letters = range('A','Z'); array_push($letters, 'nums'); $menu = ''; foreach($letters as $letter) { if($letter == $selectedLetter && $selectedLetter != 'nums') { $menu .= sprintf('%s&nbsp', $letter); } else if($letter == $selectedLetter && $selectedLetter == 'nums') { $menu .= sprintf('%s&nbsp', '#', '<hr>'); } else { if($letter == 'nums') { $menu .= sprintf('<a href="browse.php?letter=%s">%s</a> ', 'nums', '#'); } else { $menu .= sprintf('<a href="browse.php?letter=%s">%s</a> ', $letter, $letter); } } } return $menu; echo ('<HR>'); } // Function to show just paging. function index() { // Echo only paging. echo createPaging(); } // Function to show results if page was given. function browse($selectedLetter) { // Echo paging. echo createPaging($selectedLetter); echo '<br><hr>'; //Show all restaurants that start with $letter not between "A" and "Z" if ($selectedLetter == "nums") { for($i = 0; $i <= 9; $i++) { $sql = "SELECT DISTINCT ID, name, address FROM restaurants WHERE name LIKE '$i%'"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { echo '<br>'; $name = $row['name']; printf('<br><a href="view.php?ID=%s"><b>%s</b><br />%s<br /><br /></a>', $row['ID'], $row['name'], $row['address']); } } } else { $sql = "SELECT DISTINCT ID, name, address FROM restaurants WHERE name LIKE '$selectedLetter%'"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $name = $row['name']; printf('<a href="view.php?ID=%s"><b>%s</b><br />%s<br /><br /></a>', $row['ID'], $row['name'], $row['address']); } } } // Main controller which page to show. if (isset($_GET['letter'])) { browse($_GET['letter']); } elseif (basename($_SERVER['SCRIPT_FILENAME']) == "browse.php" ) { browse('A'); } else { index(); } ?>
  9. yes but that is numerical pagination these are passing variables in the url like letter=G to a completely other page so I have to jump back over a page back to letter=G or whatever I tried using the $selectedLetter which is what the script uses but it didn't pick it up it just said letter=$selectedLetter
  10. I have an alphabetical menu list for browsing so say a user chooses "G" then picks a "G" record to view, whats the easiest way to make a "back to results" link and take them back to the letter they chose? Thanks
  11. why yes...lmao..that much I do know....roflmao... ok here is my most recent updated code...got the full db results to stop outputting..but now I realize that my 7, 30, and 60 day interval query isn't working: <?php // Check if page is set to show all //if(isset($_GET['show']) && $_GET['show'] == 'all') { unset($_SESSION['seven']); unset($_SESSION['thirty']); unset($_SESSION['sixty']); unset($_SESSION['searchDate']); } // Check if there was an empty search sent if(isset($_SESSION['noVarsSent'])) { echo "<p><b>No values were submitted for the search.</b></p>"; // Unset it so a reload of page doesn't redisplay the error unset($_SESSION['noVarsSent']); unset($_SESSION['results']); } //unset($_SESSION['fullRestaurantList']); // Check if full list of restaurants has been created and stored yet // Store results in $_SESSION to limit database hits if(!isset($_SESSION['results'])) { // List not grabbed yet, so run query and store in $_SESSION //check for range if (!(isset($rangenum))) { $rangenum = 1; } if (!empty($_POST['seven'])) { $seven = $_POST['seven']; $_SESSION['seven'] = $seven; $searchDate = TRUE; } else { $seven = ''; } if (!empty($_POST['thirty'])) { $thirty = $_POST['thirty']; $_SESSION['thirty'] = $thirty; $searchDate = TRUE; } else { $thirty = ''; } if (!empty($_POST['sixty'])) { $thirty = $_POST['sixty']; $_SESSION['sixty'] = $sixty; $searchDate = TRUE; } else { $sixty = ''; } $pastDays = strtotime("-30 days"); $today = getdate(); //Working Date Query $sql = "SELECT r.ID, r.name, r.address, i.inDate FROM restaurants r, inspections i WHERE r.ID = i.ID AND r.name != '' "; if ($seven) { $sql .= "DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= i.inDate "; } if ($thirty) { $sql .= "DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= i.inDate "; } if ($sixty) { $sql .= "DATE_SUB(CURDATE(),INTERVAL 60 DAY) <= i.inDate "; } $sql .= "GROUP BY r.ID, r.name, r.address, i.inDate ORDER BY i.inDate DESC "; $result = mysql_query($sql) or die(mysql_error()); //trying to grab it by ranges from the db? $rows = mysql_num_rows($result); $page_rows = 100; $last_row = ceil($rows/$page_rows); if ($rangenum < 1) { $rangenum = 1; } elseif ($rangenum > $last_row) { $rangenum = $last_row; } //This sets the range to display in our query $max = 'limit ' .($rangenum - 1) * $page_rows .',' .$page_rows; // Process all results into $_SESSION array $position = 1; while ($row = mysql_fetch_array($result)) { $_SESSION['searchDate'][$position] = $row; $position++; } //$_SESSION['totalNumberOfRestaurants'] = $position; } ?> <table width="900" border="0"> <Tr> <td height="30" colspan="2"></td> <h3>Restaurant Inspections</h3> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <select name="searchDate"> <option value="seven">Last 7 Days</option> <option value="thirty">Last 30 Days</option> <option value="sixty">Last 60 Days</options> </select> <input name="searchDate" type="submit" value="Search"> </tr> <tr align="center"> <td align="center" colspan="3"> </td> </tr> <tr> <td align="center" colspan="3"><p>The following listings are the Greene County Department of Health Restaurant Inspections from the last 30 days.</p></td></tr> </table> <?php if(isset($_GET['Page'])) $Page = $_GET['Page']; else $Page = 1; $PerPage = 50; if(isset($_SESSION['numResults'])) { $TotalPages = ceil($_SESSION['numResults']/$PerPage); } else { $TotalPages = 1; } $StartPage = ($Page - 1) * $PerPage; // Output table header ?> <TABLE WIDTH="100%" cellspacing="3" cellpadding="4"> <TR> <TD ALIGN="CENTER" width="50" VALIGN="TOP" BGCOLOR="#000000"><FONT size="-2" COLOR="#FFFFFF"><B>Name</B></FONT></TD> <TD ALIGN="CENTER" width="50" VALIGN="TOP" BGCOLOR="#000000"><FONT size="-2" COLOR="#FFFFFF"><B>Address</B></FONT></TD> <TD ALIGN="CENTER" width="20" VALIGN="TOP" BGCOLOR="#000000"><FONT size="-2" COLOR="#FFFFFF"><B>Inspection Date</B></FONT></TD> </TR> <?php // Control logic to determine if displaying results or not if(isset($_SESSION['results'])) { // Output results if($_SESSION['results'] == "No results found") { // Query came back with nothing ?> <TR bgcolor="<?php echo $row_color ?>"> <td> <p>No results where found matching your criteria.</p> </td> </tr> <?php } else { // There are results //$ID= $_SESSION['results'][$i]['ID']; for($i = $StartPage + 1; $i < ($PerPage*$Page) && $i < $_SESSION['numResults']; $i++) { $color1 = "#FFFFFF"; $color2 = "#EAEAEA"; $row_color = ($i % 2) ? $color1 : $color2; ?> <TR bgcolor="<?php echo $row_color ?>"> <TD><FONT SIZE="-2"><a href="view.php?ID=<?php echo ($_SESSION['results'][$i]['ID']); ?>"><?php echo htmlspecialchars(stripslashes($_SESSION['results'][$i]['name'])); ?></a></FONT></TD> <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['results'][$i]['address']); ?></FONT></TD> <TD><FONT SIZE="-2"> <?php $date = strtotime($_SESSION['results'][$i]['inDate']); $formatDate = date('M j Y', $date); echo $formatDate; ?></FONT></TD> </TR> <?php } ?> </TABLE> <?php } } else { for($i = $StartPage + 1; $i < ($PerPage*$Page) && $i < $_SESSION['searchDate']; $i++) { $color1 = "#FFFFFF"; $color2 = "#EAEAEA"; $row_color = ($i % 2) ? $color1 : $color2; ?> <TR bgcolor="<?php echo $row_color ?>"> <TD><FONT SIZE="-2"><a href="view.php?ID=<?php echo $_SESSION['searchDate'][$i]['ID']?>"><?php echo htmlspecialchars(stripslashes($_SESSION['searchDate'][$i]['name'])); ?></a></FONT></TD> <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['searchDate'][$i]['address']); ?></FONT></TD> <TD><FONT SIZE="-2"><?php $date = strtotime($_SESSION['searchDate'][$i]['inDate']); $formatDate = date('M j Y', $date); echo $formatDate; ?></FONT></TD> </TR> <?php } ?> </TABLE> <?php // Calculate total number of pages $TotalPages = ceil($_SESSION['results']/$PerPage); } // Output paging control // Only need to output this if there is more than 1 page of results if ($TotalPages > 1) { echo "<hr /> \n <p>Click on the following links for more pages of results</p> \n <p>"; if ($Page != 1) { // If on first page, no need for Previous Page button echo "<a href='restaurants.php?Page="; echo $Page-1; echo "'><< Previous</a> "; } for($i = 1; $i <= $TotalPages; $i++) { if($i == $Page) { // Outputting link for current page - doesn't need to be a link echo "$i "; } else { // Outputting link for other pages - needs to be a link echo "<a href='restaurants.php?Page=$i'>$i</a> "; } } if ($Page != $TotalPages) { // If on last page, no need for Next Page button echo "<a href='restaurants.php?Page="; echo $Page+1; echo "'>Next >></a> "; } } ?>
  12. Updated Code caught some of my more obvious mistakes ...I know it lies in my sessions...right now it appears to ALMOST WORK...the date selection part works but then it is also outputting all the restaurants...so it will say...output the last seven days, then after that..list everything... updated code: <?php // Check if page is set to show all if(isset($_GET['show']) && $_GET['show'] == 'all') { unset($_SESSION['results']); unset($_SESSION['searchname']); unset($_SESSION['address']); } // Check if there was an empty search sent if(isset($_SESSION['noVarsSent'])) { echo "<p><b>No values were submitted for the search.</b></p>"; // Unset it so a reload of page doesn't redisplay the error unset($_SESSION['noVarsSent']); // unset($_SESSION['results']); } //unset($_SESSION['fullRestaurantList']); // Check if full list of restaurants has been created and stored yet // Store full results in $_SESSION to limit database hits // if(!isset($_SESSION['fullRestaurantList'])) { // List not grabbed yet, so run query and store in $_SESSION //check for range if (!(isset($rangenum))) { $rangenum = 1; } if (!empty($_POST['seven'])) { $seven = $_POST['seven']; $_SESSION['seven'] = $seven; $searchDate = TRUE; } else { $seven = ''; } if (!empty($_POST['thirty'])) { $thirty = $_POST['thirty']; $_SESSION['thirty'] = $thirty; $searchDate = TRUE; } else { $thirty = ''; } if (!empty($_POST['sixty'])) { $thirty = $_POST['sixty']; $_SESSION['sixty'] = $sixty; $searchDate = TRUE; } else { $sixty = ''; } // Grab all restaurants in alphabetical order $pastDays = strtotime("-30 days"); $today = getdate(); //Working Date Query $sql = "SELECT r.ID, r.name, r.address, i.inDate FROM restaurants r, inspections i WHERE r.ID = i.ID AND r.name != '' "; if ($seven) { $sql .= "DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= i.inDate "; } if ($thirty) { $sql .= "DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= i.inDate "; } if ($sixty) { $sql .= "DATE_SUB(CURDATE(),INTERVAL 60 DAY) <= i.inDate "; } $sql .= "GROUP BY r.ID, r.name, r.address, i.inDate ORDER BY i.inDate DESC "; $result = mysql_query($sql) or die(mysql_error()); //trying to grab it by ranges from the db? $rows = mysql_num_rows($result); $page_rows = 100; $last_row = ceil($rows/$page_rows); if ($rangenum < 1) { $rangenum = 1; } elseif ($rangenum > $last_row) { $rangenum = $last_row; } //This sets the range to display in our query $max = 'limit ' .($rangenum - 1) * $page_rows .',' .$page_rows; // Process all results into $_SESSION array $position = 1; while ($row = mysql_fetch_array($result)) { $_SESSION['searchDates'][$position] = $row; $position++; } $_SESSION['totalNumberOfRestaurants'] = $position; } ?>
  13. here is my code....trying to get a drop down to pass to a query: $seven = $_GET['seven']; $thirty = $_GET['thirty']; $sixty = $_GET['sixty']; if (!empty($_GET['seven'])) { $seven = $_GET['seven']; $_SESSION['seven'] = $seven; $searchDate = TRUE; } else { $seven = ''; } if (!empty($_GET['thirty'])) { $thirty = $_GET['thirty']; $_SESSION['thirty'] = $thirty; $searchDate = TRUE; } else { $thirty = ''; } if (!empty($_GET['sixty'])) { $thirty = $_GET['sixty']; $_SESSION['sixty'] = $sixty; $searchDate = TRUE; } else { $sixty = ''; } // Grab all restaurants in alphabetical order $pastDays = strtotime("-30 days"); $today = getdate(); //Working Date Query $sql = "SELECT r.ID, r.name, r.address, i.inDate FROM restaurants r, inspections i WHERE r.ID = i.ID AND r.name != '' "; if ($seven) { $sql .= "DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= i.inDate "; } if ($thirty) { $sql .= "DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= i.inDate "; } if ($sixty) { $sql .= "DATE_SUB(CURDATE(),INTERVAL 60 DAY) <= i.inDate "; } $sql .= "GROUP BY r.ID, r.name, r.address, i.inDate ORDER BY i.inDate DESC "; $result = mysql_query($sql) or die(mysql_error());
  14. I have the date part working, but now if I search with no date inputted it returns nothing ..so now I can't just search by name...damnit.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.