Search Form has seperate search options, but not the option "All"

I’m using a pre-made PHP script where you can upload then search for videos and images.
How can I add the search option “All” to this Form (and search.php?) so that a keyword/tag can result in a list of all (both video and images) that have that searched keyword?

Here is the Form in its current state (without the All option):

     <form method="get" action="search.php" autocomplete="off" name="form_search">

        <select size="1" name="type" />
        <option value="videos">[var.lang_word_videos]</option>
        <option value="images">[var.lang_word_images]<!--[onload;block=option;when [var.enable_images]=1;comm]--></option>
    	</select>

    	<input autocomplete="off" id="keyword" name="keyword" value="Search [var.site_name]" onclick="clickclear(this, 'Search [var.site_name]')" onblur="clickrecall(this,'Search [var.site_name]')" />
    	<input type="submit" value="Search" />
      </form>

Any guidance/feedback/help will be appreciated.

depends on how the search mechanism is implemented.

Yes, you’d need to post the search.php code to be able to see exactly how that works.

Thank you for your replies.
I’m attaching the Search.php file.
Any additional help will be appreciated.

SearchPHP.txt (12.4 KB)

so you have to ajust at least a few parts, like adding support for switch ( $get_type ) { and generate an SQL with UNION over all tables within something like if ( $query_get_type == 'all' ) { ... SQL UNION ...

Thanks for your reply.
I was also told this:
"The search query is only done on one table at a time and you have both a videos and an images table in the DB. The search.php looks for the type and creates an array based on that table.

Now, if the tables had the exact same layout, then you could use a UNION clause in the query to add them both up. But the tables have different columns, so UNION won’t work. Now, the template only takes one array at a time, so even if you could pull this off, you’d need to tweak the template to have the two results independently. With the current script you’re using, I cannot see a way to get this done."

So, my question is, with this script there is image_uploader.php and (video) uploader.php.
Wouldn’t it be possible, for example, to simply direct the Image Upload Form to a modified uploader.php that accepts .png instead of mp4 uploads? Also, Or modify search.php where a user can choose which channel he wants to upload the video to, maybe images could be uploaded to a channel in the video table and then users can search by channel, or all channels.

I look forward to any feedback. Thanks

If you want to modify the layout, you could just use a single table for all the uploads, store a “type” field to denote what the upload was, and standardise the rest. Then you could search on all, or just videos, or videos and images but not documents, and so on. Using separate tables seems to cause as many problems as it solves, to me.

Thanks for your reply. Much appreciated.
Based on your suggestion, I see that in videos table there’s a ‘video_id’ column, and in images table there is an ‘image_id’ column. Maybe adding an ‘image_id’ column into the videos table, and then modify the search to look for the uploaded image there? I’m attaching the image_uploader.php file. Any guidance with how-to/where-to try to change it so the uploaded image is stored in videos table > image_id column, would be appreciated. Thanks again

image_uploader.php (21.1 KB)

It’s a bit of a slippery slope to have a table called videos, but to start storing stuff that isn’t videos in it. Makes for a confusing database layout.

I get what your’re saying, but I’m trying to do it for test purposes, initially.
Any help will be appreciated.

They’re different types of file - MP4 is video, PNG is image

Of course I know that, I’m just trying to get some help with a creative solution

If you want both in the same table in the database then redesign the table properly so that the fields in the table make sense for both.

Would an additional table, that is not just for images, and not just for videos be a solution?

A single table with all the data that both the types have in common and a type field would be what I would use as a starting point. You only need extra tables if there is then additional data that only exists for one type and not the other.

Thanks for your reply.
There’s a good size list of all data that the images table and video table have in common. The shorter list is what they don’t each have:
Images: image_id, gallery_id, image_size
Videos: video_id, type, response_id, channel_id, sub_channel_id, channel, video_length

Are you saying I should leave those out of the “single table”?
I look forward to any guidance/clarification.
Thanks again

if you can let out the differing colums you can union with aliases like

My guess would be that image_id and video_id are the unique IDs for the row, so they would effectively be the same field in a merged table. You could do as @chorn said and UNION into another table to get the other information, which I think would be a proper normalised database, or you could simply add all those columns into your single table, prefix them to make it clear which they apply to (channel_id becomes video_channel_id and so on) and then while displaying the results, use whichever are necessary depending on the file type you are presenting. And add a column to denote Image or Video. You can still search only images, only videos, or both, or add other types in as desired.

Remember that while it solves your search issue, it would mean altering everything else in the site to use the common table rather than individual ones.

Thanks for all the replies. I don’t know how to do what chorn, suggested but am open to any help.
I went ahead and combined the videos table & images table into a table called videos-images.
Basically copied videos table over, then added: image_id, gallery_id, image_size, gallery_name, media_location and media_quality columns from the images table (because all the rest of the tables are the same as videos table). Of course, there’s no data there yet. So, any additional help/guidance will be appreciated. Maybe add something to image_uploader?

image_uploader.php (21.1 KB)

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