1

When this code loads i want it to select everything and show it, and then be able to change the results with Ajax by altering the column row variable $data.

So how do i load column bbookschool with a wildcard and change it later?

$data = '_';
$Result = mysql_query("SELECT * FROM ads WHERE bbookschool = '$data' ORDER BY time desc    limit 15")

i want to put a select list for values to be chosen which will be $data

Thanks

m59
  • 42,346
  • 14
  • 112
  • 132
Relm
  • 7,156
  • 17
  • 61
  • 106
  • What do you mean by *"...and change it later?"* ? Do you mean dynamically? Give us an example. – Funk Forty Niner Dec 14 '13 at 16:01
  • what do you mean by column row? – Ronny K Dec 14 '13 at 16:01
  • 1
    Please do not use the `mysql_*` functions anymore. They are deprecated and vulnerable to injection. See http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/14110189#14110189 for more information. – chill0r Dec 14 '13 at 16:01
  • @Fred-ii-, yes, i want to put a select list for values to be chosen which will be $data – Relm Dec 14 '13 at 16:03
  • Then I suggest you Google `"search dropdown select mysql php"` there are many questions/answers/examples that I found (just now when using those keywords) that will lead you back here on SO. One of which being [**this one**](http://stackoverflow.com/q/12254915/1415724) – I don't have actual examples in my libraries to show you, but that will get you started. – Funk Forty Niner Dec 14 '13 at 16:06

2 Answers2

1

You might want to look at the LIKE operator:

SELECT foo FROM bar WHERE baz LIKE '%part-of-baz%'

Using LIKE and updating you $data should do the trick

Eugen Rieck
  • 62,299
  • 10
  • 67
  • 91
0

You can use an or condition. When $data is the empty string, then the query will select everything:

SELECT *
FROM ads
WHERE bbookschool = '$data' or '$data' = ''
ORDER BY time desc
limit 15;
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709