Jump to content

bruisr

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by bruisr

  1. OK, I figured out how to add it. $output .= "<td><a href='loc_details.php?loc_id={$row['loc_id']}&{$row['loc_name']}'>{$row['loc_name']}</a></td>\n"; Now I'm running into 2 other issues. [*]If there is a single quote in the name, such as Devil's Eye, it cuts out just before the single quote. [*]The spaces are displayed as %20. Are there ways around this with php? Thanks!
  2. Hello - I have a search page that displays urls to a details page. Currently, the url looks like this: ".com/loc_details.php?loc_id=38" but I would like it to have the contents of the 'loc_name' field display after the id. Here is how it's being called in the code: $output .= "<td><a href='loc_details.php?loc_id={$row['loc_id']}'>{$row['loc_name']}</a></td>\n"; The only thing I can think of to compare it to would be the pretty links that Wordpress offers. The website for reference is www.giantstridedives.com/locations, so you can see it in action. Thanks for any help!
  3. mjdamato you're the man. Thanks for that. I did need to change from date to id since I don't have a date field set up. I should do that though, so thanks for reminding me about that. It worked perfectly to display the latest results but when I did a search, it returned this error at the top of the page: Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user ''@'localhost' (using password: NO) in C:\websites\giantstridedives\locations\index.php on line 12 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\websites\giantstridedives\locations\index.php on line 12 I removed the 'mysql_real_escape_strings()' code and it worked. After doing some searching, I found someone who said "Turns out i needed a database link in code before the rest. " I assume that he means the connection to the database. So after taking the advice in your signatures, I checked the php.net on mysql_real_escape_strings() and found an example that had a 'mysql_connect()' before the escape strings. So I added it above that line: mysql_connect($dbhost, $dbuser, $dbpass); $searchterm = mysql_real_escape_string(trim($_POST['search'])); Problem solved. Thanks again for your help!
  4. I have a search page and everything works fine but I would like to add the latest 10 rows to the page so there is something to look at or click on before the user searches. The page is at: www.giantstridedives.com/locations. You can see that it's pretty boring. Hit submit and you'll see the entries so far (only 3 right now). I'd like to have the latest 10 display there by default but then when a user searches they are replaced by the search results. Make sense? Here's the code I'm using for the search: <?php if (isset($_POST['submit'])) { require_once('dbconnection.php'); mysqli_select_db($conn, $dbname); $searchterm = $_POST['search']; $searchterm = strip_tags($searchterm); $searchterm = trim ($searchterm); $q ="SELECT * FROM locations WHERE loc_name LIKE '%" . $searchterm . "%' AND loc_approved != '0'"; $r = mysqli_query($conn, $q) or die(mysql_error($q)); $row = mysqli_fetch_assoc($r); $rowcount = mysqli_num_rows($r); } ?> <h1>Search for Scuba Dive Locations</h1> <form id="searchform" name="searchform" method="post" action="index.php"> <input type="text" name="search" id="search_bar" /> <input type="submit" name="submit" id="submit" value="Submit" /> </form> <span style="color: #333;">Search for the name of the location, ie: Devils Den or USS Oriskany.</span><br /> <?php if (isset($_POST['submit'])) { if ($rowcount == 0) { echo "Sorry, but we can not find an entry to match your query: <strong>$searchterm</strong>"; } else { //this tells the table below to display since $totalRows_Products_res is not 0 ?> <table style="font-size: 14px;" border="0" width="650"> <tr> <td colspan="6"><p>You searched for <strong><?php echo $searchterm; ?></strong>. Results are displayed below.</p></td> </tr> <tr> <td><strong>Location Name</strong></td> <td><strong>City</strong></td> <td><strong>State</strong></td> <td><strong>Depth (ft)</strong></td> <td><strong>Fees</strong></td> <td><strong>Gear Rentals</strong></td> <td><strong>Map</strong></td> </tr> <?php do { ?> <tr> <td><a href="loc_details.php?loc_id=<?php echo $row ['loc_id']; ?>"> <?php echo $row ['loc_name']; ?> </a></td> <td><?php echo $row ['loc_city']; ?></td> <td><?php echo $row ['loc_state']; ?></td> <td><?php echo $row ['loc_depth']; ?></td> <td>$<?php echo $row ['loc_fee']; ?></td> <td><?php if($row['loc_gear'] == 1) { echo 'Yes'; } else { echo 'No'; } ?></td> <td><a href="http://maps.google.com/maps?q=<?php echo $row ['loc_lat'];?>,<?php echo $row ['loc_lon'];?>" target="_blank">View Map</a></td> </tr> <?php } while ($row = mysqli_fetch_assoc($r)); ?> </table> <?php mysqli_free_result($r); } // this closes out results else } ?> I figure I can use the below query to get the results. select * from table WHERE id > ((SELECT MAX(id) from table) - 10); I'm just not sure how I can display them by default and then have them be replaced by the search results. Anyone have any ideas for me? As always I appreciate the help as I continue to learn this beast.
  5. I'm actually not using a loop. Because there are multiple files to be called that have a different file name, I figured it would be best code it separately? Either way, it's what I did Though your post didn't fix it exactly, it did prompt me to do another google search which led me to the 'file_exists' function. This now works for me: <?php if (file_exists('images/uploads/' . $row['loc_id'] . '_1.jpg')) { echo '<tr><td><a href="images/uploads/' . $row['loc_id'] . '_1.jpg"><img id="morephoto" src="images/uploads/thumbs/' . $row['loc_id'] . '_1thb.jpg" /></a></td></tr>'; } ?> I just copy that and change it for the _2, _3 and _4 that I have for my 4 images. Tested it on a page with pics and one with out and it works great. Thanks for your help! What part of Florida are you in? I'm in the Leesburg area.
  6. Thanks for the reply. Um, could you be a bit more specific? Explain it to me like you would to a 4 year old learning why 1 + 1 = 2
  7. Hey guys - I have some code that pulls an image out of a folder and displays it on the page. The problem is, there won't always be an image to display in which case I'd rather the code not even display. Here's my code so far: <tr><td><a href="images/uploads/<?php echo $row['loc_id']; ?>_1.jpg"><img id="morephoto" src="images/uploads/thumbs/<?php echo $row['loc_id']; ?>_1thb.jpg" /></a></td></tr> The images are renamed on upload to have the id number for that row appended to the front of the file name and that is how I'm calling them back in. I know I need to write an if statement that contains the code from the <tr> to the </tr> to display if the image exists, the problem is, since there isn't a field for this in the database, I don't know how to check it? I'm still a noob so I appreciate any help that is offered. Thanks!
×
×
  • 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.