473,782 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Some help with arrays / displaying results

Chrisjc
375 Contributor
have one page that has a drop down menu, once the user selects the desired option it will then pass the selected value to a 2nd drop down. Once they select there next option I pass that value...
Now I would like to hold the 2nd selected value have it search the database find all that match the selected and then only display what matches it in the corresponding ROWS in the database.


I was hoping to get some help with an array because I would like it, to display the infromation found in a format of an address for example

Company Name
Address
City, State Zip Code
Phone Number
Website


The user is selecting there "STATE" Once selected it pass that value to "getCity" Then displays a list of "City's" in the selected "STATE"

So once they select "CITY" id like it to display all Companys found in that "CITY" in the format I listed above

Below is the code I am trying to use to make it display things... how ever I am having no luck... I am getting an error on line 60 and 60 in that code is ( ?> )

So I am unsure what is going on... however I feel this is the wrong way to do this anyways Id like to use an array...

[PHP]
// =============== =============== =============== =============== =============== =============== ===========
// Construct parts overview after user selected state, city.
// =============== =============== =============== =============== =============== =============== ===========
if( (isset($_GET['getpart']) AND isset($_GET['state']) AND isset($_GET['city']))
OR (isset($_GET['search']) ) ) {
if(isset($_GET['getpart'])) {
$st = $_GET['state'];
$ci = $_GET['city'];
$query="SELECT dealerlocater.s tate, ".
" dealerlocater.c ompany, dealerlocater.a ddress, dealerlocater.c ity, dealerlocater.s tateabb, dealerlocater.z ip, dealerlocater.p hone, dealerlocater.w eb ".
" FROM dealerlocater ".
" WHERE state='$st' ".
" GROUP BY dealerlocater.s tate ".
" ORDER BY dealerlocater.s tate ";
}
$res = mysql_query($qu ery)
or die("Invalid query: " . mysql_query());
// verify that the part number has been passed
if (!isset($_REQUE ST['city']) OR strlen(trim(str ip_tags($_REQUE ST['city']))) < 4 )
die("Invalid city specified.");
// sanitize and save the requested part number
$city = trim(strip_tags ($_REQUEST['city']));
// select the data row for the specified part number
$res = mysql_query("SE LECT * FROM dealerlocater WHERE city='$city' LIMIT 1")
or die("Invalid select query: " . mysql_query());
// verify that a row has been selected, if not: issue message
if (mysql_num_rows ($res) < 1)
echo "No database information for '$city' found.";
// a row had been selected, process the data
else {
$row = mysql_fetch_ass oc($res);
$city = $row['city'];
$st = $row['state'];

echo $city;

?>
[/PHP]
Jan 16 '08 #1
7 1713
stepterr
157 New Member
What is the error message that you are getting? A lot of times the line number it gives isn't always the one causing the problem, it could be the line before it. Now looking at your code I see that you have "else {" but you never have a " } ". I bet that is where the error is coming from.

As far as how to display your results, try doing something like this.
[PHP]// select the data row for the specified part number
$res = mysql_query("SE LECT * FROM dealerlocater WHERE city='$city' LIMIT 1")
or die("Invalid select query: " . mysql_query());
if ($res)
{
while ($array= mysql_fetch_ass oc($res))
{

$CompanyName = $array['CompanyName'];
$Address= $array['Address'];
$city = $array['city'];
$st = $array['state'];
$zip = $array['zip'];
$Phone = $array['Phone'];
$Website = $array['Website'];

echo "'$CompanyN ame' <br>";
echo "'$Address' <br>";
echo "'$city' '$state', '$zip' <br>";
echo "'$Phone' <br>";
echo "'$Website' <br>";

}
}
else
{
echo "No database information for '$city' found.";
}[/PHP]

Of course that is a general idea to get you started. You'll have to change the names of the fields to match what you have in your database and you'll probably want to change the format a bit, maybe even put it in a table. But like I said, that should get you going.
Jan 16 '08 #2
Chrisjc
375 Contributor
Thank you for you input that should work however I am getting the error on the very lasy line which is the closing tag... even with your added code..

I did get it to work with the following code HOWEVER it was only displaying one entiry and the selection I was making should have been showing me 2 not 1

[PHP]
// =============== =============== =============== =============== =============== =============== ===========
// Construct parts overview after user selected state, city.
// =============== =============== =============== =============== =============== =============== ===========
if( (isset($_GET['getpart']) AND isset($_GET['state']) AND isset($_GET['city']))
OR (isset($_GET['search']) ) ) {
if(isset($_GET['getpart'])) {
$st = $_GET['state'];
$ci = $_GET['city'];
$ad = $_GET['address'];
$co = $_GET['company'];
$sa = $_GET['stateabb'];
$zi = $_GET['zip'];
$ph = $_GET['phone'];
$we = $_GET['web'];
$query="SELECT dealerlocater.s tate, ".
" dealerlocater.c ompany, dealerlocater.a ddress, dealerlocater.c ity, dealerlocater.s tateabb, dealerlocater.z ip, dealerlocater.p hone, dealerlocater.w eb ".
" FROM dealerlocater ".
" WHERE state='$st' ".
" GROUP BY dealerlocater.s tate ".
" ORDER BY dealerlocater.s tate ";
}
$res = mysql_query($qu ery)
or die("Invalid query: " . mysql_query());


// verify that the part number has been passed
if (!isset($_GET['city']) OR strlen(trim(str ip_tags($_GET['city']))) < 4 )
die("Invalid city specified.");

// sanitize and save the requested city
$city = trim(strip_tags ($_GET['city']));

// select the data row for the specified city
$res = mysql_query("SE LECT * FROM dealerlocater WHERE city='$city' LIMIT 0, 10")
or die("Invalid select query: " . mysql_query());

if (mysql_num_rows ($res) < 1) {
// build the output array sorted by category
$outArray=array ();
while ($row = mysql_fetch_ass oc($res)) {
$co = $row['company'];
$ad = $row['address'];
$ci = $row['city'];
$sa = $row['stateabb'];
$zi = $row['zip'];
$ph = $row['phone'];
$we = $row['web'];
$outArray=array ();
}
}
else { // no rows selected (mysql_num_rows == 0)
echo 'No results found for your search!';
}
echo $co;
}
?>
</html>
[/PHP]
Jan 16 '08 #3
Chrisjc
375 Contributor
Okay so here is an update. I got everything to work just not able to pull one city 2 times...

What I mean is there is 2 companys in one city I am only getting it to display 1 company FOUR TIMES!!!

I know its becuase of my loop its $i=0; $i<4;

however why in the hell wont it show me the selected CITY and 2 differnt companys... or for that matter any amount of companys that should be in that city...

Any help would be grate I gotta take a break Iv worked on this for 9 hours today.... BLAH!!!


Here is the code I am leaven it at for the day.

[PHP]

// =============== =============== =============== =============== =============== =============== ===========
// Construct parts overview after user selected state, city.
// =============== =============== =============== =============== =============== =============== ===========
for ($i=0; $i<4; $i++) {
if( (isset($_GET['getpart']) AND isset($_GET['state']) AND isset($_GET['city']))
OR (isset($_GET['search']) ) ) {
if(isset($_GET['getpart'])) {
$st = $_GET['state'];
$ci = $_GET['city'];
$co = $_GET['company'];
//$query=" SELECT dealerlocater.i d, ".
// " dealerlocater.c ity, dealerlocater.a ddress, dealerlocater.c ompany, dealerlocater.z ip, dealerlocater.s tateabb, dealerlocater.w eb, dealerlocater.p hone ".
//" FROM dealerlocater ".
// " WHERE city='$ci' LIMIT 1 ";
//" GROUP BY dealerlocater.c ompany ".
//" ORDER BY dealerlocater.c ompany ";
}
//$res = mysql_query($qu ery)
// or die("Invalid query: " . mysql_query());


// sanitize and save the requested city
$city = trim(strip_tags ($_GET['city']));
// select the data row for the specified city
$res = mysql_query("SE LECT * FROM dealerlocater WHERE city='$city' LIMIT 1")
or die("Invalid select query: " . mysql_query());
if ($res)
{
while ($array= mysql_fetch_ass oc($res))
{

$co = $array['company'];
$ad = $array['address'];
$ci = $array['city'];
$sa = $array['stateabb'];
$zi = $array['zip'];
$ph = $array['phone'];
$we = $array['web'];

echo "$co <br>";
echo "$ad <br>";
echo "$ci, $sa $zi <br>";
echo "$ph <br>";
echo "$we <br>";
echo "<br>";
}
}
}
}
?>
[/PHP]

I know there is 2 querys in there... one is commented out.... they both work the same... Just cant make it do what I want it toooooo

=((
Jan 17 '08 #4
stepterr
157 New Member
Take off the "LIMIT 1" from your query and see if that does the trick. That should at least give you all the companies for the city that was selected. You'll still get the issue with your loop though
Jan 17 '08 #5
Chrisjc
375 Contributor
Take off the "LIMIT 1" from your query and see if that does the trick. That should at least give you all the companies for the city that was selected. You'll still get the issue with your loop though
Fixing the loop to display the right amount is no issue at all I set it to 4 just to see if I can make it display 8.... because I know it should be returning 2 companys...

I did sadly take LIMIT 1 off and that still did not do the trick...

I am in need of more help... am I missing something here????

Some command I can add like ( GROUP BY company ORDER BY company )

Now I have tryed that and it gets mad at me... and will only display the city name after and will not keep the other ( * ) in the res...

Something I am missing

Here is the link to the site of its operation maybe you can better understand do the following selection.

The site

Select State = WYOMING
Select City = Casper

This city has 2 companys it should be displaying... and is not....

The code above still stands. Would anyone like the full 2 page code so you might be able to test it on your side?? Thank you for you help so far STEP
Jan 17 '08 #6
stepterr
157 New Member
Just curious, but have you tried doing your query all alone? Either within your database manager or just creating another page that doesn't have any other code around it besides your SQL statement?
"SELECT * FROM dealerlocater WHERE city='Casper' "
Jan 18 '08 #7
Chrisjc
375 Contributor
Just curious, but have you tried doing your query all alone? Either within your database manager or just creating another page that doesn't have any other code around it besides your SQL statement?
"SELECT * FROM dealerlocater WHERE city='Casper' "

No I havent... Let me give that a try..

stand by
Jan 18 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3804
by: Han | last post by:
Determining the pattern below has got my stumped. I have a page of HTML and need to find all occurrences of the following pattern: score=9999999999&amp; The number shown can be 5-10 characters in length. I would like to extract only the number, stripping off the "score=" and "&amp;".
3
1401
by: Pjotr Wedersteers | last post by:
I have an array with string and numerical indices: $arr = 10; $arr = 90; $arr = 45; $arr = 34; Keys are not in a sorted order and preferably it stays that way. How can I display the results like this: x0 : 10 y1: 90
2
3536
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned from my search and how many records I have set it to display per page. All great so far, HOWEVER..... When you click the next link to see the next 10 results on the next page, it just dumps the search details and pulls up all the records in the...
3
2042
by: Michael Lauzon | last post by:
This is not for a class, I have a group on SourceForge, this is what one of the Developers is asking; the more advanced you can make it right off all the better!: Can someone please create some MySQL to create the first table: the players table. It will need to include (as a minimum): - ID (unique)
3
1926
by: bb91915 | last post by:
I am taking a beginners class in C and am attempting to write code for extra problems my instructor gave us. These are not for grade and are only used solely for practice. I have a hard time taking pseudocode and turning it into code. Since I am in a beginners class, we have only learned so much to date, so what I am presenting will be really rough, so please pardon my ignorance. Here are my instructions, with my code to follow: ...
4
6917
by: Brian L. Troutwine | last post by:
I've recently begun to teach myself pygame by making a bunch of small toys. My current toy is cellular automata displayer and I've gotten a bit stuck on the displaying bit. (If automata isn't the plural of automaton please forgive me.) The current automata are only binary and are calculated using 2D Numeric arrays. It had been my assumption that once the automata was calculated I could then multiply the entire array by 255 to get a nice...
0
1262
by: wyattroerb | last post by:
Hi, like a lot of other newbies in xml i suffer from the various ways you can take for xml data processing in python. Here are my two major problems: Problem number one: A application written in python remote controls (demands actions) a HIL (Hardware in the loop) test stand and evaluate its actions (system reactions on the demand ) afterwards. The application puts all the results in a word protocol during the test. Now i would like to...
1
1852
by: assgar | last post by:
Hello I have changed the process code abit so it receives the data from the form and ensures the data in array format. This has eliminated my previous error. The problem I am experiencing is the looping is not displaying the all contents of the arrays. Do you have any idea what the problem is and how to fix the problem?
3
1498
by: Nightcrawler | last post by:
I have a website that does the following: 1. it accepts a keyword through a textbox in the UI 2. once the submit button is clicked it goes out and spiders a few websites using the keyword supplied 3. it converts the returned html to xml 4. it uses LINQ to query the html page and stores the results in a database table 5. it then pulls the results from the database using a LINQ query ad displays them on a webpage
0
9639
marktang
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...
0
10311
Oralloy
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...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7492
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6733
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4043
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
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.