Quote:
Originally Posted by Turbocharged_06
im trying to learn php and was trying to display some info from my mysql tutorials table
PHP Code:
<?php
$mysqlhost = "localhost";
$mysqluser = "user";
$mysqlpass = "pass";
$mysqltable = "table";
mysql_connect( $mysqlhost , $mysqluser ,$mysqlpass ) or die ("Could not Connect");
mysql_select_db ( $mysqltable ) or die ("could not select db $mysqltable")
$sql = (" SELECT * FROM tutorials WHERE 1=1; ");
$result = mysql_query($sql);
echo $result;
?>
i got the error
HTML Code:
parse error: syntax error, unexpected T_VARIABLE in /home/outlbnet/domains/outlaw-web.net/public_html/teest2.php on line 9
|
What you want to show from the database? First of all, this will only output(if it would work) 1 or 0... This will output the query RESULT with the query #id... For getting all rows it selected with the query, and set it into a var, you can use mysql_fetch_assoc($var_with_query). And second: You call into the mysql_select_db a TABLE and also one which have not been set into the var yet, caus the variable is defined LATER than it's called... So this should it be:
Quote:
<?php
mysql_connect("localhost", "user", "password");
mysql_select_db("database_name");
$result = mysql_query(" SELECT * FROM tutorials WHERE 1=1; ");
while($row = mysql_fetch_assoc($result)) {
echo $row['field'];
}
?>
|
where 'field' is the field you want to show, take for example: Inside the table 'tutorials' you have the follow fields:
name author text
and there's 1 row found with the query which have this values in the fields in the table tutorials:
name: Test tutorial
author: Noone
text: test
and you want to show the value of the field 'name' (in this case that's "Test Tutorial" as you can see above) then you can do that like this:
Quote:
<?php
mysql_connect("localhost", "user", "password");
mysql_select_db("database_name");
$result = mysql_query(" SELECT * FROM tutorials WHERE 1=1; ");
while($row = mysql_fetch_assoc($result)) {
echo $row['name'];
}
?>
|
I hope you understand it some better now

Good luck!