Jump to content

MySql to PHP


ItsWesYo

Recommended Posts

I was wondering how would I go about making a page for each item in a MySQL database.

 

Example:

Lets say I have a database filled like this:    Object name | Rarity | Price

 

And I had 3 object under it like this:

 

Apple | Common | $2

Book | Rare | $10

Candy | Common | $1

 

How would I extract that from the database and make a php page (info.php) with their variables with them?

 

Example of that:

 

info.php?item=Apple

The 'Apple' is a 'Common' item that costs '$2'

 

And so on.

Link to comment
Share on other sites

Yeah, I had that in mind. But it's not what I'm looking for.

 

Maybe I worded it wrong .. but I want a list of ALL the items on one page. Then the person can click on an item. It would go to another page with the information listed.

 

index.php would be the list of the items

info.php could be the page that would store the stuff (info.php?item=book, info.php?item=candy, etc)

Link to comment
Share on other sites

for ur index.php page:

 

<?php
Do other coding here...
$sql="select * from table";
$select=mysql_query($sql);
while($row=mysql_fetch_object($select)){
$Objectname=$row->objectname;
$rarity=$row->rarity;
$price=$row->price;
echo '<a href='info.php?objectname=$objectname'>$objectname</a>';
echo "<br>";
echo $rarity;
echo "<br>";
echo $price;
Do the rest of coding...
?>

 

Now for ur info.php page:

 

<?php
$objectname=$_GET['objectname'];
echo $objectname;
Do some coding here...

 

In the info.php it depends on you what type of code u make and what u want to show for that object.

You can do a sql query in info.php for retrieving details for object like in index.php but just add this to ur where clause.

select * from table where objectname='$objectname';

 

Hope this will help you.

Try it out and let me know.

Link to comment
Share on other sites

easy.

 

index.php

<?php
echo "Please select an Item.<ul>";

$query = mysql_query("SELECT * FROM `itemsTable`") or die("Error: ".mysql_error());
while($r = mysql_fetch_array($query)){
echo "<li><a href='info.php?item={$r['itemName']}'>{$r['itemName']}</a></li>";
}

echo "</ul>";
?>

 

then info.php

<?php

if(!isset($_GET['item'])){
echo "No item selected.";
exit();
}else{
$item = $_GET['item'];
}

$info = mysql_fetch_array(mysql_query("SELECT * FROM `itemsTable` WHERE `itemName`='{$item}'"));
echo <<<html
Name: {$info['itemName']}<br>
Price: {$info['itemPrice']}
html;

?>

 

etc etc. hope thats what your after.

 

EDIT: sorry mmarif4u, didnt see your post.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.