Note that there are some explanatory texts on larger screens.

plurals
  1. POUse MYSQL data via PHP in cocoa-touch?
    text
    copied!<p>I've created a working app for the iPhone which grabs data from a MYSQL database via a PHP page, then prints the data in a UIWebView.</p> <p>But the issue here is that I no longer want to print the data in a UIWebView, I want to retrieve the data and pull it back into the app, to change a UILabel.text to the MYSQL data.</p> <p>I currently have the following (which prints the data into a UIWebView (excluding most code due to DB connection passwords etc)):</p> <p><strong>PHP FILE:</strong></p> <pre><code> // Localize the GET variables $name = isset($_GET['name']) ? $_GET['name'] : ""; // Protect against sql injections $name = mysql_real_escape_string($name); $cash = "SELECT cash FROM t_users WHERE username='$name' LIMIT 1"; $result = mysql_query($cash,$conn); if(!$result) { die("Error retrieving scores " . mysql_error()); } ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/&gt; &lt;/head&gt; &lt;body&gt; &lt;?php // Display the table while ($row = mysql_fetch_object($result)) { echo ''.$row-&gt;cash.''; } mysql_free_result($result); mysql_close($conn); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>PlayerInfo.m</strong></p> <pre><code>-(IBAction)refreshData:(id)sender { test1AppDelegate *mainDelegate = (test1AppDelegate *)[[UIApplication sharedApplication] delegate]; NSString * login_key = @"REMOVED FOR STACKOVERFLOW"; NSString * username = [mainDelegate.currentUser stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *urlString = [NSString stringWithFormat:@"REMOVED FOR STACKOVERFLOW/put_score.php?login_key=%@&amp;name=%@", login_key,username]; NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [self.webview loadRequest:requestObj]; } </code></pre> <p>This changes shows the players CASH in the webview, but I want to change a UILabel to display the cash figure.</p> <p>Please help?</p> <p>Thank you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload