NameSilo

PHP help

SpaceshipSpaceship
Watch
Impact
13
Hi all,

Quite new to php and learning more and more each day. Ive now come across a situation i need help with.

I have a list of hyper links (single letters). What i want to happen is that when the user clicks his chosen letter (link) for it to query on the database showing only match's for the said letter.

So basically im guessing i somehow need to parse the URL link somehow so i can do this.

Thanks,
Darren :)
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Assuming that you are using MySQL:
PHP:
<?php
mysql_connect('username', 'password', 'server');
mysql_select_db('database');
$results = mysql_query('SELECT * FROM `table` WHERE `letter` = "'.$_GET['value'].'"')or die(mysql_error());
mysql_close();

$i = 0;
while($i < mysql_num_rows($result)){
     echo mysql_result($result, $i, 'field');
     $i++;
}
 
0
•••
Indeed im using mySQL. I'll see what i can do with that code :)

Thanks ever so much for the help!

Darren
 
0
•••
Although in essence what mikor has done is indeed correct, he has not validated the input and is just using it straight into the mysql query. Doing this is a quick way to get your application hacked.

Always validate something the user has supplied.
 
0
•••
filth@flexiwebhost said:
Although in essence what mikor has done is indeed correct, he has not validated the input and is just using it straight into the mysql query. Doing this is a quick way to get your application hacked.

Always validate something the user has supplied.

Thanks i guess il have to look up some validation aswell.
 
0
•••
And the querie used to acess that connection would be the following:


Link = page.php?letter=a


PHP:
<?php 
$value=$_GET[letter];

//MYSQL QUERIE HERE

?>
 
0
•••
now im really confused.

When i set the hyperlink value what shall i put?

Also does this code look ok for pulling the data on the page that will show the rest of the data?

PHP:
<?php

//Gets the database information to carry out SQL tasks
include ("includes/config.php");

//Includes functions for menu items
include ("includes/functions.php");


	//SQL query to gather data
	$sql = "SELECT * FROM `cprofile` WHERE `club` = "'.$_GET['value'].'";
	$result = mysql_query ($sql); 

	$i = 0;
		while($i < mysql_num_rows($result)){
			echo mysql_result($result, $i, 'field');
			
			data selection and display code would go here?
			
			$i++;
} 

?>

Thanks!
 
0
•••
Your query is messing up the rest of the code. You set the quotes up wrong.
PHP:
$sql = "SELECT * FROM `cprofile` WHERE `club` = '".$_GET['value']."'";
 
0
•••
Dan said:
Your query is messing up the rest of the code. You set the quotes up wrong.
PHP:
$sql = "SELECT * FROM `cprofile` WHERE `club` = '".$_GET['value']."'";

Havent actually tested this code yet so thanks for pointing it out so i can ajdust it.

Ive coded most of the other stuff i can do. Im only a newbie so learning everything i come across and need to create the site.

If anyone knows of any tutorials on the following subject also be grateful

- Splitting a page up so results are spread over a number of pages

Thanks to all!

Regards,
Darren
 
0
•••
0
•••
0
•••
---


Right ive just tried the following code:


PHP:
function teamlist() {

	//Get letter of the club to display the
	//relevant page
	$value=$_GET[letter]; 


	//SQL query to gather data including the id
	//to pull out the correct data
	$sql = "SELECT * FROM `cprofile` WHERE `club` = '".$_GET['value']."'";  
	$result = mysql_query ($sql); 


	//While there are more results fill
	//the following variables
	while ($row = mysql_fetch_array($result))
	{
		$clubinfo= $row["club"];

		//Display the information as needed on the page
	echo '<table>';
	echo '<tr>';
	echo '<td> '.$clubinfo.' </td>';
	echo '</tr>';
	echo '</table>';
	}
}

It dont seem to work im not sure if the URL is passing the letter correctly. To get to this page ive set the url on the page before as:

listclub.php?letter=A

Thanks again.
Darren
 
0
•••
dc1pop said:
listclub.php?letter=A

Make it listclub.php?A

And it will start working. Bcoz the value right now is coming as "letter=A"

And you are running the query with that value. While you only need to run it for "A"
 
0
•••
nick_mayhem said:
Make it listclub.php?A

And it will start working. Bcoz the value right now is coming as "letter=A"

And you are running the query with that value. While you only need to run it for "A"
How will it know what A is if it's just there and doesn't have a variable name?

Don't put that code inside of a function. Your MySQL connection is probably not being passed into it because functions are annoying like that.
 
0
•••
PHP:
<?php
echo "<a href="listclub.php?A">A</a><a href="listclub.php?B">B</a>";
?>



Below the code for listclub.php

PHP:
<?php

$pageid = $QUERY_STRING;
if ($QUERY_STRING == "")
{
$pageid = A;
}

echo "The passed variablee is $pageid";
//Now process the query here


?>


By default if nothing is passed it will take A
 
0
•••
nick_mayhem, both of those codes have errors and that doesn't change anything about his problem.

dc1pop, there's really no reason to have that inside of a function and that's what's messing it up. Your MySQL resource handle is outside of the function and never passed to it. Take a look at variable scope.
 
0
•••
Got it. Bcoz my PHP REGISTER GLOBALS = ON
 
0
•••
in your function you have:-

$value=$_GET[letter];

yet when you use it within the sql you are still using $_GET[letter], you should simply be using $value. Also as stated before ensure you validate the input, if you only expect it to be 1 letter ensure it is in fact only 1 letter.
 
0
•••
filth@flexiwebhost said:
in your function you have:-

$value=$_GET[letter];

yet when you use it within the sql you are still using $_GET[letter], you should simply be using $value. Also as stated before ensure you validate the input, if you only expect it to be 1 letter ensure it is in fact only 1 letter.

Thanks for all your help. As the site is only on my localhost i'll add all validation rules to it later so i can get the basic script up and running to see if ti all works ok.

Thanks again all!
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back