Forum Moderators: coopster
I am trying to pull specific data from MySQL database using PHP and have it displayed on my web page. Go to my web page to see exactly what I want to do.
Right click on the link and open it in a new browser or else you will get stuck in the page. Please come back and post a reply with your knowledge.
*link deleted*
You will see as you scroll down on the page that there is a table listing Part Number, Description and Price. What I want to do is use PHP to display that information from the MySQL database so all I have to do is update the database to change any price or description of a Part Number. So the Part Number I guess is the primary or index. I really don't understand much about this. I've tried searching on the net and so far all I can come up with is how to connect to the database and display results on a web page but only according to the row number. I want to be able to list the info according to the specific part number. Does anyone get my drift and can someone come show their intelligence in this and show me the code I'd need to use that is specific to my web page of what I am trying to do?
So for instance I would want to find the row data in the database based on a specific part number (not row number). Thus having it where I enter a specific part number there on my web page and the description and price will be pulled from the database and be placed in the corresponding table columns.
I appreciate it,
Mike
[edited by: ergophobe at 9:49 pm (utc) on July 31, 2004]
[edit reason] as per TOS [webmasterworld.com] [/edit]
Welcome to WebmasterWorld. Glad to have you aboard!
Check out the forum charter [webmasterworld.com] and your sticky mail for more on why the link was deleted.
As for your question, you may want to start with The Basic of extracting data from MySQL Using PHP [webmasterworld.com] which is archived in the forum library [webmasterworld.com]
Cheers,
Tom
I think you'll find what you need in the thread referenced, but to add a little specificity...
First, you probably don't want the just part number as your primary key. It's possible that two manufacturers would use the same part number. If you're sure that the part nums will always be unique, then it would be fine. Otherwise you'll want to add another column or you will want a compound primary key (keyed on say partnum and manufacturer).
Let's assume you go the first route and have a table like
id
partnum
descript
price
Then let's say that the user enters a part number in a form field named partnum.
You have a query like
$partnum = mysql_escape_string($_POST['partnum']);
$part_list = "";
$q = "SELECT partnum, descript, price FROM table1 WHERE partnum='" . $partnum . ' ORDER BY partnum";
$result = mysql_query($q);
while ($part = mysql_fetch_assoc($result))
{
$part_list .= "<tr><td>" . $part['partnum'] . "</td><td>". $part['descript'] ."</td><td>". $part['price'] ."</td><tr>";
}
echo $part_list;
Tom
I will not be using a form. Also the part number will only occur once in the database. All I want to do is display what is in the row of the primary field which is partnumber. Display that data on the web page where I need it and that's it. No forms, nothing for the user to fill out, just simple layout with the part number, description and price being pulled from the database. I have read the post you showed me but really do not understand how to use it for my application.
Mike
$partnum = mysql_escape_string($_POST['partnum']);
to set part number by whatever means you want. To test, you could just hardcode a part number and get it working that way, as in
$partnum = 'W384s5';
I really do not understand. I need plain baby talk english because I am very very new to this MySQL and PHP.
Please note that there will not be any users filling out forms on the web page to get the result. I want the data displayed when the web page loads so that the content will automatically be there for the user to see.
For instance:
Part Number: Description: Price:
111857126A Test Part 1 $85.23
222545321A Test Part 2 $21.02
333789215A Test Part 3 $54.32
So you see there is a column for part number, description and price above. As soon as the user goes to this page that content will be there for the user to see. The part number, description and price will be pulled from the database. So what I need to know is what code do I use to accomplish this and what do I enter in each column above to retrieve a specific part number that I want in that cell?
Let's say I want part number 111857126A to appear in the first row and have the description and price in the corresponding columns.
Now let's say I want 222545321A to be in the second row or maybe I want it on the third row. Maybe I change my mind and want it on the 4th row on the web page. Where ever I want it is my point. So I need to grab specific rows from the database and display them where ever I decide to on my web page.
So I need to have the querry search for a specific part number and display the results where I want and I need to do this for each row on the web page.
Does this give you any further insight as to what I need to do?
Mike
What I don't understand, if that's the case, is why you care whether you access the information via row number or part number. You get all parts either way. Are you just trying to get a list that is in order by part number?
$part_list = "";
$q = "SELECT partnum, descript, price FROM table1 ORDER BY partnum";
$result = mysql_query($q);
while ($part = mysql_fetch_assoc($result))
{
$part_list .= "<tr><td>" . $part['partnum'] . "</td><td>". $part['descript'] ."</td><td>". $part['price'] ."</td><tr>";
}
echo "<table>$part_list</table>";
That will output your table.
Maybe though, we need to back up and ask how far along you are. Do you have your database built and your data in it? Do you know how to connect to MySQL?
If not, reread the thread referenced in my first post and see if you can make sense of it.
Tom