Simple php mysql query returns only one of two columns -
i'm php , mysql newbie trying write simple query against table consisting of 2 columns: 1 text string , second date string. code below returns first column (the text string) not 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 archive_table text '%$string%'"; $result = mysql_query($search_query,$link); $rows = mysql_num_rows($result); if ($rows == 0) { echo "sorry, haven’t written ".$string." yet."; } $count = 0; while ($count < $rows) { echo mysql_result($result, $count); echo "\n\n"; $count = $count + 1; } mysql_close($link); ?>
i've tried following code replace "echo mysql_result($result, $count);", returns nothing @ all:
echo mysql_result($result['text'], $result['date_written'], $count);
i'm hoping it's simple syntax blunder fixed. in advance!
don't use
mysql_*
functions, they're deprecated , not safe. use either mysqli or pdoyou need fetch results:
$query = "blah" $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo "{$row['text']}, {$row['date_written]}"; }
Comments
Post a Comment