The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database search filter
#21
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>
  Reply
#22
Unfortunately theory and practice are two very different things.
Now its not giving any results at all any more.

Wow this is complicated stuff!
  Reply
#23
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.
  Reply
#24
Thanks Sabr. I'm very grateful!
  Reply
#25
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
prints out correctly with the following:
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:
"
to
Code:
'
for ease of reading, either works.

I hope this solves it for you. If not then i will need to test with the sql query and results filter.
  Reply
#26
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) {
  [0]=>
  object(stdClass)#7 (1) {
    ["id"]=>
    string(1) "1"
  }
  [1]=>
  object(stdClass)#9 (1) {
    ["id"]=>
    string(2) "63"
  }
  [2]=>
  object(stdClass)#10 (1) {
    ["id"]=>
    string(2) "88"
  }
}
</pre>


This looks like it is finding stuff (profile Id's 1, 63 and 88) but its just not displaying it.
  Reply
#27
can you try with replacing
Code:
$m
with
Code:
$found->id
in the previous echo statement I sent you.

I am not sure if that will fix it or not but I think it is worth a try.
  Reply
#28
YES!!!!! That worked! You're a genius!
Very very cool Smile

Thank you so much Sabr! Smile
  Reply
#29
I am glad it is working, you are welcome Smile
  Reply
#30
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.

  Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)