Currently I have a code that gets the data from the database and a foreach loop that list all the result. But I want to display one result at a time. Just to warn you, I'm really new to this. Really appreciate your help.
function featured_topics(){
$featureNum = 162;
$query = mysql_query("SELECT *
FROM `topics`
WHERE `country_id` = '$featureNum'");
$numrows = mysql_num_rows($query);
while( $row = mysql_fetch_array($query)){
$featured_topics[] = $row;
}
return $featured_topics;
}
function get_featured_topic(){
$get_topics = featured_topics();
$topic_count = sizeof($get_topics);
$current_topic = $get_topic[$topic_count];
echo $current_topic['topic_id'];
}
function featured_topics(){
$featureNum = 162;
$query = mysql_query("SELECT *
FROM `topics`
WHERE `country_id` = '$featureNum' LIMIT 0,1");
$numrows = mysql_num_rows($query);
$row = mysql_fetch_array($query);
return $row;
}
$result = mysql_result($query, 0, 'column')
0 represents the 0'th row.
You can't do this in the way you want.
SQL rows don't have an intrinsic order, so there's no guarantee that the next time you execute this query the rows will be in the same order. Here is what might happen:
Query result:
points | name
--------------------
23 | Iceland
83 | Georgia
8 | Spain
10 | Argentina
You take the 1st row (Iceland). Then later, you do the same query. You get back this result:
points | name
--------------------
83 | Georgia
23 | Iceland
8 | Spain
10 | Argentina
Whooops! Now you got Iceland again and lost track of Georgia.
Solutions to this dilemma