This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more hereX

Home > Discussion Forum

Discussion Forum

rbren90
Guest
Posts: n/a
PHP Help!

Hi,

I am currently making a system but I am slightly stuck - im a bit of a rookie at php developmet. Any help would be great!

Basically I am using PHP to pull information from a database based on url info - i.e GET function. So i want to pull information from the DB where group = 1 - easy enuff so far, with the URL saying group.php?group=1

but now i want it to pull from the DB where group = 1 AND 3, but i cant seem to get this to work, iv tried group.php?group=1,2 group.php?group=1&2 but none of this is working..

any help is greatly appreciated!
thanks
Ryan
Reply With Quote
richardh richardh is offline
Connector
Join Date: Nov 2006
Posts: 246
Hi Ryan.

My advice to you would be to read up on some beginner PHP tutorials or purchase a book on it. If you're running into problems at this stage, then things are only going to get worse (for you and your clients).

That said:-

script.php?groups[]=1&groups[]=2
Code:
<?php
$groups = $_GET['groups'];
var_dump($groups);
?>
Make sure you're using something like mysql_real_escape_string() on the user input.
Reply With Quote
bluecube bluecube is offline
Connector
Join Date: Sep 2006
Location: Birmingham
Posts: 622
Quote:
Originally posted by richardh

Make sure you're using something like mysql_real_escape_string() on the user input.
Spoil sport...
__________________
Nathan Roberts
Web Design Birmingham

Latest Projects - Loudmouth | Make Up Artist Of The Year


Contact - 0121 314 0390 | info (at) bluecubemedia.co.uk | Website Design Birmingham
Reply With Quote
RichardJohn RichardJohn is offline
Connector
Join Date: Nov 2006
Location: Bridgend
Posts: 694
Is this being used on a production site?
I wouldn't advise it... if you're running into problems with GET variables, there's likely to be exploits in the script.
Reply With Quote
richardh richardh is offline
Connector
Join Date: Nov 2006
Posts: 246
Quote:
Originally posted by bluecm
Spoil sport...
Haha :P
Reply With Quote
rbren90
Guest
Posts: n/a
Thanks a lot, thats perfect..

and yeh im using mysql_escape_string

i probably should have taken off the zinkdesign sig, im only really designing for clients not coding at the minute.. im only 17 and still learnin btw:
Quote:
If you're running into problems at this stage, then things are only going to get worse (for you and your clients).
!!

thanks for the advice

ryan
Reply With Quote
richardh richardh is offline
Connector
Join Date: Nov 2006
Posts: 246
Another option Ryan:-

script.php?groups=1,2,3
Code:
<?php
$groups = explode(",", $_GET['groups']);
var_dump($groups);
?>
Reply With Quote
rbren90
Guest
Posts: n/a
@RichardJohn

listen, enough with the givin off about my capabilities, its a personal project and i am aware of exploits etc. so thanks for the advice but theres really no need for the patronising

appreciate the help richardh
Reply With Quote
bluecube bluecube is offline
Connector
Join Date: Sep 2006
Location: Birmingham
Posts: 622
Quote:
Originally posted by rbren90
im only 17 and still learnin btw:
Not a problem, just stick at it, you could do with getting your hands on a good book though and working through it just to give you a foundation to build on.

Then there are several online resources you can use for further reference

i.e. - http://www.php.net

Hope this helps
__________________
Nathan Roberts
Web Design Birmingham

Latest Projects - Loudmouth | Make Up Artist Of The Year


Contact - 0121 314 0390 | info (at) bluecubemedia.co.uk | Website Design Birmingham
Reply With Quote
bluecube bluecube is offline
Connector
Join Date: Sep 2006
Location: Birmingham
Posts: 622
Quote:
Originally posted by rbren90
@RichardJohn

listen, enough with the givin off about my capabilities, its a personal project and i am aware of exploits etc. so thanks for the advice but theres really no need for the patronising

appreciate the help richardh
I dont think he was havin a go mate I think he was just trying to give some friendly advice

HTH

Nathan
__________________
Nathan Roberts
Web Design Birmingham

Latest Projects - Loudmouth | Make Up Artist Of The Year


Contact - 0121 314 0390 | info (at) bluecubemedia.co.uk | Website Design Birmingham
Reply With Quote
rbren90
Guest
Posts: n/a
thanks, iv been thinkin about investing in a book so i think ill have to have a look on amazon soon!

thats fair enuff, i kinda jst got annoyed over nuthin there lol

apologies, its just been a busy week

cheers again for all ur advice
ryan
Reply With Quote
RichardJohn RichardJohn is offline
Connector
Join Date: Nov 2006
Location: Bridgend
Posts: 694
I wasn't being patronising, I was just advising against using code on production sites whilst you're still learning!
Reply With Quote
rbren90
Guest
Posts: n/a
thats cool, apologies im jst a bit touchy lol. my age seems to make my credibility go wayy down a lot when im designing etc. so just a little edgy with it.. i didnt mean to snap lol

you're right tho, iv kinda jumped in the deep end, i need to start at the beginning

cheers
ryan
Reply With Quote
awebapart awebapart is offline
Connector
Join Date: Dec 2006
Location: Wellingborough, Northamptonshire, NN8 1NB
Posts: 194
Re: PHP Help!

Quote:
Originally posted by rbren90
i want it to pull from the DB where group = 1 AND 3
There are a number of ways of doing this but you might also need to read up on SQL or mySQL:

select *
from tablename
where groupid = 1

is OK

select *
from tablename
where groupid = 1 AND 3

is really saying

select *
from tablename
where groupid = 1
and 3

where 3 is a boolean expression which is always true (because it is non zero), so it is redundant. What you are really after is something ilke:

select *
from tablename
where groupid = 1
or groupid = 3

or maybe

select *
from tablename
where groupid in ( 1, 3 )
__________________
Paul, software developer.

Freebies: year planner (pdf), singer songwriter (album)
Reply With Quote
gnu gnu is offline
Connector
Join Date: Jun 2006
Posts: 227
Re: PHP Help!

Quote:
Originally posted by rbren90

but now i want it to pull from the DB where group = 1 AND 3, but i cant seem to get this to work, iv tried group.php?group=1,2 group.php?group=1&2 but none of this is working..

Ryan
If you are passing parameters in the URL you need:

group.php?group=1&group2=2&group3=3

If it is the database query you are struggling with then have a read of:

http://www.w3schools.com/sql/default.asp

Also, get a copy of phpMyAdmin installed on your host / or pc, with that you can execute queries directly in the database and get them working in SQL... then build the same statement in your code...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT +1. The time now is 07:37 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd. Copyright Shell LiveWIRE 2005-2009