|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
need help getting data to display
first let me say I am not a coder... I was partnered wit a coder to complete a small project that is similar to a yellow page application... my obligation was to compile and format over 40,000 records that will populate the database... my problem is the coder I was partnered with has walked away leaving me with something I know very little about... I am hopine someone here with the needed knowledge will assist me with the following script...
The script display two drop down menu selection... one to select a "city" and another to select a business "category" the script does that (althought there is a problem with the "category" menuy as it display two of each category???)... What I need is someone to help me get the data to display when the script is executed... i.e., display the list of businesses (selected category)(name, address,city, zip, phone, etc) that are in the city also selected ... below is the script followed by the table data... TIA to anyone that can help me out here.... <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php /* broke this into functions...much easier to see and follow the flow of the program */ /* main code block */ //see if the form is submitted if (!$_POST['submit']){ show_form(); }else{ //form submitted and need to get record(s) get_data(); }//end if //end main code block function show_form() { //assume that city and category come from database mysql_connect("localhost", "######", "######") or die(mysql_error()); mysql_select_db("BUSLIST") or die(mysql_error()); //get data for city and category $sql = 'SELECT DISTINCT city FROM bus_list'; $r = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_object($r)) { $city[] = $row->city; } $sql = 'SELECT DISTINCT category FROM bus_list'; $r = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_object($r)) { $category[] = $row->category; } $result_city = mysql_query($sql) or die ("Can't connect to perform query one because ".mysql_error()); $result_category = mysql_query($sql) or die ("Can't connect to perform query two because ".mysql_error()); if ((!result_city)||(!$result_category)){ echo "error retrieving data"; }else{ //place the results into an array while ($rows=mysql_fetch_array($result_city )){ $city[]=$rows['city']; } while ($rows1=mysql_fetch_array($result_category)){ $category[]=$rows1['category']; } //show the form headers echo " <body> <form action="" . $_SERVER['PHP_SELF'] . "" method="post"> <table> <tr> <td>Select city</td></td> <td>Select category</td> </tr> <tr> <td><select name="city">"; //show the city data for ($x=0;$x<count($city);$x++){ echo "<option value="".$city[$x]."">".$city[$x]; } echo "</select></td><td> <select name="category">"; //add the category data for ($x=0;$x<count($category);$x++){ echo "<option value="".$category[$x]."">".$category[$x]; } echo "</select></td></tr></table> <input type="submit" name="submit" value="search"> </form></body>"; } }//end function show_form function get_data() { //get data from form $city=$_POST['city']; $category=$_POST['category']; $sql="select * from bus_list where city='$city' and category='$category'"; mysql_connect("localhost", "######", "######") or die(mysql_error()); mysql_select_db("BUSLIST") or die(mysql_error()); $result=mysql_query($sql) or die ("can;t query because ".mysql_error()); //show results to user } //end function get_data ?> </body> ---------------------------------------------------------------------------------------------------------- CREATE TABLE `bus_list` ( `name` varchar(255) NOT NULL default '', `address` varchar(255) NOT NULL default '', `city` varchar(255) NOT NULL default '', `zip` varchar(15) default NULL, `phone` varchar(40) default NULL, `www` varchar(255) default NULL, `notes` text, `cat` varchar(255) default NULL, `id` int(11) unsigned NOT NULL auto_increment, `subcatid` varchar(11) default NULL, PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=1 ; |
|
#2
|
|||||
|
|||||
|
RE: need help getting data to display
as far as dups in the dropdown, you are running the queries twice and adding both resuts sets to the same array.
here is corrected showform code php Code:
That should correct the dropdown problem (note the code is untested but should work) lets get that resolved and then move on to the next step... |
|
#3
|
|||
|
|||
|
RE: need help getting data to display
Hi and thanks for the reply... I tried your code.. not sure where but there seems to be something missing? (;, }) or something because I get an error citing the last line of the script???
|
|
#4
|
|||
|
|||
|
RE: need help getting data to display
take out the last curly bracket in the function after the body tag, that should fix that problem.
|
|
#5
|
|||||
|
|||||
|
RE: need help getting data to display
here is the get_data function modified slightly to show you how to display the data.
php Code:
if you just follow my lead inside the while statement, and just add the rest of the column names to the echo, it should output a table row for each record returned. Since my design skills are quite bad, I will leave the formatting up to you. Let me know how it goes! |
|
#6
|
|||
|
|||
|
RE: need help getting data to display
please bear with me here I am not a coder... I am stuck trying to do something that is beyond my experience and I am having a hard time with this...
I went back to my original code and commented out the second string that was causing the double population... and that worked... now Can you help me get the data to display? TIA |
|
#7
|
|||
|
|||
|
RE: need help getting data to display
see my post previous to your last post, it explains it there!!!
|
|
#8
|
|||
|
|||
|
RE: need help getting data to display
getting "Parse error: parse error, expecting `','' or `';''... on line 110"
here is the entire (edited) script...what am I doing wrong? TIA <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php /* broke this into functions...much easier to see and follow the flow of the program */ /* main code block */ //see if the form is submitted if (!$_POST['submit']){ show_form(); }else{ //form submitted and need to get record(s) get_data(); }//end if //end main code block function show_form() { //assume that city and category come from database mysql_connect("localhost", "#", "#") or die(mysql_error()); mysql_select_db("BUSLIST") or die(mysql_error()); //get data for city and category $sql = 'SELECT DISTINCT city FROM bus_list'; $r = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_object($r)) { $city[] = $row->city; } $sql = 'SELECT DISTINCT category FROM bus_list'; $r = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_object($r)) { $category[] = $row->category; } $result_city = mysql_query($sql) or die ("Can't connect to perform query one because ".mysql_error()); $result_category = mysql_query($sql) or die ("Can't connect to perform query two because ".mysql_error()); if ((!result_city)||(!$result_category)){ echo "error retrieving data"; }else{ //place the results into an array while ($rows=mysql_fetch_array($result_city )){ $city[]=$rows['city']; } //while ($rows1=mysql_fetch_array($result_category)){ //$category[]=$rows1['category']; //} //show the form headers echo " <body> <form action="" . $_SERVER['PHP_SELF'] . "" method="post"> <table> <tr> <td>Select city</td></td> <td>Select category</td> </tr> <tr> <td><select name="city">"; //show the city data for ($x=0;$x<count($city);$x++){ echo "<option value="".$city[$x]."">".$city[$x]; } echo "</select></td><td> <select name="category">"; //add the category data for ($x=0;$x<count($category);$x++){ echo "<option value="".$category[$x]."">".$category[$x]; } echo "</select></td></tr></table> <input type="submit" name="submit" value="search"> </form></body>"; } }//end function show_form function get_data() { //get data from form $city=$_POST['city']; $category=$_POST['category']; $sql="select * from bus_list where city='$city' and category='$category'"; mysql_connect("localhost", "#", "#") or die(mysql_error()); mysql_select_db("BUSLIST") or die(mysql_error()); $result=mysql_query($sql) or die ("can;t query because ".mysql_error()); echo "<table>" while ($row=mysql_fetch_array($result){ echo"<tr><td>".$row['name']."</td><td>".$row['address']."</td><td>".$row['city']."</td><td>" ;//etc...etc } echo "</table>" //show results to user } //end function get_data ?> </body> </html> |
|
#9
|
|||
|
|||
|
RE: need help getting data to display
my bad... You need to put semi-colons after the 'echo "<table">' statements that come before and after the while statement (lines 108 and 115) That should fix it.
|
|
#10 |