Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,161,494 members, 7,847,031 topics. Date: Saturday, 01 June 2024 at 09:43 AM

Multiple Queries - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Multiple Queries (866 Views)

My First Html/css Project After Learning Responsiveness(media Queries) / Predicting Search Queries Before Demand Arrives / Database Normalization And Complex Queries Tutorial (2) (3) (4)

(1) (Reply) (Go Down)

Multiple Queries by skyhighweb(m): 4:59pm On Sep 03, 2018
hi need i idea how to run this to display i think am suppose to use sub query so i want to do this

example as follow on page refresh i want different values to display with same id something like this

categoryid name title
212 rap making it
212 rap falling hard
212 rap kill it
212 rap gone wide

on another refresh

200 blues under you
200 blues loving
200 blues moving
200 blues mine world


on another refresh

312 rock lazy
312 rock nice
312 rock stoned
312 rock my world


it b multiple subquery
d subquery will b in rand order limit of 3 to 4

i idea will b appreciated thanks
Re: Multiple Queries by abula112(m): 8:28am On Sep 04, 2018
Randomize category on every refresh.... For example if u have category id between 1 and 300, using php , $cat = rand(1,300).
Then ur query will be SELECT * FROM table_name where category_id = $cat limit 4 . Hope u get the logic
Re: Multiple Queries by Kamxin(m): 10:01pm On Sep 04, 2018
skyhighweb:
hi need i idea how to run this to display i think am suppose to use sun

it b multiple subquery
d subquery will b in rand order limit of 3 to 4

i idea will b appreciated thanks

First, the table must be in first normal form. ie there must be a title_id like category_id, and two tables for category and title with those ids as primary key
Second, use a 'for loop' to generate a random number which would start from first category id and end in array.length minus one. Then set the value of the random number to category_id.

Third, create an empty arrray or arrayList.
Then query the database to get the total number of title_id where category_id is equal to the the one generated above
Then use a 'for loop' to generate 4 random numbers that is less than the total number of title_id and and add each random number generated on each iteration to the empty array you created earlier which will be the title_ id we will use later.

fourth, you have category_id and title_id now.
Then use a 'for loop' to do a select on the db for the array of titles you have. You can put the result in a Html list.
So query the db by selecting the category_id and name from category table where category_id is the one you have already.
Then select title from the array of title_ids you have from title table where category_id equals the one hou have.

NB: If you want new category each time different from the last refresh then you have to use Cookie to set the result for each load and make it different next time.

(1) (Reply)

IBM To Acquire Red Hat In A $34B Deal / Graphics Designer Is Needed! / Affordable Laptops For Sale

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.