$sql=mysql_query("SELECT * FROM tags WHERE name LIMIT 0 , 30"); $row=mysql_fetch_array($sql); Test <? echo $row ?> PHP: if i use this error i get the following error any reason or syntax error
It appears as if you haven't established a connection to the database. Also, since mysql_fetch_array() returns an array you can't echo it. <? $dbhost = "localhost"; $dbuser = "username"; //replace with a valid username $dbpass = "password"; //replace with a valid password $dbname = "database" //replace with the name of a database you have already created mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname); $sql=mysql_query("SELECT * FROM tags WHERE name=Daniel LIMIT 0 , 30"); while($row=mysql_fetch_array($sql)){ echo $row[0]." ".$row[1]." ".$row[2]; //you replace this with what you want to do with the data } ?> Code (markup):
$sql=mysql_query("SELECT * FROM tags WHERE name LIMIT 0 , 30"); must be where name=something Your SQL query is incorrect.
previously i had closed the mysql connection before using fetch_array and query no i get this error $sql=mysql_query("SELECT * FROM tags WHERE name LIMIT 0 , 30"); while($row=mysql_fetch_array($sql)) { echo $row[0]; //you replace this with what you want to do with the data } ?> PHP:
<?php function dbconnect() { $link = mysql_connect( $host, $user, $pass ); if (! $link ) die("Couldn't connect to MYSQL"); mysql_select_db( $database, $link) or die("Couldn't open $database: ".mysql_error() ); } ?> PHP: Just call this function whenever you need to connect. And yeah don't forget to edit the variables with your database settings.
I did not notice, when you use WHERE you must use an equal (=): SELECT * FROM tags WHERE name=debt LIMIT 0,30 // which would return all the rows in which the name is debt. SELECT * FROM tags WHERE 1=1 LIMIT 0,30 //would return every row in the table.