473,396 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Some help with arrays / displaying results

Chrisjc
375 256MB
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.state, ".
" dealerlocater.company, dealerlocater.address, dealerlocater.city, dealerlocater.stateabb, dealerlocater.zip, dealerlocater.phone, dealerlocater.web ".
" FROM dealerlocater ".
" WHERE state='$st' ".
" GROUP BY dealerlocater.state ".
" ORDER BY dealerlocater.state ";
}
$res = mysql_query($query)
or die("Invalid query: " . mysql_query());
// verify that the part number has been passed
if (!isset($_REQUEST['city']) OR strlen(trim(strip_tags($_REQUEST['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("SELECT * 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_assoc($res);
$city = $row['city'];
$st = $row['state'];

echo $city;

?>
[/PHP]
Jan 16 '08 #1
7 1692
stepterr
157 100+
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("SELECT * FROM dealerlocater WHERE city='$city' LIMIT 1")
or die("Invalid select query: " . mysql_query());
if ($res)
{
while ($array= mysql_fetch_assoc($res))
{

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

echo "'$CompanyName' <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 256MB
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.state, ".
" dealerlocater.company, dealerlocater.address, dealerlocater.city, dealerlocater.stateabb, dealerlocater.zip, dealerlocater.phone, dealerlocater.web ".
" FROM dealerlocater ".
" WHERE state='$st' ".
" GROUP BY dealerlocater.state ".
" ORDER BY dealerlocater.state ";
}
$res = mysql_query($query)
or die("Invalid query: " . mysql_query());


// verify that the part number has been passed
if (!isset($_GET['city']) OR strlen(trim(strip_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("SELECT * 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_assoc($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 256MB
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.id, ".
// " dealerlocater.city, dealerlocater.address, dealerlocater.company, dealerlocater.zip, dealerlocater.stateabb, dealerlocater.web, dealerlocater.phone ".
//" FROM dealerlocater ".
// " WHERE city='$ci' LIMIT 1 ";
//" GROUP BY dealerlocater.company ".
//" ORDER BY dealerlocater.company ";
}
//$res = mysql_query($query)
// 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("SELECT * FROM dealerlocater WHERE city='$city' LIMIT 1")
or die("Invalid select query: " . mysql_query());
if ($res)
{
while ($array= mysql_fetch_assoc($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 100+
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 256MB
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 100+
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 256MB
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
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...
3
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...
2
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...
3
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...
3
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...
4
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...
0
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...
1
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
agi2029
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,...

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.