Help with a script

Reply

Join Date: Feb 2004
Posts: 11
Reputation: fred999 is an unknown quantity at this point 
Solved Threads: 0
fred999 fred999 is offline Offline
Newbie Poster

Help with a script

 
0
  #1
Mar 1st, 2004
Hi all, i need help for a little php script, here is what i need:

I have a table named "clans" with 4 field in it (name, url, logo, description)
I have a php page with "A-B-C-D-E-F-G-H-I-........."
I need to create the links on the letters that will only show all clans that begins with the clicked letter

I just dont have a damn idea on how to do this, i am sure that the php gurus out there can help me with something simple, i only code for fun and im still newb. Thanks in advance

fred
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 282
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Solved Threads: 6
Team Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: Help with a script

 
0
  #2
Mar 1st, 2004
Do u mean a mysql table?

Try something like this


Letters:
<a href="<?php echo $PHP_SELF; ?>?letter=a">A</a>
<a href="<?php echo $PHP_SELF; ?>?letter=b">B</a>
<a href="<?php echo $PHP_SELF; ?>?letter=c">C</a>
...
<a href="<?php echo $PHP_SELF; ?>?letter=z">Z</a> <br /><br />

[php]
<?php

// Connect to DB... blah blah blah

$db_host = 'localhost'; // Probably OK
$db_user = 'Bob'; // Change to your MySQL Username
$db_pass = 'bar'; // Change to your MySQL Password
$db_name = 'database'; // Change to your MySQL Database name

$db_connect = mysql_connect($db_host, $db_user, $db_pass);
$db = mysql_select_db($db_name);

// END DB Connection


// Find the letter=whatever stuff in the URL and assign it to
// the $starting_letter variable
$starting_letter = $_GET['letter'];

// Create + execute SQL
$sql = "SELECT * FROM clans
WHERE LEFT(name, 1) = '$starting_letter'";

$result = mysql_query($sql);

// While there are results, keep looping...
while( $row = mysql_fetch_assoc($result) )
{
// Echo the results...
echo 'Clan: <a href="' . $row['url'] . '">' . $row['name'] . '</a><br />';
echo '<img src="' . $row['logo'] . '" /><br />';
echo $row['description'] . '<br /><br />';
}

// End
?>
[/php]
Reply With Quote Quick reply to this message  
Join Date: Feb 2004
Posts: 11
Reputation: fred999 is an unknown quantity at this point 
Solved Threads: 0
fred999 fred999 is offline Offline
Newbie Poster

Re: Help with a script

 
0
  #3
Mar 1st, 2004
Roberdin ! thanks alot !!

This code did everything i wanted thank you!

fred
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 282
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Solved Threads: 6
Team Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: Help with a script

 
0
  #4
Mar 5th, 2004
No probs.

Actually that isn't too secure - you may wish to change

$starting_letter = $_GET['letter'];

to

$starting_letter = addslashes($_GET['letter']);
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 1,135
Reputation: samaru is just really nice samaru is just really nice samaru is just really nice samaru is just really nice 
Solved Threads: 6
Team Colleague
samaru's Avatar
samaru samaru is offline Offline
a.k.a inscissor

Re: Help with a script

 
0
  #5
Mar 6th, 2004
I have a function I use when I'm inserting snippets of code into a MySQL database:

  1. function mysql_safe_data($string) {
  2. $string = stripslashes($string);
  3. $string = str_replace("'", "''", $string);
  4. $string = str_replace("\\", "<a rel="nofollow" class="t" href="http://\\\" target="_blank">\\\\</a>", $string);
  5. return $string;
  6. }

If you don't replace \\ with \\\\ you're going to have problems with slashes when you insert them into MySQL. Just try inserting this code that highlights text into MySQL through an HTML form and see what I mean.

  1. function highlight($string, $words_to_highlight, $delimiter=" ", $case=0,
  2. $left_string="<b span style=\"background-color: yellow;\">", $right_string="</b>") {
  3. // This is so it highlights the first word. Each word in a textblock must be surrounded by
  4. // [^A-Za-z] in order to highlight whole words, and not subwords.
  5. /* Filtering Process:
  6. Replace statements take out all malicious chars that would break the
  7. search part of a regular expression. Takes unwanted chars and only lets the chars:
  8. [^-a-zA-Z0-9&] in. */
  9. $list_of_words = eregi_replace("[^-a-zA-Z0-9&']", " ", $words_to_highlight);
  10. // This portion of code is to take out single word characters.
  11. $list_array = explode(" ", $list_of_words);
  12. for($i=0; $i<sizeof($list_array); $i++)
  13. if(strlen($list_array[$i]) == 1)
  14. $list_array[$i] = "";
  15. $list_of_words = implode(" ", $list_array); // Use space as delimiter
  16. $list_of_words = eregi_replace(" +", "|", $list_of_words);
  17. // Make sure there aren't any pipes | around $list_of_words
  18. if($list_of_words{0}=="|")
  19. $list_of_words{0} = "";
  20. if($list_of_words{strlen($list_of_words)-1}=="|")
  21. $list_of_words{strlen($list_of_words)-1}="";
  22. $list_of_words = "(".trim($list_of_words).")";
  23. if($case==0)
  24. return eregi_replace("$list_of_words", "$left_string"."<a rel="nofollow" class="t" href="file://1%22.%22$right_string/" target="_blank">\\1"."$right_string</a>", $string);
  25. else
  26. return ereg_replace("$list_of_words", "$left_string"."<a rel="nofollow" class="t" href="file://1%22.%22$right_string/" target="_blank">\\1"."$right_string</a>", $string);
  27. } // end function highlight
Check out my blog at http://www.shinylight.com for more stuff about web dev.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 282
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Solved Threads: 6
Team Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: Help with a script

 
0
  #6
Mar 8th, 2004
...what's wrong with addslashes()? It add slashes to already existing slashes
Reply With Quote Quick reply to this message  
Join Date: Feb 2004
Posts: 11
Reputation: fred999 is an unknown quantity at this point 
Solved Threads: 0
fred999 fred999 is offline Offline
Newbie Poster

Re: Help with a script

 
0
  #7
Mar 9th, 2004
thanks alot guys! i really appreciate!

if you want to see the result go there: http://www.battlefield-vietnam.ca/clans.php



fred
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 3398 | Replies: 6
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC