Hi there, I am creating a PHP form that when the user inputs some data, it will format it a specific way. So far the user has to input both the auction title and the auction number. I am trying to find out how to make my form just have one field for the auction number, and that when the user inputs the auction number, the php script goes to http://www.trademe.co.nz/Browse/Listing.aspx?id=xxxxxxxxx (xxxxxxxxx being the auction number) and will then bring the auction title back and display it. Eg: When the user types in the auction number as 221433345, the script will go to http://www.trademe.co.nz/Browse/Listing.aspx?id=221433345 and bring back the auction title "OKTA Mondo - Telecom - As New" Is this possible? Thanks in advance, I'm really not that familiar with PHP.
I think It is only possible if u have access to trademe.'s Database. then u can look for Title field (if they have one in their database) and display it.. I m beginner in PHP, Better wait for Expert's Reply .Take Care..
Yes, this is possible. Do you need code samples? Can you share your code, so we can provide feedback? Also, would you prefer to have SEO links? For example, the user types 221433345 and the URL is http://www.trademe.co.nz/Browse/OKTA_Mondo_-_Telecom_-_As_New
Thanks Social.Network There doesn't need to be a link, it is just a packing slip tool that I would use to enter their address and the prices etc, but instead of typing the auction title, I wondered if I could retrieve it automatically. To put it even simpler, when the user types in auction 221433345, it will retrieve the auction title and display it eg: echo "$auctiontitle"; or something of the like. So the static form is like this: <form action="process.php" method="post"> Auction Number: <input type="text" name="auction_number" /> <input type="submit" /> </form> HTML: Then process.php would be similar to: <?php something would go here that would retrieve the auction title and allow me to use it as $auction_title... echo "$auction_title ($auction_number)"; ?> PHP: Like I said before, I'm new to PHP and wouldn't have a clue how to do this so any help would be much appreciated. Thanks in advance.
Let's start with the form. The form has one input field, named "auction_number". When the user clicks the "submit" button it will use the POST method to send the information to the "process.php" page. Simple enough. In the process.php page, you need to collect the information that was submitted on the form page. I will not get into the POST and GET methods, so I will keep this simple. Use the PHP $_POST Function to get the value of the Auction Number and select the auction details from the database as follows: process.php (excuse typos and syntax) <?php // Get auction number entered on static form $auction_number = $_POST["auction_number"]; // Connect to database and select auction details $con = mysql_connect("{host}","{username}","{password}"); if (!$con) { die('Could not connect to database: ' . mysql_error()); } mysql_select_db("{database}", $con); $sql = "SELECT * FROM Auctions WHERE AuctionNumber = " . mysql_real_escape_string ($auction_number); $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo $row['AuctionTitle'] . " " . $row['Description']; echo "<br />"; } mysql_close($con); ?>
All good until I saw the part about mysql... I don't have any access to this, and I would never get it. Is there any way to extract the text between the tags in the source of the auction page? <h1 id="ListingTitle_title">OKTA Mondo - Telecom - As New </h1> Can PHP extract the text between <h1 id="ListingTitle_title"> and </h1> Thanks for your help so far.
The answer to your question is yes, but I guess I need to know a bit more about the problem. Do you own or have access to the auction site source code and database? If not, are you a "seller" that uses the site? If so, I am going to make an assumption here: The auction site does not provide packing slip tools for sellers, so you want to develop a solution. Correct? Lastly, we can definitely fetch and extract the information. If you can answer the above, I will provide another sample (tomorrow, because it is 2:30am and I have to work in the morning).
That is exactly correct! I am a seller on the site, and the current packing slip tool doesn't meet today's standards. Thanks for your work so far. I don't have a real time frame for this project so tomorrow is all sweet by me. Once again, thanks for your help so far!
How about something like this? <?php $iId = '221433344'; $sUrl = 'http://www.trademe.co.nz/Browse/Listing.aspx?id=' . $iId; $sPage = file_get_contents($sUrl); preg_match('/<h1 id="ListingTitle_title">(.*?)<\/h1>/s', $sPage, $aTitle); $sTitle = trim(html_entity_decode($aTitle[1])); echo $sTitle; // OKTA Mondo - Telecom - As New ?> PHP:
Thanks clarky It's working great, but I have a problem... My source is: <?php $id = '214668730'; $url = 'http://www.trademe.co.nz/Browse/Listing.aspx?id=' . $id; $page = file_get_contents($url); preg_match('/<h1 id="ListingTitle_title">(.*?)<\/h1>/s', $page, $pre_title); $title = trim(html_entity_decode($pre_title[1])); preg_match('/<li id="ListingTitle_auctionTitleBids">Winning bid: (.*?)<\/li>/s', $page, $pre_price); $price = trim(html_entity_decode($pre_price[1])); preg_match('/<ul id="AuctionSaleDetail_ShippingDetailsList"><li>(.*?) /s', $page, $pre_shipping_price); $shipping_price = trim(html_entity_decode($pre_shipping_price[1])); preg_match('/0 (.*?)<\/li><li>/s', $page, $pre_shipping_method); $shipping_method = trim(html_entity_decode($pre_shipping_method[1])); $total = $price + $shipping_price; echo $title; echo $price; echo $shipping_price; echo $shipping_method; echo $total; ?> But the total shows as 0, which I think is to do with the dollar sign in front of the values. What do I do to fix this? Thanks in advance.
if the 'id' is supposed to be a user entered number, and if you dont have access to MySQL .. ever consider an IF / ElseIf / Else ? If there's not a lot of id numbers - then do an if($id="1234){ do what you gonna do or give a HTTP header location } ; you can substitute a Database sometimes with a .txt file and fopen / fread etc work around.
That doesn't matter. All I want to do is find away to add values with a dollar sign in them using php.
The problem is the price and shipping price values include the escaped dollar sign as follows: $price = "\$156.00" $shipping_price = "\$156.00" You can fix the problem by modifying the match pattern as follows: preg_match('/<li id="ListingTitle_auctionTitleBids">Winning bid: \$(.*?)<\/li>/s', $page, $pre_price); $price = trim(html_entity_decode($pre_price[1])); preg_match('/<ul id="AuctionSaleDetail_ShippingDetailsList"><li>\$(.*?) /s', $page, $pre_shipping_price); $shipping_price = trim(html_entity_decode($pre_shipping_price[1]));
Thanks Social.Network it worked great. Just one other question, how can I force my $total sum to have two decimal places? It just makes it as simple as possible which doesn't look right. For example, if the purchase price was $100, and the shipping price was $7.60, the total is shown as $107.6 And if the shipping price is a whole number like $5, it is just shown as $105 Thanks for your help so far!
There are a couple of methods, such as number_format, money_format, and others. Here is an example using number_format: echo number_format($total, 2);