Jump to content

Filter in php/mysql


omardavinci

Recommended Posts

At first i create the form very easy with php:

 

 

$content = '
<h4>Title 1</h4>
<form method="POST">
<table>
<tr>
<td><input id ="1" type="text" name="valueToSearch" placeholder="Value To Search"></td><br><br>
</tr>

<tr><td><input type="submit" name="search" value="Filter"></td></tr>
</form></table>

<br>
'
;

Obviously since if(isset[$_POST]) i did the query like this:

 

 

$query = "SELECT id FROM `user` WHERE CONCAT(`id`) LIKE '%".$valueToSearch."%'";

But in my case i want to update $articles ($articles are the articles ordered by pages), i mean this:

 

 

$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$perPage = 2;
//Positioning
$start = ($page > 1) ? ($page * $perPage) - $perPage : 0;
$art = $database_connection->query("SELECT id FROM user");
//Query
$articles = $database_connection->prepare("SELECT id FROM user LIMIT $start,$perPage");

$articles->execute();
$articles = $articles->fetchAll();

$resultado = $database_connection->query("SELECT COUNT(*) AS total FROM user");
$fila = $resultado->fetch(PDO::FETCH_ASSOC);
$total = $fila["total"];
$pages = ceil($total/$perPage);

In conclusion, my question is very short. how i can update $articles when someone use filter to filter the table. In other words, i am trying to search some way to update $articles and i am little lost. Thanks in advance.

Link to comment
Share on other sites

Here we go again.

 

Obviously since if(isset[$_POST]) i did the query like this:

What does this statement mean? Obviously what? If the $_POST was NOT set what query would you do then???

 

$query = "SELECT id FROM `user` WHERE CONCAT(`id`) LIKE '%".$valueToSearch."%'";

And this query - what ARE you concatenating here? Why the CONCAT?

 

$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;

Your form shows you doing a POST, yet now you are retrieving values form the $_GET array. How is that possible?

 

$art = $database_connection->query("SELECT id FROM user");

//Query

$articles = $database_connection->prepare("SELECT id FROM user LIMIT $start,$perPage");

$articles->execute();

And now you do two queries to select all of the id values. Why?

 

And finally you question us as to how to update 'articles' yet you aren't even attempting to do anything with 'articles' here. Nothing. And what are you talking about when you say "when someone use filter to filter the table"? Who is the 'someone' since it is your script and you decide what happens. And again - even you are not doing any filtering here.

 

I would almost say that we are struggling to understand your English. But then I look at your php and I have a hard time understanding what you think you are doing there.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.