Jump to content

will_1990

Members
  • Posts

    133
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

will_1990's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi All, Its been a while since i've posted, its good to be back. I am currently trying to pull two exchange rates against the $ using YQL's restful url. Unfortunately I am having a huge problem returning the results correct.... currently my array will only output a single rate (instead of two) and the hash array returns with the base rate name rather than the expected currency code. I hope someone can help me sort this as it's given me quite a headache! Please see the code below: <?php require_once('uwe_proxy.php'); /* * To change this template, choose Tools | Templates * and open the template in the editor. */ # use the yahoo YQL rest service to return any number of rates in a hash function get_yahoo_rest_rate ($base, $curr_arr) { $params = ''; $rates = array(); # define the YQL rest url head & tail $yql_base_uri = "http://query.yahooapis.com/v1/public/yql"; $yql_tail_uri = '&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys'; # build up the $params value foreach($curr_arr as $curr) { $params .= $curr.$base.','; } #strip last comma $params = substr($params, 0, -1); # build the query with the params as comma sep. string eg. USDGBP,USDBOB,.. $yql_query = "select * from yahoo.finance.xchange where pair IN ('{$params}')"; # build the the complete YQL query $yql_query_url = $yql_base_uri . "?q=" . urlencode($yql_query) . $yql_tail_uri; # send the query via proxy and get as string and load as simplexml object $yql_response = @simplexml_load_string(file_get_contents_proxy($yql_query_url)); Print_r($yql_query_url); //- debugging only # process simplexml object and return a sorted hash of rates or FALSE on error if ($yql_response) { foreach($yql_response->results->rate as $rate) { if ((float)$rate->Rate>0) { $rates[substr((string)$rate->attributes()->id, -3)] = (float)$rate->Rate; } } ksort($rates); return $rates; } else { return FALSE; }// print_r($yql_response); - debugging only } /////// - debugging only $curr_arr = array('GBP','GBP'); $rates = get_yahoo_rest_rate ('USD', $curr_arr); //PRINT_R($yql_response); print_r($rates); ?> Sorry about dumping the whole lot - but I really don't know where this is going wrong! Thanks in Advance for any help or pointers in the right direction!
  2. Hi everyone, I have the need to create a dropdown list and when an item is selected I would like to start a file download via a h ref link eg h ref "http://server1/sadf/file.xls" Is this even possible - I have read that it may not be possible to use a h ref in an options list as obviously they are normally used to pass information in a form to the server. Am I going about this the wrong way? Any advice would be greatly appreciated or any other alternatives! Many thanks, Will
  3. If you mean take it outside the if statement then it still only prints the final $ID that is collected ie - the last check box that is clicked. This also happens if i leave the array within the if statement and the print outside the statement. However, if i have both of them in there it functions correctly and both are printed. I thought that once an array has stored the data remains there despite being in the loop or not..... :S Any more thoughts im still completely stuck on this!
  4. Hello and thanks for looking! I have stored an looped variable into an array which is in an if statment. The problem im having is that if i echo the array results outside of the loop i do not get the full array just the last entry. I have tried imploding the array frist but the same result occours - here is my code and where i have got to so far... My aim is to get the array result sent accross a form so it can be written to a text file.... <form name="info" method="post" action="write_ffdb1.php"> <table border="1" border-color="black"> <tr> <td> Product Number</td> <td> Product Price </td> </tr> <?php $test; if(!($lines = file('php_ffdb.txt'))) {echo 'ERROR: Unable to open file! </body></html>'; exit;} foreach ($_POST as $ID2 => $price) { foreach($lines as $theline) { list($ID, $title, $author, $description, $price, $image) = split('\|',$theline); if($ID==$ID2) { echo " <tr> <td>$ID</td> <td>$price</td> </tr> "; $array [7] = "$ID"; $comma_separated = implode(",", $array); echo ("$comma_separated"); // This displays what i want eg 1,2,3, etc but does not work ouside of the if statement (see below) $test=$comma_separated; $novatprice += $price; echo ("<input type='hidden' name='$comma_separated'> "); - //i have used this to try and send it to my other form.. } } echo("$test"); // this only returns the final looped $ID rather than 1,2,3 ETC I would LOVE any advice or reccomendations on how to do this, any way possible!! thanks for any help or words of wisdom!! Will
  5. Hello! I am trying to send a variable that is updated 'x' amount of times depending on the number of check boxes that are selected. eg a someone can selected two items and the unique id will be posted twice here: <?php if(!($lines = file('php_ffdb.txt'))) {echo 'ERROR: Unable to open file! </body></html>'; exit;} foreach ($_POST as $ID2 => $price) { foreach($lines as $theline) { list($ID, $title, $author, $description, $price, $image) = split('\|',$theline); if($ID==$ID2) { echo " <tr> <td>$ID</td> <td>$price</td> </tr> However, i want to post these ids off to a text file and it only picks up the final one selected. currently i am using this code: <input type=hidden name=ID value=$ID2> But if i echo $ID2 it gives me ids, 1, 2, 7 for example but it would only print 7 in the text file. Here is what i am using to write to a text file: <?php $myFile = "purchases.txt"; $fh = fopen($myFile, 'a') or die("can't open file\n"); if(is_readable($myFile)) { echo "<p>File is readable </p>";} else { echo "<p>File is Not readable</p>"; } if( is_writable($myFile)) {echo "<p>File is writable </p>";} else { echo "<p>File is Not writable</p>";} $Name=$_POST['Name']; $Email=$_POST['Email']; $Price=$_POST['Price']; $ID=$_POST['ID']; $content =$Name."|".$Email."|". $Price."|".$ID."\n"; if(!(fwrite($fh , $content))) { echo "<p>Cannot write to file ($myFile)\n</p>"; exit; } else { echo "<p>Data written</p> <a href='purchases.php' >Return to Purchases</a>"; fclose($fh); } ?> I have no idea how to force this to either store each ID seperately so i can then export them separtely or store them all togeather to export them togeather... ANY hints or tips would be much appreciated!!! Sorry if i have not explain this well, im a bit of a newbie!! Many thanks in advance Will
  6. Solved this! Great thanks for your help, i wasnt aware of the += operator, thanks! Is there a way to ensure that if 1.00 and 1.00 were added it would return 2.00 instead of 2? Here is how i changed the code: <?php if(!($lines = file('php_ffdb.txt'))) {echo 'ERROR: Unable to open file! </body></html>'; exit;} foreach ($_POST as $ID2 => $price) { foreach($lines as $theline) { list($ID, $title, $author, $description, $price, $image) = split('\|',$theline); if($ID==$ID2) { echo " <table> <tr> <td> $price</td> <td>$ID</TD> </TABLE> "; $var += $price; } } } echo ("$var"); ?> Thanks very much for your help!!
  7. cheers for the quick reply, im looking into moving the for loop just thought id post this first - i am posting just the id i thought id use a short cut and have the name of the check box the $ID tag as thats all i need as its unique to each entry.... <?php if(!($lines = file('php_ffdb.txt'))) {echo 'ERROR: Unable to open file! </body></html>'; exit;} foreach($lines as $theline) { list($ID, $title, $author, $description, $price, $image) = split('\|',$theline); echo " <tr align='center'> <td><img src='$image' width='82' height='125'></td> <td align='center'>$ID. $title <br><font face='arial' size='1'>$description</font>£$price </td> <td> <input type='checkbox' name='$ID'><br></td> </tr> "; } ?> Here is my flat file database - dont believe i have to use this sql would be far better.. but it cant be helped! 1|The Lovely The Lovely Bones|Alice Sebold|<b>RRP:</b>£1.97<br><b>You Save:</b> £3.02 (61%) <br><b>Price:</b> |3.00|images/TLB.jpg 2|The Girl with the Dragon Tattoo|Stieg Larsson|<b>RRP:</b>£3.48<br><b>You Save:</b>£4.51 (56%)<br><b>Price:</b>|3.00|images/TGWDT.jpg 3|Mums Know Best|Dave Myers|<b>RRP:</b> £20.00<br><b>You Save: </B> 4.13 (52%)<br><b>Price:</b> |3.50|images/MKB.jpg 4|The Girl Who Played with Fire|Stieg Larsson|<b>RRP:</b> £7.99<br><b>You Save: </B> £4.51 (56%)<br><b>Price:</b> |1.98|images/TGWPWF.jpg 5|Breaking Dawn (Twilight Saga)|Stephenie Meyer|<b>RRP:</b> £14.99 <br><b>You Save: </B> £7.50 (50%)<br><b>Price:</b>|7.50|images/BD.jpg 6|101 One-pot Dishes|Good Food Magazine|<b>RRP:</b> £4.99 £1.97<br><b>You Save:</B> £3.02 (61%)<br><b>Price:</b>|1.97|images/GF.jpg 7|Eclipse (Twilight Saga)|Stephenie Meyer|<b>RRP:</b> £7.99 <br><b>You Save: </B> £4.53 (50%)<br><b>Price:</b>|3.46|images/Eclipse.jpg Will
  8. Hello all, long time no post! I have missed php!! Thanks in advance for any advice!! I am trying to add an updating price variable to 0 to give a total price, eg someone selects how many items they want, these are listed and the total price is added, however it seems to keep giving me the final price of the last item in my flat file database - whether or not it is selected as an item.... here is my code! <?php $var=0; foreach ($_POST as $ID2 => $price) { if(!($lines = file('php_ffdb.txt'))) {echo 'ERROR: Unable to open file! </body></html>'; exit;} foreach($lines as $theline) { list($ID, $title, $author, $description, $price, $image) = split('\|',$theline); if($ID==$ID2) { echo " <table> <tr> <td> $price</td> <td>$ID</TD> </TABLE> "; } } $sum=$var + $price; echo("$sum"); } ?> Any advice would be great!! Thanks!!! Will
  9. I have a three queries that are running but the 2nd one is not updating a dateback fie;d but the next part which inserts a new row in the same table. can anyone see what the problem could be? thanks! //query $q1 = ("SELECT BcId, BorId, DateOut from Loan WHERE BcId = '$bcid' AND BorId ='$bid' AND DateOut ='$do'"); $res1 = mysql_query($q1) or die (mysql_error()); if ($res1){ [b] $q2 = ("UPDATE Loan SET DateBack = CURDATE() WHERE BcId = '$bcid' AND BorId = '$bid' AND DateOut ='$do'"); $res2 = mysql_query($q2) or die (mysql_error()); }[/b] if ($res2) { //If it ran ok. $q3 = "INSERT INTO Loan (BorId, BcId, DateOut, DateDue, DateBack) VALUES ('$bid', '$bcid', CURDATE() , ADDDATE(CURDATE(), INTERVAL 2 MONTH), NULL)"; $res3 = mysql_query($q3) or die (mysql_error());} // Print message below: if ($res3) { $q2 = ("UPDATE Loan SET DateBack = CURDATE() WHERE BcId = '$bcid' AND BorId = '$bid' AND DateOut ='$do'"); $res2 = mysql_query($q2) or die (mysql_error()); } if ($res2) { //If it ran ok. - this is the one not updating correctly! thanks!
  10. This is the query that does not work but works in php with static data instead of variables: $sql = "SELECT bt.BtId, bt.BtName, BookCopy.BcId, PubName, AuthorId, AuthorName' . ' FROM BookTitle AS bt' . ' CROSS JOIN BookCopy USING (BtId)' . ' CROSS JOIN Loan USING (BcId)' . ' CROSS JOIN Publisher USING (PubId)' . ' CROSS JOIN Authorship USING (BtId)' . ' CROSS JOIN Author USING (AuthorId)' . ' WHERE' . ' Loan.DateBack IS NOT NULL' . ' AND' . ' bt.BtName LIKE \'%Harry%\' AND Author.AuthorName LIKE \'%row%\' LIMIT 0, 30 '; $result = mysql_query($sql) or die(mysql_error()); i have swapped this for these variables: . ' bt.BtName LIKE \'%$bn%\' AND Author.AuthorName LIKE \'%$an%\' LIMIT 0, 30 '; However apparantly its not parsed without double quotes - so i tried this: $sql = "SELECT bt.BtId, bt.BtName, BookCopy.BcId, PubName, AuthorId, AuthorName' . ' FROM BookTitle AS bt' . ' CROSS JOIN BookCopy USING (BtId)' . ' CROSS JOIN Loan USING (BcId)' . ' CROSS JOIN Publisher USING (PubId)' . ' CROSS JOIN Authorship USING (BtId)' . ' CROSS JOIN Author USING (AuthorId)' . ' WHERE' . ' Loan.DateBack IS NOT NULL' . ' AND' . ' bt.BtName LIKE \'%$bn%\' AND Author.AuthorName LIKE \'%$an%\' LIMIT 0, 30 "; $result = mysql_query($sql) or die(mysql_error()); but now i get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' . ' CROSS JOIN BookCopy USING (BtId)' . ' CROSS JOIN Loan USIN' at line 1 I have no idea what i need to do to make this work!!! Any advice/help that gets me a little further will be greatly appreciated!!
  11. Is this how its meant to be? . ' bt.BtName LIKE \'%"$bn"%\' AND Author.AuthorName LIKE \'%"$an"%\' LIMIT 0, 30 ';
  12. Despite being able to get the query to work sucessfully in phpmyadmin with static data, when i swap this out for my variable input this does not work. this works in phpmyadmin and returns the expected data on the webpage. $sql = 'SELECT bt.BtId, bt.BtName, BookCopy.BcId, PubName, AuthorId, AuthorName' . ' FROM BookTitle AS bt' . ' CROSS JOIN BookCopy USING (BtId)' . ' CROSS JOIN Loan USING (BcId)' . ' CROSS JOIN Publisher USING (PubId)' . ' CROSS JOIN Authorship USING (BtId)' . ' CROSS JOIN Author USING (AuthorId)' . ' WHERE' . ' Loan.DateBack IS NOT NULL' . ' AND' . ' bt.BtName LIKE \'%Harry%\' AND Author.AuthorName LIKE \'%row%\' LIMIT 0, 30 '; However when it is edited to: . ' bt.BtName LIKE \'%$bn%\' AND Author.AuthorName LIKE \'%$an%\' LIMIT 0, 30 '; [/code] the expected output is completely blank. Why is this is there a way to solve this or a work around? Many thanks
  13. Despite being able to get the query to work sucessfully in phpmyadmin with static data, when i swap this out for my variable input this does not work. this works in phpmyadmin and returns the expected data on the webpage. $sql = 'SELECT bt.BtId, bt.BtName, BookCopy.BcId, PubName, AuthorId, AuthorName' . ' FROM BookTitle AS bt' . ' CROSS JOIN BookCopy USING (BtId)' . ' CROSS JOIN Loan USING (BcId)' . ' CROSS JOIN Publisher USING (PubId)' . ' CROSS JOIN Authorship USING (BtId)' . ' CROSS JOIN Author USING (AuthorId)' . ' WHERE' . ' Loan.DateBack IS NOT NULL' . ' AND' . ' bt.BtName LIKE \'%Harry%\' AND Author.AuthorName LIKE \'%row%\' LIMIT 0, 30 '; However when it is edited to: . ' bt.BtName LIKE \'%$bn%\' AND Author.AuthorName LIKE \'%$an%\' LIMIT 0, 30 '; [/code] the expected output is completely blank. Why is this is there a way to solve this or a work around? thanks again
  14. Thank you so much!!!! With a little tweaking i was finally able to perfom the query correctly!! Here is what i used in the end incase you're interested! SELECT bt.BtId, bt.BtName, BookCopy.BcId, PubName, AuthorId, AuthorName FROM BookTitle AS bt CROSS JOIN BookCopy USING (BtId) CROSS JOIN Loan USING (BcId) CROSS JOIN Publisher USING (PubId) CROSS JOIN Authorship USING (BtId) CROSS JOIN Author USING (AuthorId) WHERE Loan.DateBack IS NOT NULL AND bt.BtName LIKE '%Harry%' AND Author.AuthorName LIKE '%row%' Many thanks for all your help!
  15. It doesnt work even with that changed. still get the same error. Thanks all the same.
×
×
  • 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.