How to retrieve all the values of a single column using mysql?


I’m trying to retrieve all the timings for the film show. So for a single film there will be different timings at which the film will be projected.

So if a user searches a film name it should retrieve all the film projection timings for ex:
3:00 PM, 6:30PM.

I’m trying to do this but I’m getting a single column. If I use for loop for this problem it is showing the same timings again and again.

See the image below so you can get the better understanding of what Im trying to ask.

Here :

Search Query → ABCD

Search Results :
Film Name : ABCD
Director : No
Timing : 4:00

As, you can see there are different timings for the same film, I want to retrieve all the timings of the ABCD film, how can I do this?

I’m using PHP, MySQL

What query have you already tried?
Something like this should work:-

SELECT timing FROM table WHERE film_name = 'ABCD'

I have used this:

SELECT * FROM film_table Where '$search_input' = film_name;

And I’ve also used, following functions,


I want to retrieve all the timing for the user typed input. It is like a search engine which will search film timings in specific theatre.

Everything is working fine, but it is returning only one film timing I want to retrieve all the film timing. :slight_smile:


SELECT * will get all columns of the table. If you specifically just want the timing, that is overkill.

'$search_input' = film_name

Usually this will be the other way around, WHERE film_name = '$search_input'
To be honest, I don’t know if it should of should not work the other way, I never tried it. but conventionally you would place the column name first, before the value.


These functions have been removed from php and should no longer be in use. You should be using mysqli or pdo to communicate with your database.

The query should get all rows with the given film name, so the problem may be in how you are extracting the data produced by the query. Do you have the code for that?

Code :

$query = " SELECT * from bus_timings WHERE '$from_addr' = bus_starting_point AND '$to_addr' = bus_ending_point LIMIT 2 ";
	$run = mysql_query($query);
	$count_row = mysql_num_rows($run);
	if($count_row == 0) {
		echo "<br> No Results Found. <br>";
	} else {
		while($fetch_q_02 = mysql_fetch_assoc($run_q02)) {
			$fname = $fetch_q_02['film_name'];
			$ting = $fetch_q_02['timing'];
			$dir = $fetch_q_02['director'];

        echo "$fname";
        echo "$ting";
        echo "$dir";

Yeah, it is not selecting all the row values, it is selecting only one. Why it is happening like that? Is it because I’m using older version of MySQL? OR anything else?

Because in the while loop, you are overwriting the same variables over and over again, so in the end you only have results from the last row.
To see all results, you need to echo them out from within the loop, or create an array to iterate over later.

Mysql will still work in older versions of php. But there is no good reason to continue writing new scripts using it.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.