I'm a PHP and MySQL newbie trying to write a simple query against a table consisting of 2 columns: one with a text string and the second with a date string. The code below returns the first column (the text string) but not the second date string:
<?php
$link = mysql_connect('localhost', 'myuser', 'mypassword');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('archive')or die("cannot select db");
$string = $_POST['keywords'];
$search_query = "SELECT text, date_written FROM archive_table WHERE text LIKE '%$string%'";
$result = mysql_query($search_query,$link);
$rows = mysql_num_rows($result);
if ($rows == 0) {
echo "sorry, I haven’t written about ".$string." yet.";
}
$count = 0;
while ($count < $rows) {
echo mysql_result($result, $count);
echo "\n\n";
$count = $count + 1;
}
mysql_close($link);
?>
I've tried the following code to replace "echo mysql_result($result, $count);", but it returns nothing at all:
echo mysql_result($result['text'], $result['date_written'], $count);
I'm hoping it's a fairly simple syntax blunder that is easily fixed. Thanks in advance!