Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php mysql_fetch_array reset

Tags:

php

mysql

I want to print a list from a mysql database, but the first list item isn't printing because mysql_fetch_array is called twice. I tried reset but it didn't work. What should I do?

$current_goam = mysql_real_escape_string($current_goam);
$current_content = mysql_real_escape_string($current_content);

$note_content = mysql_query("select * from notes where title='$current_content' and goam='$current_goam' and user_id='$user_id'");

$note = mysql_fetch_array( $note_content );

if($note['type'] == 'list')
{
    $note_type='list';      
    reset($note);

    print "<table>";
    while($note_info = mysql_fetch_array( $note_content ))
    {
        print "<tr><td>";
           echo $note_info['body'];
            print "</td>";

            echo "<td><input type='checkbox' name='complete_goal' value='".$note_info['note_id']."'></input></td>";         
         print "</tr>";
    }
    print "</table>";
}   
else{
    echo $note['body'];
}
like image 293
Charles Murray Avatar asked Jan 10 '12 07:01

Charles Murray


People also ask

What is mysql_fetch_array () function?

mysql_fetch_array is a PHP function that will allow you to access data stored in the result returned from the TRUE mysql_query if u want to know what is returned when you used the mysql_query function to query a Mysql database. It is not something that you can directly manipulate. Syntax.

What is difference between mysql_fetch_array () mysql_fetch_row () and Mysql_fetch_object ()?

Speed-wise, the function is identical to mysql_fetch_array(), and almost as quick as mysql_fetch_row() (the difference is insignificant). Note: mysql_fetch_object() is similar to mysql_fetch_array(), with one difference - an object is returned, instead of an array.

What is the purpose of using mysql_fetch_array () & Mysqli_num_rows ()?

mysqli_fetch_array() function: It is used to fetch rows from the database and store them as an array. The array can be fetched as an associative array, as a numeric array, or both. Syntax: mysqli_fetch_array(result, arrayType);

What does Mysqli_fetch_array return?

The fetch_array() / mysqli_fetch_array() function fetches a result row as an associative array, a numeric array, or both. Note: Fieldnames returned from this function are case-sensitive.


1 Answers

try this instead of reset

mysql_data_seek($note_content, 0);

reset works for arrays

like image 123
boobiq Avatar answered Sep 30 '22 04:09

boobiq