WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > IT Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

IT Discussion Forum Having IT issues? Got IT questions? Who doesn't? If you can't get your Apache to work with your MySQL or your php is choking on your ODBC... Let's see if we can help you come up with some ideas.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-07-2007, 12:09 PM
WebProWorld Member
 

Join Date: Nov 2006
Location: London
Posts: 60
seorocks RepRank 0
Question how to display one record in SQL/PHP

Hi all,

I have a database (spreadsheet) of products. and i want to display each product details on one page. could you please advise what is the code needed to select the info from the database and display each one on each page?

each page will have a different product, so will i need to create a page for each product page and add the code to it? or can they be generated dynamically?

many many thanks
SEO Rocks.
Reply With Quote
  #2 (permalink)  
Old 06-07-2007, 05:31 PM
WebProWorld New Member
 

Join Date: Sep 2006
Posts: 14
crdesign RepRank 0
Default Re: how to display one record in SQL/PHP

well with the vague description you gave it's hard to assess your knowledge of php or sql. First are you using MS SQL or MySQL or another type of SQL? If you know SQL I'm suprised by this question. You would easily do something similiar to SELECT * FROM tablename WHERE productID = '1'

But that is assuming you have a unique id column in your table for such a thing (if you don't well not much help from me).

Hope that helps but I think maybe you are starting before you've learned what you are doing.
Reply With Quote
  #3 (permalink)  
Old 06-07-2007, 06:42 PM
WebProWorld Member
 

Join Date: Oct 2005
Posts: 37
niggles RepRank 1
Default Re: how to display one record in SQL/PHP

You may want to do a Google search on "PHP SQL tutorials" or similar as it can be a quite complex process.

But as a starter, I'd do something like ->

$query = "SELECT * FROM tablename WHERE productID = '1'";
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){

echo $row["product_title"];
echo $row["[product_description"];

}

-----

Though you can do heaps more formatting by jumping in and out of PHP and using a "print" type command in your HTML e.g

Top Product: <?= $row["product_title"] ?>

Hope that helps.
Niggles
__________________
-------------------------------------------------
World Music World - bringing the World's Folk Music Cultures Together
http://www.worldmusicworld.com/
-------------------------------------------------
Reply With Quote
  #4 (permalink)  
Old 06-07-2007, 08:29 PM
Skywoolf's Avatar
WebProWorld Member
 

Join Date: Aug 2005
Location: Hong Kong & Philippines
Posts: 60
Skywoolf RepRank 0
Default Re: how to display one record in SQL/PHP

You sound like a guy I do work for who is not clear on the difference between a spreadsheet program on your PC/Mac and a database on the web.

I suspect you have a spreadsheet and want an online database. If this is true then you will need to design and set up the database first. You can then import the spreadsheet file after saving it as a comma or tab delimited text file. Then you need to write the PHP/SQL/HTML code to retrieve the data from the database and generate the web pages.
Reply With Quote
  #5 (permalink)  
Old 06-08-2007, 04:27 AM
WebProWorld Member
 

Join Date: Nov 2006
Location: London
Posts: 60
seorocks RepRank 0
Default Re: how to display one record in SQL/PHP

hi all,

many thanks for the posts. I have done mysql/php some time back and created a database and displayed the data on to the page.

my issue in displaying the data is: Will i need to add this code on each page and manually change the ID for each product page to display that relevant info? or is there a faster script for that which would generate all the products on different pages dynamically? not sure what such script is called and what to look for on Google/Yahoo to get more specific results.

i found on the web you could display the top 10 records.. but thats not my intention. i need pages and pages of info, each page will display one record of data. I will of course modify and present the pages by styling it with php and CSS.
Reply With Quote
  #6 (permalink)  
Old 06-08-2007, 03:49 PM
DaveSawers's Avatar
WebProWorld Veteran
 

Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 384
DaveSawers RepRank 1
Default Re: how to display one record in SQL/PHP

So why not have a single product page and pass in the id of the prouct as an argument, e.g.: http://mysite.com/product.php?id=5 and then use that in the SQL query to get the data from the database and stick it in the page.
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
  #7 (permalink)  
Old 06-08-2007, 11:20 PM
WebProWorld Member
 

Join Date: Sep 2006
Location: Michigan, USA
Posts: 29
dglaeser RepRank 0
Default Re: how to display one record in SQL/PHP

Quote:
Originally Posted by DaveSawers View Post
So why not have a single product page and pass in the id of the prouct as an argument, e.g.: http://mysite.com/product.php?id=5 and then use that in the SQL query to get the data from the database and stick it in the page.
Dave - This is exactly what we do with our advertiser listings on our sites, such as a process server in Florida is http://www.search-for-servers.com/moreinfo.php?id=33 and shows HERE COMES THE JUDGE - Sarasota, FL Process Servers - SearchForServers.com. We also do this on the main results page, such as http://www.search-for-servers.com/results.php?cat=5 shows California Process Server Search Results - SearchForServers.com.

Hope this type of information helps you out seorocks.

Last edited by dglaeser : 06-08-2007 at 11:24 PM. Reason: Forgot to uncheck 'retreive titles of urls', otherwise, my point with the dynamic urls is moot.
Reply With Quote
  #8 (permalink)  
Old 06-15-2007, 09:54 AM
WebProWorld Member
 

Join Date: Feb 2007
Location: United Kingdom
Posts: 40
lala RepRank 0
Default Re: how to display one record in SQL/PHP

Quote:
Originally Posted by DaveSawers View Post
So why not have a single product page and pass in the id of the prouct as an argument, e.g.: http://mysite.com/product.php?id=5 and then use that in the SQL query to get the data from the database and stick it in the page.

Hi Dave,

I have a similar problem and am glad to have read your answer to this post

If you were to have a navigation section, which consists of your categories and products: Would that mean that you assign to each link the corresponding id (as in your example http://mysite.com/product.php?id=5 )? Then, how could the SQL query look like? And would there a way to even automatically generate the nav bar from the database (if I create a new category with 3 new products, could they automatically update in my PHP file)? That would be marvellous...

Really apologize for my ignorance. I am totally new to the subject, but am eager to learn as much as needed to build my first PHP/MySQL project.

lala
Reply With Quote
  #9 (permalink)  
Old 06-15-2007, 10:33 AM
DaveSawers's Avatar
WebProWorld Veteran
 

Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 384
DaveSawers RepRank 1
Default Re: how to display one record in SQL/PHP

The SQL to get the product for the product page could be something like:

$qstring = $_SERVER["QUERY_STRING"];
$id = substr($qstring,strpos($qstring,"=") + 1);
$query = "select * from products where id=" . $id;
...

Then for the nav bar generation you can construct a query to get all the products in a particular category, sorting them to whatever order you want and then loop through the SQL result putting up each product in your nav bar.
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
  #10 (permalink)  
Old 06-16-2007, 10:18 AM
WebProWorld Member
 

Join Date: Feb 2007
Location: United Kingdom
Posts: 40
lala RepRank 0
Default Re: how to display one record in SQL/PHP

Thank you Dave

Just to double-check that I got this right: You would assign to each link a corresponding id ("table.htm?id=4" or similar?)and then use your query to populate the webpage with the product details of the choosen item?

Could I use a table and set it up that the product name goes in the heading, the description in the cell underneath and the product photos in the cells to the right for example? Would I use a print type command (as mentioned above) and if yes, what would it look like in my example as such?

I am so new to the subject that I need looking up literally anything. Apart from that I sometimes lack the ability to express propperly what I am looking for, so it makes it hard to Google it...

lala

Last edited by lala : 06-16-2007 at 10:23 AM. Reason: Forgot important point to mention
Reply With Quote
  #11 (permalink)  
Old 06-17-2007, 08:54 AM
DaveSawers's Avatar
WebProWorld Veteran
 

Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 384
DaveSawers RepRank 1
Default Re: how to display one record in SQL/PHP

Pretty much yes and yes. Print? Do you mean echo?

Run through some of the tutorials at: PHP Tutorial
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
  #12 (permalink)  
Old 06-19-2007, 01:33 AM
WebProWorld New Member
 

Join Date: Jun 2007
Posts: 15
vsd32 RepRank 0
Default Re: how to display one record in SQL/PHP

Try:
$query = "SELECT * FROM tablename WHERE productID = '1'";
$result = mysql_query($query);

An go on with others iddeas
Reply With Quote
  #13 (permalink)  
Old 06-19-2007, 01:14 PM
WebProWorld Member
 

Join Date: Feb 2007
Location: United Kingdom
Posts: 40
lala RepRank 0
Default Re: how to display one record in SQL/PHP

Guess I meant "echo".

I had a glance at the recommended website and it seems there is plenty of information. Will have a propper read. Thank you so much for your advice

lala
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > IT Discussion Forum
Tags: , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing an A Record lbunnell Search Engine Optimization Forum 1 03-27-2007 04:30 PM
how IP address record? Manpasand Web Programming Discussion Forum 4 05-28-2006 12:52 AM
A-Record setup twopooches Web Programming Discussion Forum 1 09-28-2005 05:23 PM
It's a record! WPW_Feedbot IT Discussion Forum 0 09-24-2005 02:57 AM
Now that's gotta be a record WebWishMaster WebProWorld: Guidelines/Announcements/Suggestions 2 06-03-2004 12:31 PM


Search Engine Optimization by vBSEO 3.2.0