简体   繁体   中英

echo MySQL array records one by one in php

I would like to know how to echo an array records one by one with button click to print both forward and revers records.

$query = "SELECT * FROM printingorder WHERE recHead = 'Pending'";
$result = mysql_query($query);

if I used

while($postate = mysql_fetch_array($result)){ 
    echo  "<h4>" .'1. Faculty : '. $postate['facultyId'] ."</h4>";
    echo  "<h4>" .'2. Department : '. $postate['departmentId'] ."</h4>";
    echo  "<h4>" .'3. Programm : '. $postate['programmId'] ."</h4>";
}

it prints all records after each raw contents.But I need only one complete raw content and next raw with button click(or hyperlink) for both forward and revers array records.

Your query should be like this :

$a = $_POST['row_number'];
$query = "SELECT * FROM printingorder WHERE recHead = 'Pending' limit $a,1";
$result = mysql_query($query);

On both button( previuos and next) post interger value which is row number. for previous decrement value and for next increment value.

`

 while($postate = mysql_fetch_assoc($result)){ 
    echo  "<h4>" .'1. Faculty : '. $postate['facultyId'] ."</h4>";
    echo  "<h4>" .'2. Department : '. $postate['departmentId'] ."</h4>";
    echo  "<h4>" .'3. Programm : '. $postate['programmId'] ."</h4>";
}

`

Try with mysql_fetch_assoc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM