PDA

View Full Version : selecting a simple row!!


RenegadeLeader
10-16-2003, 06:36 AM
:mad: :mad: :mad: :mad: :mad: :mad:
Omg, i cant get this stupif script to work! Im trying to select a simple row, and print it, and it doesnt work! WHY! heres the table:

TipID TipDesc
1 Tip


So how would i select!! Heres the script i use:
(Yes, its saved as a .php file)

<html>
<head>
</head>
<body bgcolor="#000000">
<font color="#CC0000">
<?PHP

$db = mysql_connect("localhost", "user", "pass") or die("Couldnt Connect!!");
print "Success!";

mysql_select_db("misc", $db) or die("couldnt connect to DB!!");
print "success-db";

'SELECT *
FROM t1p WHERE TipID = 1';



mysql_close($db);



?>
</font>
</body>
</html>

Kevinnaia
10-16-2003, 10:29 AM
Originally posted by RenegadeLeader

<body bgcolor="#000000">

'SELECT *
FROM t1p WHERE TipID = 1';

mysql_close($db);

?>


It should be:


<?PHP

$db = mysql_connect("localhost", "user", "pass") or die("Couldnt Connect!!");

print "Success!";

mysql_select_db("misc", $db) or die("couldnt connect to DB!!");

print "success-db";

$result = mysql_query("SELECT * FROM t1p WHERE TipID = '1'");

$rs = mysql_fetch_array($result);

echo $rs;

mysql_close($db);

?>


If you see the mistake, you were missing a the entire mysql_query string to open the quote in the select string

Kevin Naia

RenegadeLeader
10-16-2003, 11:11 AM
Only thing i get is:
Success!
success-db
Array

Kevinnaia
10-16-2003, 04:48 PM
sorry about that, I wasnt paying attention

this is the right code:

<?PHP
$db = mysql_connect("localhost", "user", "pass") or die("Couldnt Connect!!");
print "Success!";
mysql_select_db("misc", $db) or die("couldnt connect to DB!!");
print "success-db";
$result = mysql_query("SELECT * FROM t1p WHERE TipID = '1'") or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)){
echo "\t<a href=\"".$row['column']."\" title=\"".$row['column']."\" target=\"_blank\">".$row['column']."</a><br />";
}
mysql_close($db);
?>


Where it says: ".$row['column']." you have to change "column" to the name of the field you want to display, and you can take out the link thing, I put it there as an example, but leave the \t thing there.

HTH,
Kevin Naia