Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-02-2011, 09:29 AM A To Z Index...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Hi,

I have downloaded a to z index script from this site: http://www.tutorialized.com/view/tut...g-script/23912

I adjusted some code to make it work on my site, but it's just not working correctly.

See this page for the results: http://reunitemysite.com/getads.php

Simply put, all records are coming out of the database, and when you click on a letter where a record should be, there is none. What gives? Anyone?

Thanks again!
Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-02-2011, 11:40 AM Re: A To Z Index...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
And YOUR code is?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-02-2011, 08:01 PM Re: A To Z Index...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by chrishirst View Post
And YOUR code is?
Chris, here's the html / php code:

HTML Code:
<html>
<head>
<style media="screen" type="text/css">

#atoz {
background-color: #487666;
padding-left: auto;
padding-right: auto;
}

</style></head>
PHP Code:
 <?php

// DB Connect String

mysql_connect("localhost""user""pass");
mysql_select_db("database");

/* Get the letter user clicked on and assign it a variable called $sort */
$sort $_REQUEST['letter'];
 
/* Let's check if variable $sort is empty. If it is we will create a query to display all customers alphabetically ordered by last name. */

if($sort ""){
$qry"SELECT * FROM amp_ads ORDER BY title ASC " ;
}else{

/* if varible $sort is not empty we will create a query that sorts out the customers by their last name, and order the selected records ascendingly. */

$qry "SELECT * FROM amp_ads WHERE title LIKE '$sort%' ORDER BY title ASC" ;
}

/* Notice the use of '%' wilde card in the above query  "LIKE '$sort%'". */
 
//next step is to execute the query.
$execute mysql_query($qry) or die(mysql_error());
 
/* Before we display results let's create our alphabetical navigation. The easiest way to create the navigation is to use character codes and run them through the "for" loop. */

echo "
 
;
for (
$i 65$i 91$i++) {
    
printf('<a href="%s?letter=%s">%s</a> | ',
    
$PHP_SELFchr($i), chr($i));
}
echo 
"
 
;
 
/* now we are ready to display the results. Since out tbl_customers table has only three fileds we will display the results in a paragraphs. In the real world you may need to display the results in a table.
To display the results we will use "do while" loop to fetch the results. If no customers are found we will display an error message. */

if(mysql_num_rows($execute)>0){
do{
echo 
"
 
.$result['title']. "
 
;
}while(
$result mysql_fetch_assoc($execute));
}else{
echo 
"
 
No ads found.
 
;
}
?>
The problem is that when I run that php code (with database connection string set of course) I am getting this output: http://reunitemysite.com/getads.php

What the above url shows is the a to z index, then it also shows all the "titles" from the ads database. They (ad titles) are supposed to be displayed only when you click on the letter of the title ad you want to show. Also, if the letter you click on doesn't display any ads, it will show the text no ads found text, which doesn't show either. What gives? Any ideas? I'm confused

Thanks in advance!
Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 09-03-2011, 06:14 AM Re: A To Z Index...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
PHP Code:
if($sort ""
the php equality operator is '==', NOT '=' which is the assignment operaqtor
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-03-2011, 10:23 AM Re: A To Z Index...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by chrishirst View Post
PHP Code:
if($sort ""
the php equality operator is '==', NOT '=' which is the assignment operaqtor
Thanks again Chris! I don't know how you do it, you just do!
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 09-03-2011, 01:00 PM Re: A To Z Index...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
I would like to add the ability to search by 0-9 as well as a to z. Can someone help me get that?

Thank you!
Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 09-03-2011, 02:25 PM Re: A To Z Index...
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Just add another for loop after the "65-90" for values 48-57. Nothing else needs to change.

None of your records have titles beginning with a lower case or accented character, I trust.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 09-03-2011, 02:35 PM Re: A To Z Index...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
... WHERE column REGEXP '^[0-9].*' ....




http://dev.mysql.com/doc/refman/5.1/en/regexp.html
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-03-2011, 05:23 PM Re: A To Z Index...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by PaulW View Post
Just add another for loop after the "65-90" for values 48-57. Nothing else needs to change.
Thank you PaulW...I meant for something like 0-9 not like 0 1 2 3 4 5 6 7 8 9 though.

Quote:
None of your records have titles beginning with a lower case or accented character, I trust.
maybe...I really don't know if that would be the case as this is going into an a-z index and anything could be possible. I didn't know those would become issues. Something else to think about.
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 09-03-2011 at 05:25 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 09-03-2011, 06:04 PM Re: A To Z Index...
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Quote:
Originally Posted by PaulW View Post
None of your records have titles beginning with a lower case or accented character, I trust.
Quote:
Originally Posted by Brian07002 View Post
maybe...I really don't know if that would be the case as this is going into an a-z index and anything could be possible. I didn't know those would become issues. Something else to think about.
If your table and/or column collation is set to utf8_unicode_ci and you are use the `'LIKE' comparison, you should be ok with the query being case and accent insensitive.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 09-03-2011, 09:02 PM Re: A To Z Index...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by mgraphic View Post
If your table and/or column collation is set to utf8_unicode_ci and you are use the `'LIKE' comparison, you should be ok with the query being case and accent insensitive.
I tried adding an entry with the first character being lowercase -- that showed correctly under the correct letter in the a-z navigation, but if I used a '$' as the first character (accented character I am presuming a $ is) I found that it does NOT show up correctly, unless I change the url to: http://reunitemysite.com/getads.php?letter=$

Also a couple of side notes:

I would like to change the 0 1 2 3 4 5 6 7 8 9 on the a-z index to just [0-9] just like that.

I would also like to add a [misc] link to display titles that start with accented characters.

One last thing...To hide all the titles until a link is clicked, if I have too many links it will totally mess the page up.

Thank you in advance!
Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 09-03-2011, 10:14 PM Re: A To Z Index...
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Accented characture is like a grave accent for example (À)
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 09-04-2011, 04:39 PM Re: A To Z Index...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I would like to change the 0 1 2 3 4 5 6 7 8 9 on the a-z index to just [0-9] just like that.
Add the entry before or after the display loop.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to A To Z Index...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.98848 seconds with 12 queries