Everything posted by Daemon Byte
-
Php / mysql search problem
I tend to write code that's more generic. By using an array like I did it allows you to reuse the function with any array you like and you don't have to alter the function. It also means if you do want to alter that html line it's only one line instead of who knows how many lines. There is no reason specifically to do it. I just prefer it personally.
-
Php / mysql search problem
gah why are you using fetch object? I totally missed that. use fetch assoc. while($myrow = mysql_fetch_object($result)) to while($myrow = mysql_fetch_assoc($result)) you might want to drop the second appearance of echo '<h1>Search Database!</h1>'; as well :-)
-
Php / mysql search problem
You don't need the is empty. I found the problem. if($searchwords) /// CHECK SEARCH HAVE BEEN FILLED IN $whatsediterror[1]='<p class="style1"> Please search for something</p>'; should be if(!$searchwords) /// CHECK SEARCH HAVE BEEN FILLED IN echo '<p class="style1"> Please search for something</p>';
-
Php / mysql search problem
on line 33 swap $searchby = (isset($_GET['searchby'])?NULL:mysql_escape_string($_GET['searchby'])); to $searchby = (isset($_GET['searchby'])?mysql_escape_string($_GET['searchby']):false); I got the if the wrong way around :-)
-
Php / mysql search problem
ok that was full of problems so try this. <?php error_reporting(E_ALL); /************************** change to match your connection method ********************/ require_once ('../mysql_connect.php'); // Connect to the db. // Create the search function: function searchForm($select, $searchwords='') { // Re-usable form // variable setup for the form. echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">'; echo '<input type="hidden" name="cmd" value="search" />'; echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" /> '; echo 'in'; echo '<select name="searchby">'; foreach ($select as $id => $value) echo '<option value="'.$id.'">'.$value.'</option>'; echo '</select> '; echo '<input type="submit" value="Search" />'; echo '</form>'; } /************************************** END OF FUNCTION *****************************************************/ $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : false); $searchby = (isset($_GET['searchby'])? NULL : mysql_escape_string($_GET['searchby'])); $list = array( 'fname' => 'First Name', 'lname' => 'Last Name', 'details' => 'Details', 'age' => 'Age', 'location' => 'Location', 'email' => 'Email' ); echo '<h1>Search Database!</h1>'; searchForm($list, $searchwords); if(isset($_GET['cmd'])) { ///// CHECK SEARCH WHEN SUMBMITTED if($searchwords) /// CHECK SEARCH HAVE BEEN FILLED IN $whatsediterror[1]='<p class="style1"> Please search for something</p>'; else { $sql = "SELECT * FROM users WHERE {$searchby} LIKE '%{$searchwords}%'"; $result = mysql_query($sql) or die($sql.'<br /><hr /><br />'.mysql_error()); echo '<hr size="1" />'; if(mysql_num_rows($result)>0) { echo '<table align="center" cellspacing="0" cellpadding="5">'; while($myrow = mysql_fetch_object($result)) { echo'<tr><td><span>' .$myrow['fname'] .'</td><td>'. $myrow['lname'] . ' </td><td>'. $myrow['email'] .'</td><td>'. $myrow['location'] . ' </span></td></tr>'; } echo '</table>'; } else { echo '<h1>Search Database!</h1>'; echo "no results found! Try again!"; } } } ?>
-
Label Placement in Forms
I will have to alter my forms accordingly :-)
-
Php / mysql search problem
I've made some changes. <?php // Full-Text Search Example /************************** change to match your connection method ********************/ require_once ('../mysql_connect.php'); // Connect to the db. // create variables for the db $firstn='fname'; $lastn='lname'; $details='details'; $age='age'; $location='location'; $email='email'; // Create the search function: function searchForm() { // Re-usable form // variable setup for the form. $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : ''); $searchby = (isset($_GET['searchby'])? NULL : $_GET['searchby']); echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">'; echo '<input type="hidden" name="cmd" value="search" />'; echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" /> '; echo 'in'; echo '<select name="searchby">'; echo '<option value="fname"'.$firstn.'>First Name</option>'; echo '<option value="lname"'.$lastn.'>Last Name</option>'; echo '<option value="details"'.$details.'>Details</option>'; echo '<option value="age"'.$age.'>Age</option>'; echo '<option value="location"'.$location.'>Location</option>'; echo '<option value="email"'.$email.'>Email</option>'; echo '</select> '; echo '<input type="submit" value="Search" />'; echo '</form>'; } // Create the navigation switch $cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : ''); switch($cmd) { default: echo '<h1>Search Database!</h1>'; searchForm(); break; case "search": searchForm(); echo '<h3>Search Results:</h3><br />'; $searchstring = mysql_escape_string($_GET['words']); $sql = "SELECT * FROM users WHERE {$searchby} LIKE '%{$searchstring}%'"; // echo $sql; $result = mysql_query($sql) or die ($sql.'<br /><hr /><br />'.mysql_error()); while($myrow = mysql_fetch_object($result)) { echo '<hr size="1" />'; echo '<table align="center" cellspacing="0" cellpadding="5">'; echo'<td><span>' .$myrow['fname'] .'</td><td>'. $myrow['lname'] .' </td><td>'. $myrow['email'] .'</td><td>'. $myrow['location'] .' </span></td>'; echo '</tr>'; echo '</table>'; } break; } ?> </body> </html> That should stick with your original switch command although I'm not sure why you used that and get rid of the empty query. I hope it's right anyway
-
Php / mysql search problem
the is_numeric was a way to automate the search without the drop. like if it's a number then you search age not first name. I'm not sure what your problem is. can you describe it better or supply a url/screen shot?
-
any advice would be grately recieved
Thanks that was just the ticket.
-
any advice would be grately recieved
ok just for you I've set it up so the doc type changes to xhtml1.0 if it's sending it as text. :-) having huge problems trying to get the float center to work if anyone could help?
-
Php / mysql search problem
you might only be searching for half an email so no @ but something is needed to split it up. searching every when it's not needed is extreme
-
any advice would be grately recieved
Well I'm not writing off IE just because microsoft are idiots and can't be bothered to support xhtml. Nore am I going to stop using xhtml just because IE says so. As such I'm going to keep using my method however I will use content negotiation
-
Php / mysql search problem
no you'll have to do them one at a time like this $sql = "SELECT * FROM users WHERE fname LIKE '%{$searchstring}%' OR lname LIKE '%{$searchstring}%' OR details LIKE '%{$searchstring}%' OR age LIKE '%{$searchstring}%' OR location LIKE '%{$searchstring}%' OR email LIKE '%{$searchstring}%'"; Still that seems pretty big. Does the search really have to go through it all? It could be better to have a drop down menu of fields so the person can focus the search
-
any advice would be grately recieved
maybe it's the difference between coders and designers? I did put an image on the homepage but I don't think it's to bad now. It's not as embarassing as it used to me anyway
-
I want! This is so great!
I love lego and that just rocks
-
how sexy is this site
I love that site. it's really well put together. oddly I dont like the site of the people that made it
-
any advice would be grately recieved
turning my website into a giant picture isn't going to happen. I think the look of yours but I don't do lots images for many reasons.
-
any advice would be grately recieved
you're using IE yeh? I'm only asking because I have this code in my page if (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) $type = 'text/html'; else $type = 'application/xhtml+xml'; header("Content-type: {$type}"); It only gets sent as text to IE7 because IE7 will not render the correct type
-
I want an IP address not a domain name
sorry missed it
-
any advice would be grately recieved
Sorted the jumping buttons but I can't figure out those white lines in firefox. anyone got any ideas?
-
any advice would be grately recieved
I know it's plain but that's just the way I end up designing. It's not my strongest point. Basically the site will be for the overall thing but I'm planning on getting a designer on board but until then I'm stuck with just me :-) I am working on a logo but that's going to take me forever :-) You should have seen it before though. No shadow on the box more the chess picture. Thanks for pointing out the white lines. They are it seems a FF issue since it doesn't appear on opera either but I didn't notice them in testing so I'll have to track them down. I did plan on centring it all but I couldn't get float left and margin auto to work so I manually centred it for my resolution of 1024 x 768 but if you know how to get the floating centre to work that'd be great.
-
Php / mysql search problem
have you thought about using the mysql like command? say you are looking for a field in the database that contains the word FINDME you would use this sql $word = 'FINDME'; $sql = "SELECT * FROM mytable WHERE myfield LIKE '%{$word}%'"; Sure you can fit that into your code. see if it works better than match
-
any advice would be grately recieved
I'm a developer and hate design but I decided to remake my site so any feedback would be gratefully recieved http://www.neverg.co.uk/index.php
-
I want an IP address not a domain name
but penguin if it's a shared hoster that won't work because the virtual host on apache wont know which website to load. As mentioned he needs a static ip address. I'm sure fasthost will sell you one. I've got a static ip but that was for my ssl
-
Google Browser Sync
it's still on your machine anyway so it's just an extra risk. Anyway I fear we've hijacked the thread