The following warnings occurred: | ||||||||||||||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Database search filter - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29) +--- Thread: Database search filter (/showthread.php?tid=424) |
Database search filter - sabr - 01-19-2017 Yes the mix of quotes is an annoying issue which I keep forgetting about.... Theoretically this should work: Code: echo '<a href="profile.php?id="'.$m.">".$found->fname." ".$found->lname."</a><br>"; Placing single quotes around the first section should solve it. So breaking it down it should return as: Code: <a href="profile.php?id=" Code: 3 Code: > Code: example user Code: </a><br> Database search filter - LBC - 01-19-2017 Unfortunately theory and practice are two very different things. Now its not giving any results at all any more. Wow this is complicated stuff! Database search filter - sabr - 01-19-2017 Ok I will stop trying to be a smarty pants and will do some testing when I can, either lunch or this evening, unless someone else jumps in to save the day. Database search filter - LBC - 01-19-2017 Thanks Sabr. I'm very grateful! Database search filter - sabr - 01-19-2017 I realised during my test i was arranging the $m incorrectly in the string. So trying out a simple test by manually setting Code: $m Code: $fname Code: lname Code: echo '<a href="profile.php?id='.$m.'"'.'>'.$fname.' '.$lname.'</a><br>'; for your use it should be: Code: echo '<a href="profile.php?id='.$m.'"'.'>'.$found->fname.' '.$found->lname.'</a><br>'; breaking down into its sections helps when trying to work out concatenations: Code: '<a href="profile.php?id=' Code: . Code: $m Code: . Code: '"' Code: . Code: '>' Code: . Code: $found->fname Code: . Code: ' ' Code: . Code: $found->lname Code: . Code: '</a></br>'; I have changed the quotes from Code: " Code: ' I hope this solves it for you. If not then i will need to test with the sql query and results filter. Database search filter - LBC - 01-20-2017 Nope, no dice I'm afraid. It is not giving any results. However...I have dumped the ($matches); and that is showing me this: <pre> Code: array(3) { This looks like it is finding stuff (profile Id's 1, 63 and 88) but its just not displaying it. Database search filter - sabr - 01-20-2017 can you try with replacing Code: $m Code: $found->id I am not sure if that will fix it or not but I think it is worth a try. Database search filter - LBC - 01-20-2017 YES!!!!! That worked! You're a genius! Very very cool Thank you so much Sabr! Database search filter - sabr - 01-20-2017 I am glad it is working, you are welcome Database search filter - mudmin - 01-20-2017 My internet was down (I live in Rural Alaska, so that can be a pain). Just to add a few things into the mix. A lot of times I end my variables with Q, R, or C for Query, Results, and Count. Sometimes I don't do the R one and give it a better name. It's kind of nice to have $findUsersQ - the query $findUsersC - the number of users found and $foundUsers or $findUsersR - The results. It's your code...obviously just have fun with it, but the consistent urls make life easier. Another thing that makes life easier is if you have a column named "total", make your variable total, your form input name total, your form input id total. EVERYTHING. give it one name. I've learned my lesson on that. Then total=total=total=total and you don't have to keep going to the db to figure out what's wrong. A few more db things. You can string those things together if you want. So you can do Code: $findUser = $db->query("SELECT * FROM users WHERE fname = ?",array('bob'))->results(); BUT the one thing I always want to think about is what happens if the db returns either zero results (because something is broken) or more results than I would expect. That's where you want to wrap things in the Code: if($findUserC > 0){ Code: //do stuff here Code: }else{ Code: //Display some message. It doesn't seem that important until you have a bug or you are designing something like a support ticket system and you delete your old tickets. You always want something other than an error to happen if you get no results found. |