Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,194,378 members, 7,954,531 topics. Date: Friday, 20 September 2024 at 09:29 PM

Is This Possible To Do In PHP AND MYSQL - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Is This Possible To Do In PHP AND MYSQL (1551 Views)

PHP And Mysql: Absolute Beginner. / Closed - Out of date / Android Quiz App With Php And MYSQL Database (2) (3) (4)

(1) (Reply) (Go Down)

Is This Possible To Do In PHP AND MYSQL by teampregar(m): 6:29pm On Jun 13, 2016
$array = array("seun", "bob"wink;

for($array as $a)
$query = "SELECT * FROM dbtable WHERE name= $a";
$result = mysqli_query($link,$query);
//Then the rest
My question is, is it possible to query a table against an array in PHP and still get your result,
in the above example i want to get rows of data from seun and bob
Re: Is This Possible To Do In PHP AND MYSQL by chainsaw11: 7:26pm On Jun 13, 2016
Of course, it's very much possible.
Re: Is This Possible To Do In PHP AND MYSQL by teampregar(m): 9:00pm On Jun 13, 2016
chainsaw11:
Of course, it's very much possible.


Waht i want to do is , for example, seun , bob and others makes a post then i follow seun , bob and others on twitter,
how do i query the database to show me posts of pple i follow based on the time they posted
Re: Is This Possible To Do In PHP AND MYSQL by CodeHouse: 10:13pm On Jun 13, 2016
teampregar:
$array = array("seun", "bob"wink;

for($array as $a)
$query = "SELECT * FROM dbtable WHERE name= $a";
$result = mysqli_query($link,$query);
//Then the rest
My question is, is it possible to query a table against an array in PHP and still get your result,
in the above example i want to get rows of data from seun and bob

All you need to do is to explode the array, assuming your friends are stored in the table with a comma, exploding the array would generate a unique key starting from zero to the amount of friends in the table and also generate a value along side the unique key, the value is what you need, it contains the individual friends without a comma.. and that is what you need to run the other query... Note that youhave to sanitize, to avoid injection, what you have below should solve your problem...To get the post according to how they are posted, you can simply ORDER by post id

Re: Is This Possible To Do In PHP AND MYSQL by CodeHouse: 10:34pm On Jun 13, 2016
Note that your second query will be the post table not the user table, I assume that you have a table where all your post are submitted, then if I have 50 friends in my array, then $value will fetch each names and then the resulting names will be used to query the post table and then ORDER by post id in Descending order
Re: Is This Possible To Do In PHP AND MYSQL by teampregar(m): 10:43pm On Jun 13, 2016
CodeHouse:


All you need to do is to explode the array, assuming your friends are stored in the table with a comma, exploding the array would generate a unique key starting from zero to the amount of friends in the table and also generate a value along side the unique key, the value is what you need, it contains the individual friends without a comma.. and that is what you need to run the other query... Note that youhave to sanitize, to avoid injection, what you have below should solve your problem...To get the post according to how they are posted, you can simply ORDER by post id
Thanks Alot , i will try it if u have any difficulty i will let you know, nice IDE tho, i bet u use a MAC OS
Re: Is This Possible To Do In PHP AND MYSQL by CodeHouse: 11:11pm On Jun 13, 2016
teampregar:

Thanks Alot , i will try it if u have any difficulty i will let you know, nice IDE tho, i bet u use a MAC OS

No p
Re: Is This Possible To Do In PHP AND MYSQL by D34lw4p(m): 3:33am On Jun 14, 2016
For your programming related questions post them at:www.nct.com.ng related and get almost instant reply from real G33ks
Re: Is This Possible To Do In PHP AND MYSQL by teampregar(m): 7:03am On Jun 14, 2016
D34lw4p:
For your programming related questions post them at:www.nct.com.ng related and get almost instant reply from real G33ks
wat does nct mean
Re: Is This Possible To Do In PHP AND MYSQL by teampregar(m): 7:21am On Jun 14, 2016
CodeHouse:


All you need to do is to explode the array, assuming your friends are stored in the table with a comma, exploding the array would generate a unique key starting from zero to the amount of friends in the table and also generate a value along side the unique key, the value is what you need, it contains the individual friends without a comma.. and that is what you need to run the other query... Note that youhave to sanitize, to avoid injection, what you have below should solve your problem...To get the post according to how they are posted, you can simply ORDER by post id
When did you declare the variable $user and why are you comparing its value with $value variable
Re: Is This Possible To Do In PHP AND MYSQL by guru01(m): 8:07am On Jun 14, 2016
teampregar:

Waht i want to do is , for example, seun , bob and others makes a post then i follow seun , bob and others on twitter,
how do i query the database to show me posts of pple i follow based on the time they posted
You already said it.
All you need is 2 tables, 1 for post which has the time post was made (columt), the other is the follow table which will hold info for the post_id, user_id, then time.
So when you select you have to join user table with post table to retrieve users info who made the post and may be the one who also follow the post.

Note: my logic might not be 100% accurate, but it will help you understand how it can be achieve.
Re: Is This Possible To Do In PHP AND MYSQL by CodeHouse: 12:03pm On Jun 14, 2016
teampregar:

When did you declare the variable $user and why are you comparing its value with $value variable

It is very easy, firstly you can take off the condition where I compared the user variable to the value variable, usually when I create social forums, during registration, users are also placed in the friend list for a special reason, all depends on the coder and the aim and that is the reason I searched in the value variable to make sure the post of the logged in user does not appear twice cos I already assumed the user already posted and his or her post has been fetched and displayed?

The code i sent to you is to fetch all the posts made by a user and displayed to all followers or those in the friend list whenever they are logged in.

The user variable is the session variable for logged in user, so the second mysql code is supposed to fetch each posts of those in my friend list via the value variable as they are fetched.

Note the second mysql query should be SELECT * users post table not the users table as indicated in the first mysql query. The reason for this method is that it helps you manipulate database record in relation to users and those in their friend list, with the above, you can fetch Likes, Shares, Comments, Views, etc
Re: Is This Possible To Do In PHP AND MYSQL by D34lw4p(m): 8:04pm On Jun 14, 2016
teampregar:
wat does nct mean
it means Nigeria Coders Team

(1) (Reply)

Working On My Own Game / Urgent!!!!! Startup Company In Need Of an APP DEVELOPER For Ios And Android / What Can I Build With Python And Php?

(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. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.