Jump to content


PHP Help (Database Categories in URL)


10 replies to this topic

#1 ImPaKt

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 26 August 2006 - 12:17 PM

Hey there... been trawling through the main site looking in PHP for help on a site i'm building for a mate. The site is games mapping/skinning and i am up to the maps browsing page.

Ok... I have a database set up with 4 test map entries in it... 2 are from 1 category, 1 from another and the other is in another category. I want to have my nav go to say /maps.php?game=Unreal for unreal tournament maps and it will check the database's 'Game' row for all items with 'Unreal' and then display them on the page.

Then if I was to go to /maps.php?game=DOD it would shw me all Day of Defeat maps on the page instead.

I can attach my site dir and a databse setup .sql file if anybody would like that if they can help.

Thank you. :love:

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 26 August 2006 - 12:36 PM

function in_iarray($search, &$array) {
	$search = strtolower($search);
	foreach($array as $item)
		if(strtolower($item) == $search)
			return TRUE;
		return FALSE;
}

$categorys = array('dod', 'unreal');
if(isset($_GET['game']) && in_iarray($_GET['game'], $categorys)){

$result = mysql_query("SELECT * FROM `games` WHERE `category` RLIKE '$_GET[game]' ORDER BY `id` DESC") or die(mysql_error());

Basically just like that. You'd than have it echo all results of that the exact same way you'd echo your individual normal results.
It's safest to use an array of the possible games just so no-one tries to take advantage of it and tries to find a way into something they shouldn't.
The in_iarray() function is something I got off some random site I found. Basically just an incase-sensitive version of in_array().

Edited by Demonslay, 26 August 2006 - 12:36 PM.


#3 ImPaKt

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 26 August 2006 - 12:39 PM

Woah :o at first i cud hardly understand that bu yeah, i'll try and see what happens :love:

Erm... tells me i have a parse error on line 469... and that line is... "?>"

Also i get

"Parse error: parse error, expecting `T_WHILE' in c:\www\map\maps.php on line 435"

line 435 is:

<td height="12" colspan="2">Game: <?php echo $row_Maps['game']; } ?> Author: <?php echo $row_Maps['author']; ?></td>

Edited by ImPaKt, 26 August 2006 - 12:48 PM.


#4 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 26 August 2006 - 12:50 PM

You'll have to give us more of your code so we can actually see what the problem is.
Whenever you get an error, it may be on a line 50 lines up, and since it is an 'unexpect WHILE clause' that means there must be something goin' on with that.

#5 ImPaKt

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 26 August 2006 - 12:55 PM

Added Maps.php

The original scrip you gave me is lines 67 to 78 and my table layout is lines 421 to 444

and i added the .php before i added the script to where i was not getting parse errors. The title will show up like i want when you browse to each area but all the other data parts stay the same and all show up :love:

Attached Files


Edited by ImPaKt, 26 August 2006 - 01:20 PM.


#6 FelipeCtrz

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 26 August 2006 - 05:27 PM

View PostDemonslay, on Aug 26 2006, 02:36 PM, said:

function in_iarray($search, &$array) {
	$search = strtolower($search);
	foreach($array as $item)
		if(strtolower($item) == $search)
			return TRUE;
		return FALSE;
}

$categorys = array('dod', 'unreal');
if(isset($_GET['game']) && in_iarray($_GET['game'], $categorys)){

$result = mysql_query("SELECT * FROM `games` WHERE `category` RLIKE '$_GET[game]' ORDER BY `id` DESC") or die(mysql_error());

Basically just like that. You'd than have it echo all results of that the exact same way you'd echo your individual normal results.
It's safest to use an array of the possible games just so no-one tries to take advantage of it and tries to find a way into something they shouldn't.
The in_iarray() function is something I got off some random site I found. Basically just an incase-sensitive version of in_array().


Or use $_REQUEST


<?
$content = $_REQUEST['game'];

if($content == "dod"){

echo("D.O.D. Content");

}
?>

This is easier.

#7 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 26 August 2006 - 05:33 PM

Thing is, if you did it that way, he would need to pull completely new code for every category. With mine, it simply plugs it into the SQL and he can then echo it however he wants that way.

And I think you edited the file a bit, because all the rows that you said give an error are completly different from what you posted. :ph34r:

#8 FelipeCtrz

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 26 August 2006 - 05:40 PM

Oh, and btw, i think you made a typo. You wrote RLIKE, which is LIKE

#9 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 26 August 2006 - 05:58 PM

RLIKE also exists....dont know why you are using it....but still....

Demonslay, the whole new function thing you got going isnt really needed....why not just use strlower on $_GET['game'] and then use in_array?

This isnt the way i would do this at all but i wont barge in.

Edited by .Matt, 26 August 2006 - 05:58 PM.


#10 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 26 August 2006 - 06:14 PM

Meh, I made it a habit by accident, but you're right Matt. :D
Used to too many arrays where I don't have 100% control on the casing of.

And I use RLIKE because when I used LIKE in this same scenario I kept getting the dreaded 'SQL syntax error' and some crap about invalid arguants with my WHERE clauses. I then used REGEX and RLIKE and boom, it works. :ph34r:

#11 ImPaKt

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 26 August 2006 - 07:32 PM

meh... i'm using dreamweaver and it's done most of what you see on that page anyway. In the maps__before_.php file is how i got it to work showing the title of the game in the url only but the rest of the data won't follow suit :ph34r:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users