ItsWesYo Posted June 27, 2007 Share Posted June 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 read up on your mysql, but basicaly you are running a query on your database and it looks like this <?php $item = $_GET['item']; $q = "SELECT * FROM `table` WHERE `Object name` = '$item'"; $result = mysql_query($q) or die (mysql_error()); Quote Link to comment Share on other sites More sharing options...
ItsWesYo Posted June 27, 2007 Author Share Posted June 27, 2007 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) Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 27, 2007 Share Posted June 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted June 27, 2007 Share Posted June 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
ItsWesYo Posted June 27, 2007 Author Share Posted June 27, 2007 Thanks you all, that's exactly what I was looking for. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.