|
| Index | Recent Threads | Unanswered Threads | Who's Online | User List | Help |
|
|
| No member browsing this thread |
|
Thread Status: Active Total posts in this thread: 8
|
|
| Author |
|
|
Stranger Joined: May 27, 2008 Post Count: 6 Status: Offline |
I am new to using asp with mysql, I have everything set up with my database and my webpage is displaying the database information that I want. So far so good, however have now hit a snag. I will explain what I am doing to give a better description of my problem since I don't really know what the problem is. I have a database of restaurants that I am displaying in tables, I would like to have each restaurant display as a hyperlink to further information about that specific restaurant though. And I am not sure how to go about doing that, if I can do it at all ? So picture a big list of restaurants in a table from a database, lets say I want to see more information about McDonalds, I click mcdonalds and it then loads more in depth information about mcdonalds. |
||
|
|
Advanced Member Joined: Jun 14, 2003 Post Count: 2933 Status: Offline |
Hi, What you want to do is create what a lot of people would call a 'detail' page. This is what you need to do:
For example, in your first page where you list all your records, for each record/row you would include this link: <a href="detail-page.asp?restaurantid='<% response.write "restaurant-id" %>'">View Details</a> Now in you 'detail' page, you need to grab that id from the query string: <% Request.QueryString("restaurantid") %> Makes sense? Stefan ---------------------------------------- Stefan Mischook Video Tutorial Store | Web Templates |
||
|
|
Stranger Joined: May 27, 2008 Post Count: 6 Status: Offline |
Is it possible to pass the restaurantid to the restaurant when the page is called up ? Or do I need to create an ID by hand for each link and then use that ? Basically as I understand it then it almost seems easier to just HTML cod the list of restaurants, since I would be hand coding each entry with an sql query via asp anyway ? |
||
|
|
Advanced Member USA Joined: Aug 14, 2007 Post Count: 1129 Status: Offline |
Basically as I understand it then it almost seems easier to just HTML cod the list of restaurants, since I would be hand coding each entry with an sql query via asp anyway ? You don't need to hand code this. You can set up your restaurants table in the database to have a unique id that automatically increments: Then use a loop to loop through the restaurant table, grabbing one row at a time, and using asp get the id of each restaurant and create the link like Stef (Admin) suggested. That link (for example, you could link to "detail-page.asp?restaurantid=1") would then send the user to the details page, which would then figure out which restaurant the user is wanting to view via the restaurantid in the URL (in this case, the restaurant with an id of 1) and display the correct information. ---------------------------------------- Benjamin Falk | student : designer : developer Twitter: falkencreative |
||
|
|
Advanced Member USA Joined: Aug 14, 2007 Post Count: 1129 Status: Offline |
Just as an add-on to my last reply, you may want to check out (found using a quick search on Google): http://www.plus2net.com/asp-tutorial/sql-select.php http://www.w3schools.com/ASP/coll_querystring.asp ---------------------------------------- Benjamin Falk | student : designer : developer Twitter: falkencreative |
||
|
|
Stranger Joined: May 27, 2008 Post Count: 6 Status: Offline |
Very informative thanks, Ill try some of this out and post again if I run into more problems. |
||
|
|
Stranger Joined: May 27, 2008 Post Count: 6 Status: Offline |
Ok I had to rework the structure of my database in order to get the ID to work properly, the problem I have run into now is that my page now has blank lines in it and shows the information lopsided. Dim oConn, oRs Dim qry, connectstr Dim db_name, db_username, db_userpassword Dim db_server db_server = "secureserver.net" db_name = "newtest22" db_username = "myusername" db_userpassword = "mypassword" fieldname = "AF" fieldname2 = "ID" tablename = "newtest" connectstr = "Driver={MySQL ODBC 3.51 Driver};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword Set oConn = Server.CreateObject("ADODB.Connection") oConn.Open connectstr qry = "SELECT * FROM " & tablename Set oRS = oConn.Execute(qry) if not oRS.EOF then while not oRS.EOF %> <table width="720" border="2" cellpadding="0" cellspacing="0"> <tr> <td width="177" align="center" valign="top"><% if oRs.Fields(fieldname2) < 8 then response.write oRs.Fields(fieldname) else %></td> <td width="177" align="center" valign="top"><% if oRs.Fields(fieldname2) > 7 then response.write oRs.Fields(fieldname) else %></td> </tr> </table> This is what I am using to display the information and split it. Basically I have entered a number of restaurants, if there ID is under 8 they go on side one. If its more then 7 it goes on side 2... The problem is that side two has 7 blank lines and then starts inputting data, instead of starting at the top... I am guessing it's due to my lack of else statement, but I can't find a code that says else remove blank line until we hit some data. ---------------------------------------- [Edit 1 times, last edit by newbies13 at May 28, 2008 8:44:14 PM] |
||
|
|
Stranger Joined: May 27, 2008 Post Count: 6 Status: Offline |
Also I have run into a snag with dynamic select query... I have my restaurant page linked to my database, it queries all and puts a link on each as suggested. so now when you click on arbys it points to ?restaurantID=Arbys. My problem now is producing that in my details page, I request the querystring and try to match that up to the database so that only the arbys details are shown. But I can't seem to get it to work without specially writing arbys into my select command. Which of course results in every restaurant displaying arbys.... and SELECT * FROM doesn't seem to like dynamic content in it... |
||
|
|
|
|
|
Current timezone is GMT Mar 19, 2010 2:52:33 AM |