Jump to content

Code syntax


doodlebug

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?
Link to comment
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.