Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,433 members, 7,819,560 topics. Date: Monday, 06 May 2024 at 06:14 PM

I Need Help With Php And Mysql - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / I Need Help With Php And Mysql (736 Views)

Android Quiz Application With Json Parser, Php And Mysql Database / Why Do Seun Dont Like Php And Mysql Programmers (2) (3) (4)

(1) (Reply) (Go Down)

I Need Help With Php And Mysql by macwilcy1: 12:06am On Apr 18, 2013
Hello, please I need help on how to use variables when using the IN of mysql. I.e "SELECT * FROM table_name WHERE username IN ('$username') ORDER BY DATE". Please is it possible to write it that way or is there a right way of writing that. Thanks for your help
Re: I Need Help With Php And Mysql by spikesC(m): 7:24am On Apr 18, 2013
Yeah, that's the perfect way. IN ('$username', $integer, ?)
wink

1 Like

Re: I Need Help With Php And Mysql by adexsimply(m): 11:46am On Apr 18, 2013
mysql_query("SELECT * FROM table_name WHERE username = '$username'"wink
... wink wink

1 Like

Re: I Need Help With Php And Mysql by macwilcy1: 1:23am On Apr 19, 2013
Thanks for the assistance. I forgot to mention that the variable $username is coming from database holding an array of values separated by comma (,). For instance $username = "macwilcy,cy,cyril,cy1,macwilcy1,...";. I want to use the username to fetch post made by users ordering it by date. I initially used "SELECT * FROM table_name WHERE username = '$username' ORDER BY DATE" but it was fetching the posts starting from the first username to the last username regardless of which user's post is the latest post. I will very much appreciate your help. Thanks
Re: I Need Help With Php And Mysql by spikesC(m): 2:23am On Apr 19, 2013
//if $username = "macwilcy,cy,cyril,cy1,macwilcy1,...";
//Do this first

$username = str_replace(",", "','", $username);

//Therefore, $username is now = "macwilcy','cy','cyril','cy1','macwilcy1,...";


//Then, SQL Query
SELECT * FROM table_name WHERE username IN ('$username') ORDER BY date_posted DESC

#Happy Coding cool

1 Like

(1) (Reply)

Advantages Of Scripting Language / Intel Realsense App Challenge 2014 / Please Can A Novice In Computer Go For Programming Or Networking

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