Jump to content

Archived

This topic is now archived and is closed to further replies.

doodlebug

Code syntax

Recommended Posts

Hi Board,

I am a newbie to php mysql (hence the posting in this forum). I have done a tiny snippet of code....that does not work, surprise, surprise!!!!

Here's the code
[code]
<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","username","password");
    
//select which database you want to edit
mysql_select_db("dbase name");

$result = my_sql query(SELECT COUNT(DISTINCT user_id));
   AS how_many_users_have_predicted
FROM plpredictionsdata
$result = my_sql query(SELECT COUNT(user_id));
   AS total_users
FROM pluserdata

{    
   $title=$r["pluserdata"];
   $who=$r["plpredictionsdata"];
  
   echo "$title <br> users have predicted out of <br> $who ";
}
?>
[/code]

The table names are 'plpredictionsdata' & 'pluserdata', and i want it to parse a string like the last line on the code (above). One problem is that the table 'plpredictionsdata' currently has 48 lines per user (hence the (DISTINCT user_id)), but i keep getting :
Parse error: syntax error, unexpected T_STRING in /xxxxx/xxxxxxx/public_html/PredictionLeague/test.php on line 9

Any ideas where i have gone wrong?

Share this post


Link to post
Share on other sites
Try this for starters

in the two occasions where you have this

[code]my_sql query[/code]

Replace with this:

[code]mysql_query[/code]

Share this post


Link to post
Share on other sites
Oooops, that was quite an obvious error, changed it, but i still get the same error message:

Parse error: syntax error, unexpected T_STRING in /xxxxx/xxxxxxx/public_html/PredictionLeague/test.php on line 9

Share this post


Link to post
Share on other sites
Try This.

I assume that you are replacing username, password and dbase_name with the appropriate values in the script you are actually running.....

[code]//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","username","password");
    
//select which database you want to edit
mysql_select_db("dbase_name");

$result = mysql_query("SELECT COUNT(DISTINCT user_id)
   AS how_many_users_have_predicted
FROM plpredictionsdata");
$result = mysql_query("SELECT COUNT(user_id)
   AS total_users
FROM pluserdata");

{    
   $title=$r["pluserdata"];
   $who=$r["plpredictionsdata"];
  
   echo "$title <br> users have predicted out of <br> $who ";
}[/code]

Share this post


Link to post
Share on other sites
Yes, you are right in your assumption, i removed them from the post....sorry, should have mentioned that.

Ok, i have amended the code as per the previous post, bow i get an output but it's not parsing the database information in to it. The output can be viewed here [a href=\"http://football-prediction-league.a22.biz/PredictionLeague/test.php\" target=\"_blank\"]http://football-prediction-league.a22.biz/...League/test.php[/a]

As i see it, it is connecting to the database ok, running the script ok, but not generating the required results.

Any other ideas??

P.S. Thanks for your help already, much appreciated

Share this post


Link to post
Share on other sites

×

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.