Current location: Hot Scripts Forums » Programming Languages » PHP » Item Database Issues


Item Database Issues

Reply
  #1 (permalink)  
Old 11-16-09, 09:02 PM
The Knowing The Knowing is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Question Item Database Issues

Alright so I am building an item database; I am having some issues with codes and I figure I could get some help from the users here. You all have proven useful before. Wish I had my old account password.

With my database I need to have my price checker to work with it as well. The code will have to be changed some to work in the database and I am not sure exactly what needs to be changed. If I can get some help it would be greatly appreciated.

Here is the current code:
PHP Code:

<?php

if($_GET['id'])
{
 
$item = array(
               
"min" => "",
               
"mark" => "",
               
"max" => "",
              );
 
$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']);
 
ereg('<img id="item_image"[^<]+',$src,$image); 
 }

          
          
                echo 
$image[0] ;
                echo 
$_GET['id']; <br/> 
                 
    echo 
'
 <strong>Minumim:</strong> ' 
$item['min'][1] . '<br />
 <strong>Market:</strong> ' 
$item['mark'][1] . '<br />
 <strong>Maximum:</strong> ' 
$item['max'][1] . '<br />';
?>
What I need it to do is to get its id from my database. The field id is "Ge_id". So it needs to get Ge_id and post it in the url. I then need it to curl the information and get the three prices.

I next need to store the prices in the database in their fields. "Ge_Minimum, Ge_Market, and Ge_Maximum". I need a timestamp to work somehow to where it checks the price from the database. If it has been less than 12 hours it gets the price from the database. If it has been more than 12 hours it gets the price again and stores it. Then it updates the timestamp. How would I do this?

I believe this is all I need help on for now. Let me know if you need any of my scripts to work to get this working. Thanks in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-16-09, 09:05 PM
The Knowing The Knowing is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
I forgot to mention I need the image part of that script taken out.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-17-09, 09:20 PM
The Knowing The Knowing is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Alright. I found the original code without any of the extras added to it:
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 />';
?>
Now when I have been doing is: changing id to Ge_id and changing $_GET to $row.

I have an issue with this though. I am testing on PHP 5.3.0 ereg is depreciated. What would I use instead of ereg? I have tried a few things but the script just crashes.

Once I get the information I need to have it stored in the database. I know I will have to use the min, mark and max and make them into values for storage. How exactly would I do that and what would the storage script be?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-18-09, 08:20 AM
therocket954's Avatar
therocket954 therocket954 is offline
Community Liaison
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 334
Thanks: 2
Thanked 8 Times in 8 Posts
Here's a good link on switching from the depreciated ereg to preg:
Recipe 13.2 Switching From ereg to preg / PHP CookBook
__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-18-09, 04:32 PM
The Knowing The Knowing is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
That is what I was using. I get different errors when I switch to that. The server this will be on has a few versions older than the latest release. I am going to download that version of php and see if testing works with my code. If it does I will go ahead and finish building the database and then fix the code up when the server is moved to 5.3.0.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 11-18-09, 05:15 PM
The Knowing The Knowing is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
I have the script working now. I still need help on this part:
"I next need to store the prices in the database in their fields. "Ge_Minimum, Ge_Market, and Ge_Maximum". I need a timestamp to work somehow to where it checks the price from the database. If it has been less than 12 hours it gets the price from the database. If it has been more than 12 hours it gets the price again and stores it. Then it updates the timestamp. How would I do this?"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 11-18-09, 07:57 PM
The Knowing The Knowing is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
The timestamp updates on its' own when anything in the row is changed. I have that part done. I have the script that should be posting the info into the database but it isn't working out. Can I get someone to look over it please? Thanks.

PHP Code:

<?php

$con 
mysql_connect('localhost','admin','password');
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }
mysql_select_db('itemdb'$con);

$result mysql_query("SELECT * FROM items");


echo 
'<table>
<tr>
<th>Item</th>
<th>Members</th>
<th>Tradeable</th>
<th>Quest Only Item</th>
<th>Shop Selling Price</th>
<th>Low Alchemy</th>
<th>High Alchemy</th>
<th>Requirements to wield</th>
<th>Wield Slot</th>
<th>Requirements to make</th>
<th>Where to obtain</th>
<th>Examine Info</th>
<th>Other info</th>
<th>Picture</th>
<th>Price</th>
</tr>'
;

while(
$row mysql_fetch_array($result))
  {
  if (
$row["Accepted"]== "Yes") {
  echo 
'<tr>';
  echo 
'<td>' $row['Item'] . '</td>';
  echo 
'<td>' $row['Members'] . '</td>';
  echo 
'<td>' $row['Tradeable'] . '</td>';
  echo 
'<td>' $row['Quest Only Item'] . '</td>';
  echo 
'<td>' $row['Shop Selling Price'] . '</td>';
  echo 
'<td>' $row['Low Alchemy'] . "gp" '</td>';
  echo 
'<td>' $row['High Alchemy'] . "gp" '</td>';
  echo 
'<td>' $row['Requirements to wield'] . '</td>';
  echo 
'<td>' $row['Wield Slot'] . '</td>';
  echo 
'<td>' $row['Requirements to make'] . '</td>';
  echo 
'<td>' $row['Where to obtain'] . '</td>';
  echo 
'<td>' $row['Examine Info'] . '</td>';
  echo 
'<td>' $row['Other Info'] . '</td>';
  echo 
'<td> <img alt="' $row['Item'] . ' " src="http://localhost/item database/images/' $row['Item'] . '.gif"/></td>';
  echo 
'<td>';
  
$time1 $query_result['Ge_updated'];
$time2 time();
$diff = ($time2 $time1)/(60*60);
if(
$diff 12) {
  
$curlh curl_init();

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

$src curl_exec($curlh);

curl_close($curlh);

$item = array();

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

mysql_query("UPDATE items SET Ge_Minimum =" $item['Ge_Minimum'][1] . "WHERE Item =" $row['Item']);
mysql_query("UPDATE items SET Ge_Market =" $item['Ge_Market'][1] . "WHERE Item =" $row['Item']);
mysql_query("UPDATE items SET Ge_Maximum =" $item['Ge_Maximum'][1] . "WHERE Item =" $row['Item']);

echo 
'
<strong>Minimum:</strong> ' 
$item['Ge_Minimum'][1] . '<br />
<strong>Market:</strong> ' 
$item['Ge_Market'][1] . '<br />
<strong>Maximum:</strong> ' 
$item['Ge_Maximum'][1] . '<br />';
}

 else {  echo 
'<strong>Minimum:</strong> ' $row['Ge_Minimum '][1] . '<br />
<strong>Market:</strong> ' 
$row['Ge_Market'][1] . '<br />
<strong>Maximum:</strong> ' 
$row['Ge_Maximum'][1] . '<br />';} '</td>';
  echo 
'</tr>'; }
  }
echo 
'</table>';
mysql_close($con);
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 11-18-09, 10:11 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Put an echo or var_dump on the values returned from the web service.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 11-18-09, 10:44 PM
The Knowing The Knowing is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Ereg is what is posting the information. I need help on storing the information after it is grabbed.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 11-18-09, 10:50 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
ereg has been deprecated. If you use it, in the future, your script will crash, and you or someone else will have to fix it. Use PHP: preg_match - Manual.

Dump out the strings produced by ereg, or better yet, preg_match.

Also - it looks like you need a space before "WHERE" - like so: " WHERE"

Last edited by wirehopper; 11-18-09 at 10:52 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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 02:30 AM
Why won't select list item insert into database? gavacho PHP 2 12-05-08 07:38 PM
Item database site lymia Script Requests 0 12-01-08 05:36 PM
Trouble with positioning naviboard BlueDragoness HTML/XHTML/XML 1 01-12-08 07:42 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 07:02 AM


All times are GMT -5. The time now is 12:18 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.