Current location: Hot Scripts Forums » Programming Languages » PHP » Grab item


Grab item

Reply
  #1 (permalink)  
Old 06-08-09, 09:38 PM
Schmidty102 Schmidty102 is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Grab item

Hey all! I am new here... and am in need of some major help! I hope I am posting this in the right forum section, and if I am not... feel free to move it.

I have taken on a project for grabbing item prices from a database for an online game called RuneScape.

Here is my current progress: http://schmidty102.com/grandexchange...changegrab.php

If you enter in 1127 into the submit box and hit submit, it will grab the prices of the rune platebody.

Each item which we will be adding to this has its own individual code/id just like the rune platebody. How would we go about turning "item name" into "item id"?

What I want to be able to do is enter in Rune platebody in the text box and to be able to get the price of it. I am thinking this would be an if code... HELP!?

Here is my current code for the page listed above:
HTML Code:
<form method="get">
Name: <input type="text" name="id" />
<input type="submit" />
</form>
PHP Code:

<?php

$curlh 
curl_init();

curl_setopt($curlhCURLOPT_URL'http://itemdb-rs.runescape.com/viewitem.ws?obj=' $_GET['id']);
curl_setopt($curlhCURLOPT_RETURNTRANSFERtrue);

$src curl_exec($curlh);

curl_close($curlh);

$item = array();

ereg('<b>Minimum price:</b> ([0-9\.km,]+)'$src$item['min']);
ereg('<b>Market price:</b> ([0-9\.km,]+)'$src$item['mark']);
ereg('<b>Maximum price:</b> ([0-9\.km,]+)'$src$item['max']);


echo 
'
<strong>Minumim:</strong> ' 
$item['min'][1] . '<br />
<strong>Market:</strong> ' 
$item['mark'][1] . '<br />
<strong>Maximum:</strong> ' 
$item['max'][1] . '<br />';
?>
Reply With Quote
  #2 (permalink)  
Old 06-09-09, 02:25 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
If you create an array with the item id as the KEY and the item name as the VALUE, then you can use array_search() to get the ID when you enter a name.

Example:
PHP Code:

<?php
if($_GET['id'])
{
 
$item = array(
               
"min" => "",
               
"mark" => "",
               
"max" => "",
               
"1147" => "Rune platebody"
               
);
 
$curlh curl_init();
 
curl_setopt($curlhCURLOPT_URL'http://itemdb-rs.runescape.com/viewitem.ws?obj=' array_search($_GET['id'],$item));
 
curl_setopt($curlhCURLOPT_RETURNTRANSFERtrue);
 
$src curl_exec($curlh);
 
curl_close($curlh);
 
ereg('<b>Minimum price:</b> ([0-9\.km,]+)'$src$item['min']);
 
ereg('<b>Market price:</b> ([0-9\.km,]+)'$src$item['mark']);
 
ereg('<b>Maximum price:</b> ([0-9\.km,]+)'$src$item['max']);
 echo 
'
 <strong>Minumim:</strong> ' 
$item['min'][1] . '<br />
 <strong>Market:</strong> ' 
$item['mark'][1] . '<br />
 <strong>Maximum:</strong> ' 
$item['max'][1] . '<br />';
 }
?>
<form method="get">
Name: <input type="text" name="id" />
<input type="submit" />
</form>
__________________
Jerry Broughton

Last edited by job0107; 06-09-09 at 02:39 AM.
Reply With Quote
  #3 (permalink)  
Old 06-09-09, 07:03 AM
Schmidty102 Schmidty102 is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks

I have one more problem with this. The User is likely to search up lets say rune platebody in many ways...
Rune Platebody
rune platebody
Rune platebody
rune Platebody

I know it is weird... but we are dealing with kids... so would I have to create 4 arrays just for rune platebody? Or can I set it to where caps don't matter?

Edit:

I will also be needing to add hundreds of more items and ids to this. Would I do it under the same array, or make a new array for each item?

Last edited by Schmidty102; 06-09-09 at 07:11 AM.
Reply With Quote
  #4 (permalink)  
Old 06-09-09, 05:04 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
You could use all lowercase names in your array, then use;
PHP Code:

//change id to lowercase;
$id strtolower($_GET['id']);

$item = array(
               
"min" => "",
               
"mark" => "",
               
"max" => "",
               
"1147" => "rune platebody"
               
);

array_search($id,$item); 
Edit: just add your new items under 1147 using the same format. It needs to be all in the same array.
Reply With Quote
  #5 (permalink)  
Old 06-09-09, 10:35 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Yes, you want to do exactly what jcbones said to do.
Change all the item names in your array to lower case.
Then the kids can have all the fun they want with upper and lower case letters.

So after making the modifications your code would look like this"

PHP Code:

<?php
if($_GET['id'])
{
 
$item = array(
               
"min" => "",
               
"mark" => "",
               
"max" => "",
               
"1147" => "rune platebody"
               
);
 
$curlh curl_init();
 
curl_setopt($curlhCURLOPT_URL'http://itemdb-rs.runescape.com/viewitem.ws?obj=' array_search(strtolower($_GET['id']),$item));
 
curl_setopt($curlhCURLOPT_RETURNTRANSFERtrue);
 
$src curl_exec($curlh);
 
curl_close($curlh);
 
ereg('<b>Minimum price:</b> ([0-9\.km,]+)'$src$item['min']);
 
ereg('<b>Market price:</b> ([0-9\.km,]+)'$src$item['mark']);
 
ereg('<b>Maximum price:</b> ([0-9\.km,]+)'$src$item['max']);
 echo 
'
 <strong>Minumim:</strong> ' 
$item['min'][1] . '<br />
 <strong>Market:</strong> ' 
$item['mark'][1] . '<br />
 <strong>Maximum:</strong> ' 
$item['max'][1] . '<br />';
 }
?>
<form method="get">
Name: <input type="text" name="id" />
<input type="submit" />
</form>
__________________
Jerry Broughton
Reply With Quote
  #6 (permalink)  
Old 06-10-09, 10:07 PM
Schmidty102 Schmidty102 is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you thank you thank you!

Edit: if you read what I had just posted earlier please just ignore it. I found a whole list of items and their ids which will make my job much easier now.

There is one thing I would like to be able to do though...
I would like to be able to grab the item description and the item picture from the runescape web page...
Here is a webpage that you can look at:
http://itemdb-rs.runescape.com/viewitem.ws?obj=50
Item = Shortbow (u) ; Description = I need to find a string for this. ; Image = the one to the right... http://itemdb-rs.runescape.com/2659_obj_big.gif?id=50

Thanks again.

Last edited by Schmidty102; 06-10-09 at 10:18 PM.
Reply With Quote
  #7 (permalink)  
Old 06-11-09, 12:05 PM
Schmidty102 Schmidty102 is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
I know that each image has the same id as the item, so it should be pretty easy calling the image. If you can help me figure the code out that would be great! I have been messing around with the codes for the past hour and can not figure out how to add the image in.

Thanks again,
Schmidty102
Reply With Quote
  #8 (permalink)  
Old 06-11-09, 06:38 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
How often do you think that the rune platebody price changes? Your script current goes and grabs this information every single time it runs. Why not , if it ain't against the sites' term of service, just scrap all of it once and store it in a database. This way you won't get in trouble if someone starts to have a problem with all the resources this will consume over time.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
  #9 (permalink)  
Old 06-11-09, 08:42 PM
Schmidty102 Schmidty102 is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
This isn't just grabbing rune platebody. It is grabbing over 3k item prices... and most items change price every hour. It is not against term of use, I have already been in contact with Jagex (the owners) and many other website currently do similar things. (They just won't help me) It uses less of my resources grabbing the prices as needed. If it were to update hourly, I would quickly use up my bandwidth... and so would the other sites I am letting use this code.
Reply With Quote
  #10 (permalink)  
Old 06-12-09, 09:07 PM
Schmidty102 Schmidty102 is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
i still need help if anyone can help me.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Superfish jquery menu problems with modification transcend2005 CSS 2 03-25-09 01:30 AM
display mysql data in columns? todayscoffee PHP 4 03-11-09 10:05 PM
Trouble with positioning naviboard BlueDragoness HTML/XHTML/XML 1 01-12-08 06:42 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM


All times are GMT -5. The time now is 08:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.