Hi
I am trying to do something with PHP and having problems - a bit of a
a PHP novice I'm afraid.
What I am trying to achieve is to display the alphabet and numbers 0-9
on a web page. I want the letters/numbers to be clickable to specific
web pages if there are companies on my database that start with that
letter. If they are not on the database I just wantthe letters
displayed but not clickable.
I'm ok on all of the seperate components but I cannot seem to fit it
all together
1. I do a select from a SQL database using this string to reduce the
company name to it's initial letter.
$query = 'SELECT DISTINCT LEFT(company_na me,1) FROM members ORDER BY
company_name ASC';
2. I know I can use the following to get the numbers & letters
displayed.
for ($numbers = 0; $numbers <= 9; $numbers++) {
echo "<a href='members.p hp?coletter=$nu mbers'>$numbers </a>";
}
What I can't seem to work out is how to do a loop to do this check and
decide what to echo
After a few hours of trying various things from the manuals and web I
am now looking for some assistance.
Any help would be appreciated. 5 1704
skinnybloke schrieb: Hi
I'm ok on all of the seperate components but I cannot seem to fit it all together
1. I do a select from a SQL database using this string to reduce the company name to it's initial letter.
$query = 'SELECT DISTINCT LEFT(company_na me,1) FROM members ORDER BY company_name ASC';
ok!
2. I know I can use the following to get the numbers & letters displayed.
for ($numbers = 0; $numbers <= 9; $numbers++) {
only numbers in this case
echo "<a href='members.p hp?coletter=$nu mbers'>$numbers </a>"; }
What I can't seem to work out is how to do a loop to do this check and decide what to echo
// get the first element from your query
$row=mysql_fetc h_row($result);
$match=$row?$ro w[0]:false;
for( .... ) { // loop through your chars
if ($row && $match==$number ) { // we have a match
echo "<a href='members.p hp?coletter=$nu mbers'>$numbers </a>";
// make your output
//advance in the database
$row=mysql_fetc h_row($result);
$match=$row?$ro w[0]:false;
}
}
hope it helps
however ther are much "cooler" solutions to achive this this goal
eg:
for( .... ) { // loop through your chars
// now check if there ar entries in your DB starting with that letter
$query="SELECT COUNT(*) FROM members WHERE company_name like ${letter}*";
//
$row=mysql_fetc h_row($result);
if($row[0] > 0) {
echo ....
}
}
HIH
Jo
"skinnyblok e" <th************ **@yahoo.co.uk> kirjoitti
viestissä:27*** *************** **************@ 4ax.com... Hi
I am trying to do something with PHP and having problems - a bit of a a PHP novice I'm afraid.
What I am trying to achieve is to display the alphabet and numbers 0-9 on a web page. I want the letters/numbers to be clickable to specific web pages if there are companies on my database that start with that letter. If they are not on the database I just wantthe letters displayed but not clickable.
I'm ok on all of the seperate components but I cannot seem to fit it all together 1. I do a select from a SQL database using this string to reduce the company name to it's initial letter.
$query = 'SELECT DISTINCT LEFT(company_na me,1) FROM members ORDER BY company_name ASC';
Now that you have a query result containing the letters and numbers, you can
put them in an array like so:
$result = mysql_query($qu ery);
while($row = mysql_fetch_arr ay($result)) $alphanums[] = $row[0];
2. I know I can use the following to get the numbers & letters displayed.
for ($numbers = 0; $numbers <= 9; $numbers++) {
Now we just add a little condition that decides whether or not a link is
displayed
if(in_array($nu mbers, $alphanums)) // We check if it is in the array we
did earlier
echo "<a href='members.p hp?coletter=$nu mbers'>$numbers </a>";
else // If it wasn't -> just print a number without <a href>.
echo "$numbers"; }
That should do it.
-Kimmo
So a "cooler" solution would be to hit the database once for each
letter/number that might be in there as opposed to hitting it just once
at the beginning?
On Tue, 16 Aug 2005 19:25:49 +0300, "Kimmo Laine"
<et************ *******@Mgmail. com> wrote:
Hi Kimmo - thanks for that - I spent hours trying to sort this out and
in the end you've shown me that it was the "While" loop that I had
screwed up.
One other small issue
I currently only have 3 records on the database and all start with an
alpha character yet the script is showing the numeric 0 as a linkable
field.
Is this another of those PHP anomolies? Any ideas on how I put this
right
To anyone interested I corrected this by:
if ( in_array( strval( $numbers ), $alphanums ) )
On Wed, 17 Aug 2005 08:07:28 GMT, skinnybloke
<th************ **@yahoo.co.uk> wrote: On Tue, 16 Aug 2005 19:25:49 +0300, "Kimmo Laine" <et*********** ********@Mgmail .com> wrote:
Hi Kimmo - thanks for that - I spent hours trying to sort this out and in the end you've shown me that it was the "While" loop that I had screwed up.
One other small issue
I currently only have 3 records on the database and all start with an alpha character yet the script is showing the numeric 0 as a linkable field.
Is this another of those PHP anomolies? Any ideas on how I put this right This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Peter Olcott |
last post by:
The Halting Problem can not be solved within the degree of
expressability of a TM. My solution only worked because of
its more limited degree of expressability.
There is no such thing as a void function in a TM, thus there is
no way to make constructing the counter-example program
impossible for a TM.
|
by: Jack Addington |
last post by:
I want to scroll through the alphabet in order to scroll some data to the
closest name that starts with a letter. If the user hits the H button then
it should scroll to the letter closest to H. If no one exists with H, then
go to I, etc. If its near the end, say 'V', and the last person is a 'T'
then it should work its way back up the alphabet. I was trying to loop as
if the Char's were ints but I am having problems
I have buttons...
|
by: pmud |
last post by:
Hi,
I have 2 drop down lists on an asp.Net page. The 1st contains alphabets.
When the user selects an alphabet frm the first list, the second drop down
list should be populated with names from the sql database, which begin with
that alphabet.
For this I used an sql data Adapter & created a data set. The user's
selection in 1st list is passed as parameter to the sql statement.
|
by: Ammar |
last post by:
Dear All,
I'm facing a small problem.
I have a portal web site, that contains articles, for each article, the end
user can send a comment about the article.
The problem is:
I the comment length is more that 1249 bytes, then the progress bar of the
browser will move too slow and then displaying that the page not found!!!!
If the message is less than or equal to 1249 then no problem.
|
by: knoxautoguy |
last post by:
This problem has consumed a lot of my time, and I'm aftraid someone
will tell me that my whole approach to this objective is wrong;
however, I would like to know if there is a way to do this.
I have a web page divided into two major segments, with the top segment
fixed and the bottom segment allowed to scroll, thus giving the look of
frames without frames.
I also have anchors so that users can click on a letter of the alphabet
to jump...
| |
by: Mark |
last post by:
Hello.
I am looking for a way to download and cache a web page that the user has
not yet requested, and write the web page to the browser cache without
displaying it. My intention is to improve display performance when the user
eventually requests the cached document.
Is there a way to do this in Javascript?
Thanks
|
by: donald |
last post by:
Hi all,
Trying to having a div center and then div at the side got which i get
a problem with
The only way i can see to have this done is using a neg number for the
margin-top i can't use this becuase i don;t know the lenght of the main
div.
How can i fix this?
|
by: Wilson |
last post by:
i am learning to program using c++ and was set a task of making a
simple encryption algorithim. I choose to start with one where simply
each letter is replaced with its equivilent in the alphabet when
written backmards, i am hoping to make this more complex soon. Below
is the program i wrote but it does not work, it simply returns the
exact same text you enter. Could you please advise on how to sort
this, and also suggest any ways of...
|
by: dav3 |
last post by:
I am trying to code a little console program (no swing, no awt, just console). But I am having some trouble and I am not sure if its my logic, or my code, or possibly both?!
Anyways heres what I currently have, I have not taken into consideration a user winning by guessing the word yet. Just working on displaying the hidden word and updating it with respect to the users guesses.
public class whatever {
public static void main(String...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |