Forum Moderators: coopster
So far my script is:
<?
$username="root";
$password="*****";
$database="tabs";mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM tabs WHERE $_POST['keyword'] IN ('songname','artistname')";
mysql_query($query);
$key = '$_POST['keyword']';
$result = mysql_query("select * from table where column regexp '$key'", $connect) or die ("query 1: " . mysql_error());
$mysql_num = mysql_num_rows($result);
if ($mysql_num >= 1)
{echo 'query successful, display results in a loop';}
else
{echo 'query failed, post for more help.';}
try that and let me know how it goes.
$result = mysql_query("select * from tabs where songname regexp '$key' OR artistname regexp '$key'") or die ("query 1: " . mysql_error());
now i want to display info of the results that match in a table that has columns for Song, Artist, Version, Guitar Type, Tab Type
so how would i go about doing that?
while ($row = mysql_fetch_array($result))
{
echo $row['song'].''.$row['artist'].''.$row['version'].''.$row['guitar'].''.$row['type'].''.$row['tab type'];
}
just make sure that the variables are all correct(names of your columns) and that should work for you.
need anything else let me know.
Dylan
I am not sure what is better code though
If you initialize the variable to "" at the top of the script so it has a known value in all cases, then both are equivalent and #1 saves you a function call.
If you do not initialize the variable you are counting on PHP default values and will get an undefined variable notice if you display notices; I prefer not to count on default values.
<?
$username="root";
$password="*****";
$database="tabs";
$key = $_GET['id'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query("select * from tabs where id regexp '$key'") or die (mysql_error());
$row = mysql_fetch_array($result);
what would i use to change the value of the views column for the id that is being displayed?
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query("select * from tabs where id regexp '$key' UPDATE tabs SET views = '$row[views] + 1' WHERE id = $id") or die (mysql_error());
$row = mysql_fetch_array($result);
$sql = "UPDATE tabs SET views = '$views' WHERE id = $id";
mysql_query($sql)
its not working...
$result = mysql_query("select * from tabs where id regexp '$key' UPDATE tabs SET views = '$row[views] + 1' WHERE id = $id") or die (mysql_error());
$row = mysql_fetch_array($result);
$sql = "UPDATE tabs SET views = '$views' WHERE id = $id";
you have the update script input twice.
Im not sure if this will work, but just cut out the 1st update script like so
$result = mysql_query("select * from tabs where id regexp '$key'") or die (mysql_error());
$row = mysql_fetch_array($result);
$sql = "UPDATE tabs SET views = '$views' WHERE id = $id";
Also, here
"select * from tabs where id regexp '$key'"
I dont see people searching your site for the id of the item, I may be wrong but just to bring this to your attention, may want to change the column name to query.
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query("select * from tabs where id regexp '$key'") or die (mysql_error());
$row = mysql_fetch_array($result);
$newview = $row['views'] + 1;
$sql= "UPDATE tabs WHERE id = $key SET views = $newview";
mysql_query($sql);
any ideas?
here the script again:
<?
$username="root";
$password="*****";
$database="tabs";
$key = $_GET['id'];mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query("select * from tabs where id regexp '$key'") or die (mysql_error());
$row = mysql_fetch_array($result);
mysql_query("UPDATE tabs where id = $id SET views = views+1");
?>
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query("select * from tabs where id regexp '$key'") or die (mysql_error());
$row = mysql_fetch_array($result);
$newview = $row['views'] + 1;
$sql= "UPDATE tabs SET views = $newview WHERE id = '$key'";
mysql_query($sql);
If not please respond and I will see what I can do.
$result = mysql_query("select * from tabs where id regexp '$key'") or die (mysql_error());
$row = mysql_fetch_array($result);
$query = "UPDATE tabs SET views = views + 1 " .
"WHERE id = '$key'";
mysql_query($query);
mysql_close()
?>
Now I need a script that displays the last 20 entries in the database... I know what the search things would be but how would I limit the display to only 20?