简体   繁体   中英

how to sql query without changing the value in the query?

So i know the question sounds weird but I did not know how to describe it. Let me show you.

I have a page index.php that has an:

<a ref="videos/vid.php?id=' . $tag["video_tag"] .'">

that $tag["video_tag"] in my DB is a category and assigned a value lets say 3

Now on my other page videos.php is loaded when someone clicks that a href. At this point my query pulls the correct videos by matching that category value of 3 to the videos.video_tag_id (which should do that) BUT!! it changes the id of the video. That is what is happening with this query because I inspect element and view the id=3 on all the videos.

This query is pulling the right videos but then changing the actual id on the videos when they are listed on the page

Kind of like if netflix matched "show-1 " to six other "show2-6" but you cant load the "shows2-6" because the unique id's are all the same. The query is changing that and I do not know how to fix it.

$sql = 'SELECT * FROM videos,category WHERE videos.video_tag_id = category.video_tag AND videos.video_tag_id = ' . $categoryId . ' ORDER BY RAND() LIMIT 6';

Thank you

Share your table structure. I think, In your query, id field of category table and videos table is ambiguous. Try to alias your field names.

$sql = "SELECT v.*,c.*,v.id as video_id FROM videos v left join category c ON v.video_tag_id = c.video_tag where v.video_tag_id = " . $categoryId . " ORDER BY RAND() LIMIT 6";

Try this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM